[CodeQuality] Handle mix HTML+PHP on ForRepeatedCountToOwnVariableRector #3282
Merged
TomasVotruba merged 8 commits intomainfrom Jan 14, 2023
Merged
[CodeQuality] Handle mix HTML+PHP on ForRepeatedCountToOwnVariableRector #3282TomasVotruba merged 8 commits intomainfrom
TomasVotruba merged 8 commits intomainfrom
Conversation
Member
Author
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
Member
|
Thanks 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is actually general issue when use mix HTML+PHP and we need to insert code between, for this use case, I found at
ForRepeatedCountToOwnVariableRector, which change to:$itemsCount = count($items);<?php + for ($i = 5; $i <= $itemsCount; $i++) { echo $items[$i]; }when previous node is HTML, the code become invalid, The tweak is by re-print the previous/next node when previous/next Node is HTML.
see https://getrector.org/demo/5b00ff10-b7af-4465-bb5d-3e4727e4c948
This is not perfect as it cause unnecessary empty
<?php ?>tag before the previous of previous node, and empty<?phpafter, but it make code keep working.New Rector rule or cs tool may needed to clean the code for that :)