rectorphp / rector

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

Laravel rules seems not working; nothing is done #7264

Closed cavo789 closed 2 years ago

cavo789 commented 2 years ago

Bug Report

Subject Details
Rector version 0.3.17 (installed right now)

Hello all,

I'm trying to upgrade from Laravel 7 to Laravel 9. I'm following this documentation: https://github.com/rectorphp/rector-laravel#use-sets

And nothing happens i.e. Rector see nothing to change; everything is OK for him in my codebase while it's not the case (I should migrate a Laravel 7 codebase).

I've then tried a specific rule (see online demo below) and ... still nothing happens.

Minimal PHP Code Causing Issue

The example just comes from your official doc: [AnonymousMigrationsRector](https://github.com/rectorphp/rector-laravel/blob/main/docs/rector_rules_overview.md#anonymousmigrationsrector] rule.

https://getrector.org/demo/e992441c-9b1a-433e-ad83-3c63f1719538

And it does nothing.

Expected Behaviour

The function has been rewrite so it's anonymous (as explained in the documention).

On top of that specific rule, I expect that the following configuration file will reports me a lot of changes:

use Rector\Laravel\Set\LaravelSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->sets([
        LaravelSetList::LARAVEL_90
    ]);
};

The next CLI run rector on a file having issues and nothing is reported by Rector:

 vendor/bin/rector process --config .config/rector-laravel9.php --debug -vvv --dry-run database/migrations/create_languages_table.php
database/migrations/create_languages_table.php
[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector

[file] database/migrations/create_languages_table.php
[rule] Rector\Renaming\Rector\MethodCall\RenameMethodRector

 [OK] Rector is done!

(Oh, I didn't see AnonymousMigrationsRector in the list when I use LaravelSetList::LARAVEL_90 (same for LaravelSetList::LARAVEL_80 ...)

Many thanks !

TomasVotruba commented 2 years ago

Hi, thanks for reporting. I think for this case we'll need a minimal reproducible repository to figure out, what is going wrong.

cavo789 commented 2 years ago

Hi Tomas

Does the demo isn't sufficient ? If not, tell me and I'll create a temporary repo on github.com

Thanks

TomasVotruba commented 2 years ago

Hi, demo does not contain your project and setup. It has no /vendor, and misses all the laravel classes. It's like testing your project without /vendor :)

That's why we need the context and exact repository of your setup that does not work. The smaller the better so we have less places to check.

TomasVotruba commented 2 years ago

We're narrowing issues to keep focus on active and engaging contributor to keep project growing. Thank you for understanding.

Closing for lack of feedback, but feel free to re-open with failing reproducer repository.

cavo789 commented 2 years ago

Hi Tomas

You're perfectly right of course! Sorry for the delay.

In fact, that was my last working week before three weeks enjoying the sun (holiday) ;-)

Back to work, I've tried once more and I've still the same problem on my office computer while... I don't have that problem on my private, home, computer. There, I've restart everything from scratch i.e. by installing an old Laravel 7.x version, installing locally Rector (in composer.json thus) and running the AnonymousMigrationsRector. As expected, the migration file is correctly upgraded.

So, the rule is working

On my office computer, I'm not directly using Rector (as a composer dependency) but using https://github.com/jakzal/phpqa (an amazing Docker image with a lot of QA tools).

My home version of Docker is 0.13.9; the one packaged in phpqa is 0.13.6.

Should be a problem of versions thus.

Many thanks, once more (I'll never say enough how much Rector is amazing and how much I admire the work done by you and the other volunteers).

TomasVotruba commented 2 years ago

Hi @cavo789,

thanks for reaching out. I'm happy it worked for you and you enjoyed a piece of holiday for yourself :)

To be honnest, Docker is the number one issue most people rage-quit or think Rector does not work. There is too many version, wrapping, path issues, that they're unable to use Rector successfuly. Another problem is caching issues.

Unless you're running PHP 7.1 or bellow, where Rector cannot run natively, always use it as a composer dependency. You'll save so much WTFs along the way, and be able to get direct input :+1: