From e1afb9dc829bcde62c34fcfe8f09a653d0c9131d Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Mon, 17 Jun 2024 15:02:16 +0200 Subject: [PATCH 1/4] [TASK] Add rector to composer.json with a simple null-config Adding rector as a development dependency enables us to do automatic refactorings. Initially this comes with a simple null-config, that does not do much but run rector, so following the suggested integration path of "taking it slow" [1]. Helps with #432 [1] https://getrector.com/documentation/integration-to-new-project Signed-off-by: Daniel Ziegenberg --- composer.json | 11 +++++++++-- config/rector.php | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 config/rector.php diff --git a/composer.json b/composer.json index 810e0ade..d363939f 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "phpstan/extension-installer": "^1.4.1", "phpstan/phpstan": "^1.11.4", "phpstan/phpstan-phpunit": "^1.4.0", - "phpunit/phpunit": "^8.5.38" + "phpunit/phpunit": "^8.5.38", + "rector/rector": "^1.1.0" }, "suggest": { "ext-mbstring": "for parsing UTF-8 CSS" @@ -70,8 +71,10 @@ ], "ci:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests", "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", + "ci:php:rector": "\"./vendor/bin/rector\" --no-progress-bar --dry-run --config=config/rector.php", "ci:static": [ "@ci:php:fixer", + "@ci:php:rector", "@ci:php:stan" ], "ci:tests": [ @@ -80,9 +83,11 @@ "ci:tests:sof": "\"./vendor/bin/phpunit\" --stop-on-failure --do-not-cache-result", "ci:tests:unit": "\"./vendor/bin/phpunit\" --do-not-cache-result", "fix:php": [ - "@fix:php:fixer" + "@fix:php:fixer", + "@fix:php:rector" ], "fix:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix bin src tests", + "fix:php:rector": "\"./vendor/bin/rector\" --config=config/rector.php", "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": { @@ -90,12 +95,14 @@ "ci:dynamic": "Runs all dynamic code checks (i.e., currently, the unit tests).", "ci:php:fixer": "Checks the code style with PHP CS Fixer.", "ci:php:stan": "Checks the types with PHPStan.", + "ci:php:rector": "Checks the code for possible code updates and refactoring.", "ci:static": "Runs all static code analysis checks for the code.", "ci:tests": "Runs all dynamic tests (i.e., currently, the unit tests).", "ci:tests:sof": "Runs the unit tests and stops at the first failure.", "ci:tests:unit": "Runs all unit tests.", "fix:php": "Autofixes all autofixable issues in the PHP code.", "fix:php:fixer": "Fixes autofixable issues found by PHP CS Fixer.", + "fix:php:rector": "Fixes autofixable issues found by Rector.", "phpstan:baseline": "Updates the PHPStan baseline file to match the code." } } diff --git a/config/rector.php b/config/rector.php new file mode 100644 index 00000000..2b8904db --- /dev/null +++ b/config/rector.php @@ -0,0 +1,21 @@ +withPaths( + [ + __DIR__ . '/../src', + __DIR__ . '/../tests', + ] + ) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withRules( + [ + // AddVoidReturnTypeWhereNoReturnRector::class, + ] + ); From 409cab051d0808f0b55ee6df449cd86fe4e601ab Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Mon, 17 Jun 2024 15:08:48 +0200 Subject: [PATCH 2/4] [TASK] Add rector to github actions Signed-off-by: Daniel Ziegenberg --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 647996ff..a6236052 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,7 @@ jobs: command: - fixer - stan + - rector php-version: - '8.3' From 82f0dcb73502a28a904d2e947745b44c2135305d Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Mon, 17 Jun 2024 16:09:33 +0200 Subject: [PATCH 3/4] fixup! [TASK] Add rector to composer.json with a simple null-config --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d363939f..4fdb23ac 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,7 @@ ], "ci:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests", "ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon", - "ci:php:rector": "\"./vendor/bin/rector\" --no-progress-bar --dry-run --config=config/rector.php", + "ci:php:rector": "rector --no-progress-bar --dry-run --config=config/rector.php", "ci:static": [ "@ci:php:fixer", "@ci:php:rector", @@ -87,7 +87,7 @@ "@fix:php:rector" ], "fix:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix bin src tests", - "fix:php:rector": "\"./vendor/bin/rector\" --config=config/rector.php", + "fix:php:rector": "vendor/bin/rector --config=config/rector.php", "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": { From 89bce8bf2bd7753a190cb6748cc68829566130b9 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Mon, 17 Jun 2024 17:05:37 +0200 Subject: [PATCH 4/4] fixup! [TASK] Add rector to composer.json with a simple null-config --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4fdb23ac..d2b1eb4b 100644 --- a/composer.json +++ b/composer.json @@ -87,7 +87,7 @@ "@fix:php:rector" ], "fix:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix bin src tests", - "fix:php:rector": "vendor/bin/rector --config=config/rector.php", + "fix:php:rector": "rector --config=config/rector.php", "phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon" }, "scripts-descriptions": {