Skip to content

Commit

Permalink
Fix const usage in always-white methods (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Dec 6, 2024
1 parent ee6004c commit eedf31b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rule/DeadCodeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private function isConsideredWhite(ClassMemberUsage $memberUsage): bool
{
return $memberUsage->getOrigin() === null
|| $this->isAnonymousClass($memberUsage->getOrigin()->className)
|| (array_key_exists($memberUsage->getOrigin()->memberName, self::UNSUPPORTED_MAGIC_METHODS) && $memberUsage instanceof ClassMethodUsage);
|| (array_key_exists($memberUsage->getOrigin()->memberName, self::UNSUPPORTED_MAGIC_METHODS));
}

private function isNeverReportedAsDead(BlackMember $blackMember): bool
Expand Down
1 change: 1 addition & 0 deletions tests/Rule/DeadCodeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public static function provideFiles(): iterable
yield 'const-function' => [__DIR__ . '/data/constants/constant-function.php'];
yield 'const-dynamic' => [__DIR__ . '/data/constants/dynamic.php'];
yield 'const-expr' => [__DIR__ . '/data/constants/expr.php'];
yield 'const-magic' => [__DIR__ . '/data/constants/magic.php'];
yield 'const-mixed' => [__DIR__ . '/data/constants/mixed/tracked.php'];
yield 'const-override' => [__DIR__ . '/data/constants/override.php'];
yield 'const-static' => [__DIR__ . '/data/constants/static.php'];
Expand Down
14 changes: 14 additions & 0 deletions tests/Rule/data/constants/magic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1);

namespace DeadConstMagic;

class Magic {

const FOO = 1;

public function __destruct() {
echo self::FOO;
}

}

0 comments on commit eedf31b

Please sign in to comment.