Skip to content
Permalink
Browse files

Fix #910 - dead code issues with abstract vendor method

  • Loading branch information...
muglug committed Sep 1, 2019
1 parent b4178c7 commit 9cbe38928569cfbd7d453b2bb4d359b140a772ba
Showing with 70 additions and 1 deletion.
  1. +16 −0 src/Psalm/Internal/Codebase/ClassLikes.php
  2. +54 −1 tests/StubTest.php
@@ -1488,6 +1488,13 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth
$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 @@ private function checkMethodReferences(ClassLikeStorage $classlike_storage, Meth
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 @@ public function foo(string $a) {
*/
public function testStubFileWithTemplatedClassDefinitionAndMagicMethodOverride()
{
//$this->markTestSkipped('Currently broken');
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
@@ -973,4 +972,58 @@ class C extends B {}'
$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();
}
}

0 comments on commit 9cbe389

Please sign in to comment.
You can’t perform that action at this time.