Skip to content

Commit

Permalink
Classes that just reference themselves aren’t used
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 16, 2019
1 parent bf67c03 commit e551b24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ public static function analyze(
$fq_class_name, $fq_class_name,
new CodeLocation($source, $stmt->class), new CodeLocation($source, $stmt->class),
$statements_analyzer->getSuppressedIssues(), $statements_analyzer->getSuppressedIssues(),
false $stmt->class instanceof PhpParser\Node\Name
&& !count($stmt->class->parts) !== 1
&& in_array(strtolower($stmt->class->parts[0]), ['self', 'static'], true)
)) { )) {
return false; return false;
} }
Expand Down
12 changes: 12 additions & 0 deletions tests/UnusedCodeTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -929,6 +929,18 @@ function foo(DateTimeImmutable $dt) : void {
}', }',
'error_message' => 'UnusedMethodCall', 'error_message' => 'UnusedMethodCall',
], ],
'unusedClassReferencesItself' => [
'<?php
class A {}
class AChild extends A {
public function __construct() {
self::foo();
}
public static function foo() : void {}
}',
'error_message' => 'UnusedClass',
],
]; ];
} }
} }

0 comments on commit e551b24

Please sign in to comment.