mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #910 - dead code issues with abstract vendor method
This commit is contained in:
parent
b4178c7ee1
commit
9cbe389285
@ -1488,6 +1488,13 @@ class ClassLikes
|
||||
$method_id = $declaring_method_id;
|
||||
}
|
||||
|
||||
if ($method_storage->location
|
||||
&& !$project_analyzer->canReportIssues($method_storage->location->file_path)
|
||||
&& !$codebase->analyzer->canReportIssues($method_storage->location->file_path)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method_referenced = $this->file_reference_provider->isClassMethodReferenced(strtolower($method_id));
|
||||
|
||||
if (!$method_referenced
|
||||
@ -1510,12 +1517,21 @@ class ClassLikes
|
||||
foreach ($classlike_storage->overridden_method_ids[$method_name_lc] as $parent_method_id) {
|
||||
$parent_method_storage = $methods->getStorage($parent_method_id);
|
||||
|
||||
if ($parent_method_storage->location
|
||||
&& !$project_analyzer->canReportIssues($parent_method_storage->location->file_path)
|
||||
) {
|
||||
// here we just don’t know
|
||||
$has_parent_references = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$parent_method_referenced = $this->file_reference_provider->isClassMethodReferenced(
|
||||
strtolower($parent_method_id)
|
||||
);
|
||||
|
||||
if (!$parent_method_storage->abstract || $parent_method_referenced) {
|
||||
$has_parent_references = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -929,7 +929,6 @@ class StubTest extends TestCase
|
||||
*/
|
||||
public function testStubFileWithTemplatedClassDefinitionAndMagicMethodOverride()
|
||||
{
|
||||
//$this->markTestSkipped('Currently broken');
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
@ -973,4 +972,58 @@ class StubTest extends TestCase
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
public function testInheritedMethodUsedInStub() : void
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm
|
||||
findUnusedCode="true"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$this->project_analyzer->getCodebase()->reportUnusedCode();
|
||||
|
||||
$vendor_file_path = getcwd() . '/vendor/vendor_class.php';
|
||||
|
||||
$this->addFile(
|
||||
$vendor_file_path,
|
||||
'<?php
|
||||
namespace SomeVendor;
|
||||
|
||||
class VendorClass {
|
||||
abstract public function foo() : void;
|
||||
|
||||
public static function vendorFunction(VendorClass $v) : void {
|
||||
$v->foo();
|
||||
}
|
||||
}',
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
class MyClass extends \SomeVendor\VendorClass {
|
||||
public function foo() : void {}
|
||||
}
|
||||
|
||||
\SomeVendor\VendorClass::vendorFunction(new MyClass);'
|
||||
);
|
||||
|
||||
$context = new Context();
|
||||
$context->collect_references = true;
|
||||
|
||||
$this->analyzeFile($file_path, $context, false);
|
||||
|
||||
$this->project_analyzer->checkClassReferences();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user