Skip to content

Commit e1afb9d

Browse files
committed
[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 MyIntervals#432 [1] https://getrector.com/documentation/integration-to-new-project Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
1 parent 06d4f5b commit e1afb9d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"phpstan/extension-installer": "^1.4.1",
3232
"phpstan/phpstan": "^1.11.4",
3333
"phpstan/phpstan-phpunit": "^1.4.0",
34-
"phpunit/phpunit": "^8.5.38"
34+
"phpunit/phpunit": "^8.5.38",
35+
"rector/rector": "^1.1.0"
3536
},
3637
"suggest": {
3738
"ext-mbstring": "for parsing UTF-8 CSS"
@@ -70,8 +71,10 @@
7071
],
7172
"ci:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots --diff bin src tests",
7273
"ci:php:stan": "phpstan --no-progress --configuration=config/phpstan.neon",
74+
"ci:php:rector": "\"./vendor/bin/rector\" --no-progress-bar --dry-run --config=config/rector.php",
7375
"ci:static": [
7476
"@ci:php:fixer",
77+
"@ci:php:rector",
7578
"@ci:php:stan"
7679
],
7780
"ci:tests": [
@@ -80,22 +83,26 @@
8083
"ci:tests:sof": "\"./vendor/bin/phpunit\" --stop-on-failure --do-not-cache-result",
8184
"ci:tests:unit": "\"./vendor/bin/phpunit\" --do-not-cache-result",
8285
"fix:php": [
83-
"@fix:php:fixer"
86+
"@fix:php:fixer",
87+
"@fix:php:rector"
8488
],
8589
"fix:php:fixer": "\"./.phive/php-cs-fixer\" --config=config/php-cs-fixer.php fix bin src tests",
90+
"fix:php:rector": "\"./vendor/bin/rector\" --config=config/rector.php",
8691
"phpstan:baseline": "phpstan --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon"
8792
},
8893
"scripts-descriptions": {
8994
"ci": "Runs all dynamic and static code checks.",
9095
"ci:dynamic": "Runs all dynamic code checks (i.e., currently, the unit tests).",
9196
"ci:php:fixer": "Checks the code style with PHP CS Fixer.",
9297
"ci:php:stan": "Checks the types with PHPStan.",
98+
"ci:php:rector": "Checks the code for possible code updates and refactoring.",
9399
"ci:static": "Runs all static code analysis checks for the code.",
94100
"ci:tests": "Runs all dynamic tests (i.e., currently, the unit tests).",
95101
"ci:tests:sof": "Runs the unit tests and stops at the first failure.",
96102
"ci:tests:unit": "Runs all unit tests.",
97103
"fix:php": "Autofixes all autofixable issues in the PHP code.",
98104
"fix:php:fixer": "Fixes autofixable issues found by PHP CS Fixer.",
105+
"fix:php:rector": "Fixes autofixable issues found by Rector.",
99106
"phpstan:baseline": "Updates the PHPStan baseline file to match the code."
100107
}
101108
}

config/rector.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
7+
8+
return RectorConfig::configure()
9+
->withPaths(
10+
[
11+
__DIR__ . '/../src',
12+
__DIR__ . '/../tests',
13+
]
14+
)
15+
// uncomment to reach your current PHP version
16+
// ->withPhpSets()
17+
->withRules(
18+
[
19+
// AddVoidReturnTypeWhereNoReturnRector::class,
20+
]
21+
);

0 commit comments

Comments
 (0)