2016-05-16 05:06:03 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Analyzer;
|
2016-05-16 05:06:03 +02:00
|
|
|
|
2022-02-24 01:50:05 +01:00
|
|
|
use PhpParser\Node\Stmt\Trait_;
|
2018-01-21 18:44:46 +01:00
|
|
|
use Psalm\Aliases;
|
2022-02-24 01:50:05 +01:00
|
|
|
use Psalm\Context;
|
|
|
|
|
|
|
|
use function assert;
|
2016-08-13 20:20:46 +02:00
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
class TraitAnalyzer extends ClassLikeAnalyzer
|
2016-05-16 05:06:03 +02:00
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
2018-01-21 18:44:46 +01:00
|
|
|
* @var Aliases
|
2016-11-02 07:29:00 +01:00
|
|
|
*/
|
2018-01-21 18:44:46 +01:00
|
|
|
private $aliases;
|
|
|
|
|
|
|
|
public function __construct(
|
2022-02-24 01:50:05 +01:00
|
|
|
Trait_ $class,
|
2018-11-06 03:57:36 +01:00
|
|
|
SourceAnalyzer $source,
|
2020-09-07 01:36:47 +02:00
|
|
|
string $fq_class_name,
|
2018-01-21 18:44:46 +01:00
|
|
|
Aliases $aliases
|
|
|
|
) {
|
|
|
|
$this->source = $source;
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->file_analyzer = $source->getFileAnalyzer();
|
2018-11-06 03:57:36 +01:00
|
|
|
$this->aliases = $source->getAliases();
|
2016-08-14 00:54:49 +02:00
|
|
|
$this->class = $class;
|
2016-11-07 23:29:51 +01:00
|
|
|
$this->fq_class_name = $fq_class_name;
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase = $source->getCodebase();
|
|
|
|
$this->storage = $codebase->classlike_storage_provider->get($fq_class_name);
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->aliases = $aliases;
|
|
|
|
}
|
|
|
|
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getNamespace(): ?string
|
2018-01-21 18:44:46 +01:00
|
|
|
{
|
|
|
|
return $this->aliases->namespace;
|
|
|
|
}
|
2016-05-16 05:06:03 +02:00
|
|
|
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getAliases(): Aliases
|
2018-01-21 18:44:46 +01:00
|
|
|
{
|
|
|
|
return $this->aliases;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-29 12:42:12 +01:00
|
|
|
* @return array<lowercase-string, string>
|
2018-01-21 18:44:46 +01:00
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getAliasedClassesFlipped(): array
|
2018-01-21 18:44:46 +01:00
|
|
|
{
|
|
|
|
return [];
|
2016-05-16 05:06:03 +02:00
|
|
|
}
|
2019-06-06 04:13:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, string>
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getAliasedClassesFlippedReplaceable(): array
|
2019-06-06 04:13:33 +02:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2022-02-24 01:50:05 +01: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,
|
2022-03-14 20:15:07 +01:00
|
|
|
AttributesAnalyzer::TARGET_CLASS,
|
2022-02-24 01:50:05 +01:00
|
|
|
$storage->suppressed_issues + $statements_analyzer->getSuppressedIssues()
|
|
|
|
);
|
|
|
|
}
|
2016-05-16 05:06:03 +02:00
|
|
|
}
|