mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Add references to $this-> properties for method invalidation
This commit is contained in:
parent
43c5e9dd4c
commit
13b6868ab0
@ -85,8 +85,7 @@ class PropertyFetchChecker
|
||||
|
||||
$codebase->analyzer->incrementNonMixedCount($statements_checker->getFilePath());
|
||||
|
||||
if ($context->collect_references
|
||||
&& isset($stmt->var->inferredType)
|
||||
if (isset($stmt->var->inferredType)
|
||||
&& $stmt->var->inferredType->hasObjectType()
|
||||
&& $stmt->name instanceof PhpParser\Node\Identifier
|
||||
) {
|
||||
@ -102,7 +101,9 @@ class PropertyFetchChecker
|
||||
$codebase->properties->propertyExists(
|
||||
$property_id,
|
||||
$context->calling_method_id,
|
||||
new CodeLocation($statements_checker->getSource(), $stmt)
|
||||
$context->collect_references
|
||||
? new CodeLocation($statements_checker->getSource(), $stmt)
|
||||
: null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1040,6 +1040,53 @@ class FileUpdateTest extends TestCase
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [],
|
||||
]
|
||||
],
|
||||
'rescanPropertyAssertingMethod' => [
|
||||
'start_files' => [
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
||||
namespace Foo;
|
||||
|
||||
class A {
|
||||
/** @var string */
|
||||
private $foo;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function bar() : void {
|
||||
if ($this->foo === null) {}
|
||||
}
|
||||
}',
|
||||
],
|
||||
'end_files' => [
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
||||
namespace Foo;
|
||||
|
||||
class A {
|
||||
/** @var string|null */
|
||||
private $foo;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function bar() : void {
|
||||
if ($this->foo === null) {}
|
||||
}
|
||||
}',
|
||||
],
|
||||
'initial_correct_methods' => [
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [
|
||||
'foo\a::__construct' => 2,
|
||||
'foo\a::bar' => 1,
|
||||
],
|
||||
],
|
||||
'unaffected_correct_methods' => [
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [
|
||||
],
|
||||
],
|
||||
[
|
||||
'PropertyNotSetInConstructor' => \Psalm\Config::REPORT_INFO,
|
||||
'DocblockTypeContradiction' => \Psalm\Config::REPORT_INFO,
|
||||
'RedundantConditionGivenDocblockType' => \Psalm\Config::REPORT_INFO,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user