Skip to content

Commit

Permalink
Analyze dynamic class const names
Browse files Browse the repository at this point in the history
  • Loading branch information
edsrzf committed Feb 1, 2024
1 parent a66aace commit 88c2e00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,15 @@ public static function analyzeFetch(
}

if (!$stmt->name instanceof PhpParser\Node\Identifier) {
return true;
$was_inside_general_use = $context->inside_general_use;

$context->inside_general_use = true;

$ret = ExpressionAnalyzer::analyze($statements_analyzer, $stmt->name, $context);

$context->inside_general_use = $was_inside_general_use;

return $ret;
}

$const_id = $fq_class_name . '::' . $stmt->name;
Expand Down
17 changes: 17 additions & 0 deletions tests/UnusedVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,23 @@ function foo() : void {
A::$method();
}',
],
'usedAsClassConstFetch' => [
'code' => '<?php
class A {
const bool something = false;
public function foo() : void {
$var = "something";
if (rand(0, 1)) {
static::{$var};
}
}
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'usedAsStaticPropertyAssign' => [
'code' => '<?php
class A {
Expand Down

0 comments on commit 88c2e00

Please sign in to comment.