From f675b30a169c6ad0e3785d253fee56bbf39f8005 Mon Sep 17 00:00:00 2001 From: Phil Bates Date: Mon, 22 Jan 2024 08:52:14 +0000 Subject: [PATCH] WIP Rector --- .github/workflows/backend.yml | 15 ++++++ composer.json | 2 + composer.lock | 93 ++++++++++++++++++++++++++++++++++- rector.php | 53 ++++++++++++++++++++ 4 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 rector.php diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index b2d06cc..4652d0e 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -50,6 +50,21 @@ jobs: - name: Run phpstan run: composer run phpstan + rector: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - name: Generate key + run: php artisan key:generate + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + - name: Run rector + run: composer run rector -- --dry-run + php-cs-fixer: runs-on: ubuntu-latest steps: diff --git a/composer.json b/composer.json index 261f710..cd4a733 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "laravel/tinker": "^2.8" }, "require-dev": { + "driftingly/rector-laravel": "^0.30.0", "fakerphp/faker": "^1.9.1", "friendsofphp/php-cs-fixer": "^3.47", "larastan/larastan": "^2.8", @@ -23,6 +24,7 @@ "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", "phpunit/phpunit": "^10.1", + "rector/rector": "^0.19.2", "spatie/laravel-ignition": "^2.0", "squizlabs/php_codesniffer": "^3.8" }, diff --git a/composer.lock b/composer.lock index bb61ed3..94b06ff 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "56684846b8028333843df5cae8ebd79e", + "content-hash": "b8baa246ac2290a66e6444e828e4d06e", "packages": [ { "name": "brick/math", @@ -5782,6 +5782,41 @@ ], "time": "2022-02-25T21:32:43+00:00" }, + { + "name": "driftingly/rector-laravel", + "version": "0.30.0", + "source": { + "type": "git", + "url": "https://github.com/driftingly/rector-laravel.git", + "reference": "871a5921177be5f493646d4a22998c8aa3eedebc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/871a5921177be5f493646d4a22998c8aa3eedebc", + "reference": "871a5921177be5f493646d4a22998c8aa3eedebc", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "rector/rector": "^0.19.0" + }, + "type": "rector-extension", + "autoload": { + "psr-4": { + "RectorLaravel\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Rector upgrades rules for Laravel Framework", + "support": { + "issues": "https://github.com/driftingly/rector-laravel/issues", + "source": "https://github.com/driftingly/rector-laravel/tree/0.30.0" + }, + "time": "2024-01-11T18:11:35+00:00" + }, { "name": "fakerphp/faker", "version": "v1.23.1", @@ -7230,6 +7265,62 @@ ], "time": "2024-01-14T16:40:30+00:00" }, + { + "name": "rector/rector", + "version": "0.19.2", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "bc96a99895bf47c6bfe70ea1b799f0081ed5a903" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/bc96a99895bf47c6bfe70ea1b799f0081ed5a903", + "reference": "bc96a99895bf47c6bfe70ea1b799f0081ed5a903", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.10.56" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/0.19.2" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2024-01-19T10:58:30+00:00" + }, { "name": "sebastian/cli-parser", "version": "2.0.0", diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..8d6d3a8 --- /dev/null +++ b/rector.php @@ -0,0 +1,53 @@ +paths([ + __DIR__ . '/app', + __DIR__ . '/bootstrap', + __DIR__ . '/config', + __DIR__ . '/public', + __DIR__ . '/resources', + __DIR__ . '/routes', + __DIR__ . '/tests', + ]); + + $rectorConfig->skip([ + __DIR__ . '/bootstrap/cache', + ]); + + // This currently throws an error, see https://github.com/rectorphp/rector/issues/8006 + // $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist'); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_83, + LaravelSetList::LARAVEL_100, + PHPUnitSetList::PHPUNIT_100, + + // High hit sets - Run all the time + SetList::CODE_QUALITY, + // SetList::CODING_STYLE, // Let php-cs-fixer handle this + SetList::DEAD_CODE, + SetList::STRICT_BOOLEANS, + // SetList::GMAGICK_TO_IMAGICK, // We don't use this + SetList::NAMING, + SetList::PRIVATIZATION, + SetList::TYPE_DECLARATION, + SetList::EARLY_RETURN, + SetList::INSTANCEOF, + // LaravelSetList::LARAVEL_STATIC_TO_INJECTION, + LaravelSetList::LARAVEL_CODE_QUALITY, + // LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES, + LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES, + LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + ]); +};