rectorphp / rector

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

Latest dev-main cause infinite loop #7948

Closed samsonasik closed 1 year ago

samsonasik commented 1 year ago

Bug Report

Subject Details
Rector version dev-main

Minimal PHP Code Causing Issue

Tested in CodeIgniter 4 project system directory, stuck on 99%:

➜  CodeIgniter4 git:(develop) ✗ vendor/bin/rector process system --clear-cache
 423/426 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░]  99%

Expected Behaviour

It should not stack, I will look into it.

samsonasik commented 1 year ago

It seems stuck on RemoveUnusedVariableAssignRector:

[file] system/Images/Handlers/GDHandler.php
[rule] Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector
--- consumed 0 B, total 198.5 MB, took 0.00 s

[file] system/Images/Handlers/GDHandler.php
[rule] Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector
samsonasik commented 1 year ago

It seems due 2 rules combined:

    $rectorConfig->rule(RemoveUnusedVariableAssignRector::class);
    $rectorConfig->rule(SimplifyIfElseToTernaryRector::class);

with namespaced class:

<?php

namespace CodeIgniter\Images\Handlers;

class GDHandler
{
    protected function _flatten(int $red = 255, int $green = 255, int $blue = 255)
    {
        $srcImg = $this->createImage();

        if (function_exists('imagecreatetruecolor')) {
            $create = 'imagecreatetruecolor';
            $copy   = 'imagecopyresampled';
        } else {
            $create = 'imagecreate';
            $copy   = 'imagecopyresized';
        }
        $dest = $create($this->width, $this->height);

        $matte = imagecolorallocate($dest, $red, $green, $blue);

        imagefilledrectangle($dest, 0, 0, $this->width, $this->height, $matte);
        imagecopy($dest, $srcImg, 0, 0, 0, 0, $this->width, $this->height);

        // Kill the file handles
        imagedestroy($srcImg);

        $this->resource = $dest;

        return $this;
    }

}

Ref https://getrector.com/demo/14526a95-140e-49dc-99c1-c53c2c8b25e1