Skip to content

Commit

Permalink
fix: global import from an array value
Browse files Browse the repository at this point in the history
  • Loading branch information
mRoca committed Jan 25, 2023
1 parent 31677bd commit 0c26ea8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/php/PHPMD/Rule/CleanCode/MissingImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ protected function isSelfReference(ASTNode $classNode)
*/
protected function isGlobalNamespace(ASTNode $classNode)
{
return !strpos($classNode->getImage(), '\\', 1);
return $classNode->getImage() !== '' && !strpos($classNode->getImage(), '\\', 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
function testRuleAppliesToFunctionWithNotImportedDependencies()
{
$a = new \stdClass();

// Using an array value as a classname can break the code, as the node will not be an ASTClass*
$classes = array('\stdClass');
$b = new $classes[0];
}

0 comments on commit 0c26ea8

Please sign in to comment.