driftingly / rector-laravel

Rector upgrades rules for Laravel
http://getrector.org
MIT License
500 stars 49 forks source link

Can't execute rector-laravel #67

Closed KasumiHumphreys closed 1 year ago

KasumiHumphreys commented 1 year ago

Dear Team,

I installed rector and rector-laravel reffering this site. And these commands are I executed;

vagrant@homestead:~/code/laravel-project$ php -v
PHP 8.0.25 (cli) (built: Oct 28 2022 18:02:51) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.25, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.25, Copyright (c), by Zend Technologies

vagrant@homestead:~/code$ cd laravel-project/
vagrant@homestead:~/code/laravel-project$ mkdir --parents tools/rector
vagrant@homestead:~/code/laravel-project$ composer req --working-dir=tools/rector rector/rector
・・・
vagrant@homestead:~/code/laravel-project$ tools/rector/vendor/bin/rector --version
Rector 0.14.8
vagrant@homestead:~/code/laravel-project$ tools/rector/vendor/bin/rector init

Then, edit laravel-project/rector.php :

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/Flow',
        __DIR__ . '/app',
        __DIR__ . '/bootstrap',
        __DIR__ . '/config',
        __DIR__ . '/database',
        __DIR__ . '/public',
        __DIR__ . '/resources',
        __DIR__ . '/routes',
        __DIR__ . '/storage',
        __DIR__ . '/tests',
        __DIR__ . '/tools',
    ]);

    // register a single rule
    $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

    // define sets of rules
        $rectorConfig->sets([
            LevelSetList::UP_TO_PHP_80
        ]);
};

Execute rector.php tools/rector/vendor/bin/rector process --dry-run →run successfully

Install rector-laravel composer req --working-dir=tools/rector driftingly/rector-laravel Edit laravel-project/rector.php again

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use RectorLaravel\Set\LaravelSetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/Flow',
        __DIR__ . '/app',
        __DIR__ . '/bootstrap',
        __DIR__ . '/config',
        __DIR__ . '/database',
        __DIR__ . '/public',
        __DIR__ . '/resources',
        __DIR__ . '/routes',
        __DIR__ . '/storage',
        __DIR__ . '/tests',
        __DIR__ . '/tools',
    ]);

    // register a single rule
    $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

    // define sets of rules
        $rectorConfig->sets([
            UP_TO_LARAVEL_70
        ]);
};

Execute;

vagrant@homestead:~/code/laravel-project$ tools/rector/vendor/bin/rector process --dry-run
[ERROR] Class "Rector\Larave\Set\LaravelSetList" not found

Why this error occured?

Thanks, Kate.

KasumiHumphreys commented 1 year ago

Resolved by myself…:(

Akak-mx commented 1 year ago

@KasumiHumphreys what was the error? It's happening to me too. 😅