mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix issue capturing method mutations in traits
This commit is contained in:
parent
72e1221a2f
commit
152d1512f1
@ -908,11 +908,11 @@ class ProjectChecker
|
||||
|
||||
$file_checker = $this->getVisitedFileCheckerForClassLike($fq_class_name);
|
||||
|
||||
$declaring_method_id = (string)MethodChecker::getDeclaringMethodId($original_method_id);
|
||||
list($declaring_fq_class_name) = explode('::', $declaring_method_id);
|
||||
$appearing_method_id = (string)MethodChecker::getAppearingMethodId($original_method_id);
|
||||
list($appearing_fq_class_name) = explode('::', $appearing_method_id);
|
||||
|
||||
if (strtolower($declaring_fq_class_name) !== strtolower($fq_class_name)) {
|
||||
$file_checker = $this->getVisitedFileCheckerForClassLike($declaring_fq_class_name);
|
||||
if (strtolower($appearing_fq_class_name) !== strtolower($fq_class_name)) {
|
||||
$file_checker = $this->getVisitedFileCheckerForClassLike($appearing_fq_class_name);
|
||||
}
|
||||
|
||||
$file_checker->analyze(false, true);
|
||||
@ -922,7 +922,7 @@ class ProjectChecker
|
||||
$this_context->vars_in_scope['$this'] = Type::parseString($fq_class_name);
|
||||
}
|
||||
|
||||
$file_checker->getMethodMutations($declaring_method_id, $this_context);
|
||||
$file_checker->getMethodMutations($appearing_method_id, $this_context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,4 +136,42 @@ class MethodMutationTest extends TestCase
|
||||
|
||||
$this->assertSame('Foo', (string)$method_context->vars_in_scope['$this->foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTraitMethod()
|
||||
{
|
||||
$this->project_checker->registerFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo { }
|
||||
|
||||
trait T {
|
||||
private function setFoo() : void {
|
||||
$this->foo = new Foo();
|
||||
}
|
||||
}
|
||||
|
||||
class FooController {
|
||||
use T;
|
||||
|
||||
/** @var Foo|null */
|
||||
public $foo;
|
||||
|
||||
public function __construct() {
|
||||
$this->setFoo();
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker);
|
||||
$context = new Context();
|
||||
$file_checker->visit($context);
|
||||
$file_checker->analyze(false, true);
|
||||
$method_context = new Context();
|
||||
$this->project_checker->getMethodMutations('FooController::__construct', $method_context);
|
||||
|
||||
$this->assertSame('Foo', (string)$method_context->vars_in_scope['$this->foo']);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user