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

RemoveUnusedNonEmptyArrayBeforeForeachRector: skip array dim fetch #5166

Merged
merged 6 commits into from Oct 14, 2023

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 14, 2023


public static function getFootnotes($group = self::DEFAULT_GROUP): array
{
if (! empty(self::$groups[$group])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since we already skip "regular" dim fetch, I think it makes sense to also skip it for this example

Copy link
Member

Choose a reason for hiding this comment

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

is it possible to to check native ArrayDimFetch type for this case?

if ($foreachExpr instanceof Expr\ArrayDimFetch) {
   $nativeType = $this->nodeTypeResolver-getNativeType(...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have a test case in mind which fails atm?

Copy link
Member

Choose a reason for hiding this comment

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

something like assign in prev stmt:

self::$groups[$group] = ["foo"];

if (! empty(self::$groups[$group]))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed with 0edaf2d

Copy link
Member

Choose a reason for hiding this comment

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

could you fix phpstan notice? thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch :-). fixed.

@samsonasik samsonasik merged commit da2dd66 into rectorphp:main Oct 14, 2023
39 checks passed
@samsonasik
Copy link
Member

Thank you @staabm

@staabm staabm deleted the dim-fetch branch October 14, 2023 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants