Skip to content

Commit

Permalink
Fix #1996 - detect unused variable in static property name
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 9, 2019
1 parent 85c9b6b commit 5254b75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -992,6 +992,10 @@ public static function analyzeStatic(
$prop_name = $stmt->name; $prop_name = $stmt->name;


if (!$prop_name instanceof PhpParser\Node\Identifier) { if (!$prop_name instanceof PhpParser\Node\Identifier) {
if (ExpressionAnalyzer::analyze($statements_analyzer, $prop_name, $context) === false) {
return false;
}

if ($fq_class_name && !$context->ignore_variable_property) { if ($fq_class_name && !$context->ignore_variable_property) {
$codebase->analyzer->addMixedMemberName( $codebase->analyzer->addMixedMemberName(
strtolower($fq_class_name) . '::$', strtolower($fq_class_name) . '::$',
Expand Down
14 changes: 14 additions & 0 deletions tests/UnusedVariableTest.php
Expand Up @@ -1020,6 +1020,20 @@ function foo() : void {
A::$method(); A::$method();
}', }',
], ],
'usedAsStaticPropertyName' => [
'<?php
class A {
private static bool $something = false;
public function foo() : void {
$var = "something";
if (true) {
static::${$var} = true;
}
}
}'
],
]; ];
} }


Expand Down

0 comments on commit 5254b75

Please sign in to comment.