-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
RemoveAlwaysTrueIfConditionRector removes if-statement that is required for undefined array key check #8413
Comments
Could you create failing test case fixture PR? Thank you. |
Here is a sample code. As "$changeSet['add']" might not be set the Rector fix will lead to PHP notice messages. Also, it is unclear why the two if-conditions are not treated the same way (only second is removed by Rector).
|
That's seems phpstan bug based on its type detected, I created issue on phpstan side, see phpstan/phpstan#10640 |
Also, -$changes[$add['id']]['del'][] = doSomething($del);
+$changes[$del['id']]['del'][] = doSomething($del); on 2nd loop, otherwise, the |
I am closing it as it is phpstan bug and already reported there phpstan/phpstan#10640 You can skip the rule until it got fixed on phpstan side ;) |
Bug Report
The RemoveAlwaysTrueIfConditionRector tries to remove an if-statement that is needed to prevent access to undefined array keys.
Minimal PHP Code Causing Issue
https://getrector.com/demo/a1bd0aae-6e03-4fe7-b3c5-a6ccbaaff5bc
PHP Warning: Undefined array key "add" in rectorTest.php on line 22 PHP Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in rectorTest.php:22 Stack trace: #0 rectorTest.php(22): array_merge() #1 rectorTest.php(31): Test->test() #2 {main} thrown in rectorTest.php on line 22
Expected Behaviour
There should be no change as the "if" is required.
The text was updated successfully, but these errors were encountered: