Skip to content

[CodeQuality] Handle mix HTML+PHP on ForRepeatedCountToOwnVariableRector #3282

Merged
TomasVotruba merged 8 commits intomainfrom
mix-html-php
Jan 14, 2023
Merged

[CodeQuality] Handle mix HTML+PHP on ForRepeatedCountToOwnVariableRector #3282
TomasVotruba merged 8 commits intomainfrom
mix-html-php

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik samsonasik commented Jan 14, 2023

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 <?php after, but it make code keep working.

New Rector rule or cs tool may needed to clean the code for that :)

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba TomasVotruba merged commit d9ee43c into main Jan 14, 2023
@TomasVotruba TomasVotruba deleted the mix-html-php branch January 14, 2023 08:04
@TomasVotruba
Copy link
Copy Markdown
Member

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants