Skip to content

Commit 0a8df56

Browse files
committed
feat: add rector support
1 parent a92fe64 commit 0a8df56

File tree

5 files changed

+92
-5
lines changed

5 files changed

+92
-5
lines changed

.github/workflows/integrate.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,6 @@ jobs:
361361
with:
362362
dependencies: ${{ matrix.dependencies }}
363363

364-
- name: 🐛 Check installed packages for security vulnerability advisories
365-
run: composer audit --ansi
366-
367364
- name: 🔍 Run static analysis using phpstan
368365
run: composer stan:ci
369366

@@ -425,4 +422,55 @@ jobs:
425422
- name: 🧪 Run tests using phpunit/phpunit
426423
run: php vendor/bin/pest
427424

425+
refactoring:
426+
timeout-minutes: 4
427+
runs-on: ${{ matrix.os }}
428+
concurrency:
429+
cancel-in-progress: true
430+
group: refactoring-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
431+
strategy:
432+
fail-fast: true
433+
matrix:
434+
os:
435+
- ubuntu-latest
436+
php-version:
437+
- '8.2'
438+
dependencies:
439+
- locked
440+
steps:
441+
- name: 📦 Check out the codebase
442+
uses: actions/checkout@v4.1.1
443+
444+
- name: 🛠️ Setup PHP
445+
uses: shivammathur/setup-php@2.30.2
446+
with:
447+
php-version: ${{ matrix.php-version }}
448+
extensions: mbstring, pdo, pdo_sqlite
449+
ini-values: error_reporting=E_ALL
450+
coverage: none
451+
452+
- name: 🛠️ Setup problem matchers
453+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
454+
455+
- name: 🤖 Validate composer.json and composer.lock
456+
run: composer validate --ansi --strict
457+
458+
- name: 🔍 Get composer cache directory
459+
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@master
460+
461+
- name: ♻️ Restore cached dependencies installed with composer
462+
uses: actions/cache@v4.0.2
463+
with:
464+
path: ${{ env.COMPOSER_CACHE_DIR }}
465+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
466+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
467+
468+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies
469+
uses: wayofdev/gh-actions/actions/composer/install@master
470+
with:
471+
dependencies: ${{ matrix.dependencies }}
472+
473+
- name: ⚙️ Run automated refactoring with rector/rector
474+
run: composer refactor:ci
475+
428476
...

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ lint-audit: ## Runs security checks for composer dependencies
209209
$(APP_COMPOSER) audit
210210
.PHONY: lint-security
211211

212+
refactor: ## Runs rector – code refactoring tool
213+
$(APP_COMPOSER) refactor
214+
.PHONY: refactor
215+
212216
#
213217
# Testing
214218
# ------------------------------------------------------------------------------------

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"phpstan/phpstan-phpunit": "^1.3",
3636
"phpstan/phpstan-strict-rules": "^1.5",
3737
"phpunit/phpunit": "^10.5 || ^11.0",
38+
"rector/rector": "^1.0",
3839
"roave/security-advisories": "dev-latest",
3940
"wayofdev/cs-fixer-config": "^1.2"
4041
},
@@ -88,6 +89,8 @@
8889
"stan:ci": "php vendor/bin/phpstan analyse --memory-limit=2G --error-format=github",
8990
"stan:baseline": "php vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
9091
"test": "XDEBUG_MODE=coverage php vendor/bin/pest",
91-
"test:cc": "XDEBUG_MODE=coverage php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml"
92+
"test:cc": "XDEBUG_MODE=coverage php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml",
93+
"refactor": "php vendor/bin/rector process --config=rector.php",
94+
"refactor:ci": "php vendor/bin/rector process --config=rector.php --dry-run --ansi"
9295
}
9396
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rector.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config;
6+
use Rector\Php81;
7+
use Rector\PHPUnit;
8+
use Rector\ValueObject;
9+
10+
return static function (Config\RectorConfig $rectorConfig): void {
11+
$rectorConfig->cacheDirectory(__DIR__ . '/.build/rector/');
12+
13+
$rectorConfig->import(__DIR__ . '/vendor/fakerphp/faker/rector-migrate.php');
14+
15+
$rectorConfig->paths([
16+
__DIR__ . '/config/',
17+
__DIR__ . '/src/',
18+
__DIR__ . '/tests/',
19+
__DIR__ . '/.php-cs-fixer.dist.php',
20+
__DIR__ . '/rector.php',
21+
]);
22+
23+
$rectorConfig->phpVersion(ValueObject\PhpVersion::PHP_82);
24+
25+
$rectorConfig->rules([
26+
Php81\Rector\Property\ReadOnlyPropertyRector::class,
27+
]);
28+
29+
$rectorConfig->sets([
30+
PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
31+
]);
32+
};

0 commit comments

Comments
 (0)