Skip to content

Commit

Permalink
WIP Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Bates committed Jan 22, 2024
1 parent fcee04e commit a6a7f7b
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down Expand Up @@ -74,6 +76,9 @@
"phpstan": [
"phpstan --ansi"
],
"rector": [
"rector process --ansi"
],
"php-cs-fixer": [
"php-cs-fixer fix --ansi"
],
Expand Down
93 changes: 92 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use RectorLaravel\Set\LaravelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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,
]);
};

0 comments on commit a6a7f7b

Please sign in to comment.