mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Properly analyse nested traits
This commit is contained in:
parent
68dbe509a8
commit
1462020cd4
@ -2,6 +2,7 @@
|
||||
namespace Psalm\Checker;
|
||||
|
||||
use PhpParser;
|
||||
use Psalm\Aliases;
|
||||
use Psalm\Checker\FunctionLike\ReturnTypeChecker;
|
||||
use Psalm\Checker\Statements\ExpressionChecker;
|
||||
use Psalm\CodeLocation;
|
||||
@ -399,6 +400,7 @@ class ClassChecker extends ClassLikeChecker
|
||||
}
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\TraitUse) {
|
||||
if ($this->analyzeTraitUse(
|
||||
$this->source->getAliases(),
|
||||
$stmt,
|
||||
$project_checker,
|
||||
$storage,
|
||||
@ -644,6 +646,7 @@ class ClassChecker extends ClassLikeChecker
|
||||
* @return false|null
|
||||
*/
|
||||
private function analyzeTraitUse(
|
||||
Aliases $aliases,
|
||||
PhpParser\Node\Stmt\TraitUse $stmt,
|
||||
ProjectChecker $project_checker,
|
||||
ClassLikeStorage $storage,
|
||||
@ -660,7 +663,7 @@ class ClassChecker extends ClassLikeChecker
|
||||
|
||||
$fq_trait_name = self::getFQCLNFromNameObject(
|
||||
$trait_name,
|
||||
$this->source->getAliases()
|
||||
$aliases
|
||||
);
|
||||
|
||||
if (!$codebase->classlikes->hasFullyQualifiedTraitName($fq_trait_name)) {
|
||||
@ -713,6 +716,7 @@ class ClassChecker extends ClassLikeChecker
|
||||
}
|
||||
} elseif ($trait_stmt instanceof PhpParser\Node\Stmt\TraitUse) {
|
||||
if ($this->analyzeTraitUse(
|
||||
$trait_aliases,
|
||||
$trait_stmt,
|
||||
$project_checker,
|
||||
$storage,
|
||||
|
@ -465,16 +465,26 @@ class IncludeTest extends TestCase
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'file3.php' => '<?php
|
||||
require("file2.php");
|
||||
|
||||
namespace Foo;
|
||||
|
||||
use Bar\B;
|
||||
|
||||
class C {
|
||||
use B;
|
||||
}',
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'file2.php' => '<?php
|
||||
require("file1.php");
|
||||
|
||||
namespace Bar;
|
||||
|
||||
use Bat\A;
|
||||
|
||||
trait B {
|
||||
use A;
|
||||
}',
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'file1.php' => '<?php
|
||||
namespace Bat;
|
||||
|
||||
trait A{
|
||||
public function fooFoo(): string {
|
||||
return 5;
|
||||
|
Loading…
x
Reference in New Issue
Block a user