1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00
psalm/src/Psalm/Internal/Analyzer/TraitAnalyzer.php

77 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2018-11-05 21:57:36 -05:00
namespace Psalm\Internal\Analyzer;
2022-02-23 18:50:05 -06:00
use PhpParser\Node\Stmt\Trait_;
2018-01-21 12:44:46 -05:00
use Psalm\Aliases;
2022-02-23 18:50:05 -06:00
use Psalm\Context;
use function assert;
/**
* @internal
*/
2018-11-05 21:57:36 -05:00
class TraitAnalyzer extends ClassLikeAnalyzer
{
2016-11-02 02:29:00 -04:00
/**
2018-01-21 12:44:46 -05:00
* @var Aliases
2016-11-02 02:29:00 -04:00
*/
2018-01-21 12:44:46 -05:00
private $aliases;
public function __construct(
2022-02-23 18:50:05 -06:00
Trait_ $class,
2018-11-05 21:57:36 -05:00
SourceAnalyzer $source,
string $fq_class_name,
2018-01-21 12:44:46 -05:00
Aliases $aliases
) {
$this->source = $source;
2018-11-11 12:01:14 -05:00
$this->file_analyzer = $source->getFileAnalyzer();
2018-11-05 21:57:36 -05:00
$this->aliases = $source->getAliases();
$this->class = $class;
$this->fq_class_name = $fq_class_name;
$codebase = $source->getCodebase();
$this->storage = $codebase->classlike_storage_provider->get($fq_class_name);
2018-01-21 12:44:46 -05:00
$this->aliases = $aliases;
}
public function getNamespace(): ?string
2018-01-21 12:44:46 -05:00
{
return $this->aliases->namespace;
}
public function getAliases(): Aliases
2018-01-21 12:44:46 -05:00
{
return $this->aliases;
}
/**
* @return array<lowercase-string, string>
2018-01-21 12:44:46 -05:00
*/
public function getAliasedClassesFlipped(): array
2018-01-21 12:44:46 -05:00
{
return [];
}
2019-06-05 22:13:33 -04:00
/**
* @return array<string, string>
*/
public function getAliasedClassesFlippedReplaceable(): array
2019-06-05 22:13:33 -04:00
{
return [];
}
2022-02-23 18:50:05 -06:00
public static function analyze(StatementsAnalyzer $statements_analyzer, Trait_ $stmt, Context $context): void
{
assert($stmt->name !== null);
$storage = $statements_analyzer->getCodebase()->classlike_storage_provider->get($stmt->name->name);
AttributesAnalyzer::analyze(
$statements_analyzer,
$context,
$storage,
$stmt->attrGroups,
1,
$storage->suppressed_issues + $statements_analyzer->getSuppressedIssues()
);
}
}