rector icon indicating copy to clipboard operation
rector copied to clipboard

Incorrect behavior of RenameForeachValueVariableToMatchExprVariableRector

Open frankii91 opened this issue 1 year ago • 1 comments

Bug Report

error with more complex code...

Subject Details
Rector version now()

Minimal PHP Code Causing Issue

code before using rector:

    if (isset($parameter['smarty_internal_index'])) {
        $output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], {$_nocache}, {$_scope});\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
    } elseif ($compiler->template->smarty instanceof SmartyBC) {
        // implement Smarty2's behaviour of variables assigned by reference
        $output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
        $output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;";
        $output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new SmartyVariable($_attr[value], $_nocache, $_scope);";
    } else {
        $output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new SmartyVariable($_attr[value], $_nocache, $_scope);";
    }

code with syntax errors after changing: if (isset($parameter['smarty_internal_index'])) { $output = "<?php $_smarty_tpl->createLocalArrayVariable($_attr[var], {$_nocache}, {$_scope});\n$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; } elseif ($compiler->template->smarty instanceof SmartyBC) { // implement Smarty2's behaviour of variables assigned by reference $output = sprintf('<?php if (isset($_smarty_tpl->tpl_vars[%s])) {$_smarty_tpl->tpl_vars[%s] = clone $_smarty_tpl->tpl_vars[%s];', $_attr[var], $_attr[var], $_attr[var]); $output .= "\n$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; $_smarty_tpl->tpl_vars[$_attr[var]]->nocache = {$_nocache}; $_smarty_tpl->tpl_vars[$_attr[var]]->scope = {$_scope};"; $output .= "\n} else $_smarty_tpl->tpl_vars[$_attr[var]] = new SmartyVariable($_attr[value], {$_nocache}, {$_scope});"; } else { $output = sprintf('<?php $_smarty_tpl->tpl_vars[%s] = new SmartyVariable(%s, %s, %s);', $_attr[var], $_attr[value], $_nocache, $_scope); }

frankii91 avatar Aug 19 '24 20:08 frankii91

Could you reproduce at https://getrector.com/demo ? Thank you

samsonasik avatar Aug 19 '24 20:08 samsonasik

I am closing it as no code and config provided. If I check your example, it seems you're changing smarty, that third party vendor, my suggestion is to not change vendor or third party code.

You can skip the path of it https://getrector.com/documentation/ignoring-rules-or-paths

samsonasik avatar Aug 30 '24 18:08 samsonasik

t4o że smarty to nie znaczy że w pełni zewnętrzne odłamane w około 2015 i optymalizowane na własną rękę ...

pt., 30 sie 2024 o 20:42 Abdul Malik Ikhsan @.***> napisał(a):

I am closing it as no code and config provided. If I check your example, it seems you're changing smarty, that third party vendor, my suggestion is to not change vendor or third party code.

You can skip the path of it https://getrector.com/documentation/ignoring-rules-or-paths

— Reply to this email directly, view it on GitHub https://github.com/rectorphp/rector/issues/8796#issuecomment-2322136304, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLSI3WZQXNYUWM7HBJYK2DZUC4K7AVCNFSM6AAAAABMYQCQUGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRSGEZTMMZQGQ . You are receiving this because you authored the thread.Message ID: @.***>

frankii91 avatar Sep 03 '24 18:09 frankii91