rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.32k stars 670 forks source link

ForRepeatedCountToOwnVariableRector put php code outside open php tag #8628

Closed allanforms closed 3 weeks ago

allanforms commented 3 weeks ago

Bug Report

Subject Details
ForRepeatedCountToOwnVariableRector 1.0.4

ForRepeatedCountToOwnVariableRector detected a correction on the following code

        </tr>

        <?php
        for ($i = 0; $i < count($arrlinks); $i++) { ?>
            <tr bgcolor="#FFFFFF">

and corrected to this

        </tr>

$counter = count($arrlinks);<?php
        for ($i = 0; $i < $counter; $i++) { ?>
            <tr bgcolor="#FFFFFF">

Expected Behaviour

I thought it would make something like this

    </tr>

<?php $counter = count($arrlinks);
        for ($i = 0; $i < $counter; $i++) { ?>
            <tr bgcolor="#FFFFFF">

or this

        </tr>

        <?php
$counter = count($arrlinks);
        for ($i = 0; $i < $counter; $i++) { ?>
            <tr bgcolor="#FFFFFF">

or this


        </tr>

<?php
$counter = count($arrlinks);
        for ($i = 0; $i < $counter; $i++) { ?>
samsonasik commented 3 weeks ago

That expected drawback of mix PHP+HTML, you need to verify manually on that, see https://github.com/rectorphp/rector?tab=readme-ov-file#may-cause-unexpected-output-on-file-with-mixed-phphtml-content