mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Only invalidate methods that call a removed trait
This commit is contained in:
parent
0050d1f4d7
commit
ceebc9e81d
@ -614,12 +614,30 @@ class Analyzer
|
||||
|
||||
$classlikes = $codebase->classlikes;
|
||||
|
||||
foreach ($all_referencing_methods as $member_id => $referencing_method_ids) {
|
||||
$member_class_name = preg_replace('/::.*$/', '', $member_id);
|
||||
foreach ($changed_members as $file_path => $members_by_file) {
|
||||
foreach ($members_by_file as $changed_member => $_) {
|
||||
if (!strpos($changed_member, '&')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($classlikes->hasFullyQualifiedClassLikeName($member_class_name)
|
||||
&& !$classlikes->hasFullyQualifiedTraitName($member_class_name)
|
||||
) {
|
||||
list($base_class, $trait) = explode('&', $changed_member);
|
||||
|
||||
foreach ($all_referencing_methods as $member_id => $referencing_method_ids) {
|
||||
if (strpos($member_id, $base_class . '::') !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$member_bit = substr($member_id, strlen($base_class) + 2);
|
||||
|
||||
if (isset($all_referencing_methods[$trait . '::' . $member_bit])) {
|
||||
$changed_members[$file_path][$member_id] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($all_referencing_methods as $member_id => $referencing_method_ids) {
|
||||
if (!strpos($member_id, '&')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ class ClassStatementsDiffer extends AstDiffer
|
||||
}
|
||||
} elseif ($diff_elem->old instanceof PhpParser\Node\Stmt\TraitUse) {
|
||||
foreach ($diff_elem->old->traits as $trait) {
|
||||
$keep[] = strtolower((string) $trait->getAttribute('resolvedName')) . '::*';
|
||||
$keep[] = strtolower($name . '&' . $trait->getAttribute('resolvedName'));
|
||||
}
|
||||
}
|
||||
} elseif ($diff_elem->type === DiffElem::TYPE_KEEP_SIGNATURE) {
|
||||
@ -229,7 +229,7 @@ class ClassStatementsDiffer extends AstDiffer
|
||||
}
|
||||
} elseif ($affected_elem instanceof PhpParser\Node\Stmt\TraitUse) {
|
||||
foreach ($affected_elem->traits as $trait) {
|
||||
$add_or_delete[] = strtolower((string) $trait->getAttribute('resolvedName')) . '::*';
|
||||
$add_or_delete[] = strtolower($name . '&' . $trait->getAttribute('resolvedName'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ class AnalyzedMethodTest extends \Psalm\Tests\TestCase
|
||||
class A {
|
||||
use T;
|
||||
|
||||
public function fooFoo(): void { }
|
||||
public function fooFoo(?string $foo = null): void { }
|
||||
}',
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'B.php' => '<?php
|
||||
namespace Foo;
|
||||
@ -535,7 +535,7 @@ class AnalyzedMethodTest extends \Psalm\Tests\TestCase
|
||||
namespace Foo;
|
||||
|
||||
class A {
|
||||
public function fooFoo(?string $foo = null): void { }
|
||||
public function fooFoo(): void { }
|
||||
}',
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'B.php' => '<?php
|
||||
namespace Foo;
|
||||
@ -569,9 +569,7 @@ class AnalyzedMethodTest extends \Psalm\Tests\TestCase
|
||||
],
|
||||
],
|
||||
'unaffected_analyzed_methods' => [
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [
|
||||
'foo\a::barbar&foo\t::barbar' => 1, // this doesn't exist, so we don't care
|
||||
],
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [],
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [],
|
||||
],
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user