Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: global import from an array value #996

Merged
merged 1 commit into from Jan 25, 2023

Conversation

mRoca
Copy link
Contributor

@mRoca mRoca commented Jan 25, 2023

Type: bugfix
Breaking change: no

This PR fixes a PHP issue when running the following code with the MissingImport's ignore-global option enabled:

$classes = ['\stdClass'];
$b = new $classes[0];

The error:

ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)

src/main/php/PHPMD/Rule/CleanCode/MissingImport.php:92

The reason:

In this case, the current ASTNode will be a PDepend\Source\AST\ASTArrayIndexExpression, and $classNode->getImage() will return an empty string

@mRoca mRoca force-pushed the fix/global-import-from-array branch from 7b1c4db to 0c26ea8 Compare January 25, 2023 14:29
Copy link
Member

@kylekatarnls kylekatarnls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🙏

Copy link
Member

@AJenbo AJenbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test for this

@AJenbo AJenbo merged commit d81cefd into phpmd:master Jan 25, 2023
@mRoca mRoca deleted the fix/global-import-from-array branch January 25, 2023 16:54
@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants