-
-
Notifications
You must be signed in to change notification settings - Fork 340
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
[Php71] Add MultiDimensionalArrayToArrayDestructRector #6031
[Php71] Add MultiDimensionalArrayToArrayDestructRector #6031
Conversation
Hi, thanks for the proposal. |
Hi, are you talking about the MR code being hard to read or the modified code that rector produces with this rule? I think this rule should be part of a generic set as it's quite similar to the existing rule ListToArrayDestructRector which is already part of the set, the only difference is that this one works with associative arrays. I personally find this PHP feature neat to use when you have multidimensional associative arrays as you only have couple of options
|
Interesting rule. I never knew it was possible to destruct multi dimensional arrays like this. Only did it for values. TIL!
This is something completely different. The ListToArrayDestruct is converts an older syntax The rule you are proposing is a preference that can potentially create a lot of changes (everything in the loop) and is not something every developers wants. |
In that case, developer can disable the rule in the configuration or we could have this as part of some other set. In my opinion, even though it changes more than a single line, this is something that will contribute to making the code cleaner and shorter by remove the need for constant foreach variable reference. |
I think this should not be included in config/sets, so user can manually enable it theirself |
Also a possibility. Just let me know what you decide so that I can adjust. |
I think not registered in any set is the way it become easy merge, as it may be personal preference syntax |
Done |
@samsonasik Seems like PHPStan is complaining now that it must be registered in a set. How should I fix this? |
It seems you can ignore at phpstan.neon Lines 238 to 239 in d68e8fa
|
@@ -32,7 +32,7 @@ | |||
|
|||
- [Php70](#php70) (19) | |||
|
|||
- [Php71](#php71) (7) | |||
- [Php71](#php71) (8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these changes need to be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the documentation is generated weekly, you can revert the doc change, and it will be regenerated later by CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great if manual changes to these files are rejected :D
@nikolicaleksa I think better than PHP 7.1, where rules are features most devs want, is better to target "coding style" namespace, where it depends on taste. PHPStan error will be fixed :) |
Should I move it to "coding style" set and leave it enabled for that set or just move it there but not register? |
@nikolicaleksa Only move to the namespace. No registrations as that would automatically run for everyone using the set. |
PHPStan notice seems only on php set, on other namespace, that seems working ok without registering in config set. |
All done 🤝 |
Awesome! Thank you for fast work 🎉 |
Just discussed this with a team member, and they gave this feedback:
Did you consider an alternative syntax as soon as the array shape line becomes too long? |
It seems cause downgrade error: ---------------------------------------------------------
Parse error: rector-prefixed-downgraded/rules/CodingStyle/Rector/Foreach/MultiDimensionalArrayToArrayDestructRector.php:4
2|
3| declare (strict_types=1);
> 4| namespace Rector\CodingStyle\Rector\Foreach;
|
downgrade error should be resolved at #6045 |
@ruudk that possibly an improvement area to make rule configurable with "limit" variable config... |
No description provided.