Skip to content

[DeadCode] Skip count() on mixed on RemoveUnusedNonEmptyArrayBeforeForeachRector#5160

Merged
samsonasik merged 1 commit intomainfrom
skip-count-mixed
Oct 13, 2023
Merged

[DeadCode] Skip count() on mixed on RemoveUnusedNonEmptyArrayBeforeForeachRector#5160
samsonasik merged 1 commit intomainfrom
skip-count-mixed

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik
Copy link
Copy Markdown
Member Author

Fixed 🎉 /cc @staabm

@samsonasik
Copy link
Copy Markdown
Member Author

@staabm while it fixed the issue, could you create a https://3v4l.org/ demo for how it can cause invalid usage without skipping?

Otherwise, the patch is useless :)

@staabm
Copy link
Copy Markdown
Contributor

staabm commented Oct 13, 2023

see https://3v4l.org/bavqQ where we get fatal errors on the count variant, but not the foreach variant

@samsonasik
Copy link
Copy Markdown
Member Author

The error is exists on the first place, so removing count() actually unrelated to side effect.

see https://3v4l.org/eGBHn

when no change yet, it already fatal error.

In real app, actually, removing count() should never used when only used on loop next.

@staabm
Copy link
Copy Markdown
Contributor

staabm commented Oct 13, 2023

when no change yet, it already fatal error.

I don't get your point. IMO we can't change code which fatal errors (so from a runtime perspective will stop execution and will not proceed) with a different code which no longer fatal errors and keeps executing.

sure the code not running into fatal errors sounds better but if rector is doing such change it completely changes the code beeing executed and because of procssing is not running into a fatal error anymore it might lead to e.g. other serious problem in code after that, which was never executed before rector did the change

@samsonasik
Copy link
Copy Markdown
Member Author

That seems just hiding the real issue then. If the code after that must not be executed, then code should be modified to fix that.

The TypeError check will need to be catched on the first place, and user should see that.

@staabm
Copy link
Copy Markdown
Contributor

staabm commented Oct 13, 2023

back to square one: the only thing I am saying is, that rector cannot do a change which fundamentally changes the execution path.

of course such a code should be fixed by a human.

the RemoveUnusedNonEmptyArrayBeforeForeachRector can of course remove e.g. a count() statement if it knows whatever passed to it is countable.

@samsonasik
Copy link
Copy Markdown
Member Author

Ok, the rule is named RemoveUnusedNonEmptyArrayBeforeForeachRector, so it should only care about ArrayType, so your reason is reasonable.

I am merging it then ;)

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.

RemoveUnusedNonEmptyArrayBeforeForeachRector: removal of count() without array type

2 participants