Skip to content

Commit 514e81f

Browse files
committed
Loosen version, clean up config
1 parent e86009a commit 514e81f

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ predefined rulesets. Rector can be highly opinionated based on its configuration
130130
so be sure to read the documentation and figure out the best fit for you. This workflow performs
131131
a "dry run" to check for any changes that Rector would have made and fail if there are matches.
132132

133+
> Note: Rector updates rules all the time so you may want to lock your repo to the latest known working version of Rector to prevent unexpected failures
134+
> E.g. in **.github/workflows/rector.yml** supply the specific minor patch: `composer global require --dev rector/rector:0.12.4`
135+
133136
#### Unused
134137

135138
Composer Unused does one thing: checks that your code actually uses the dependencies you

src/.github/workflows/rector.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ jobs:
6464
6565
- name: Analyze for refactoring
6666
run: |
67-
composer global require --dev rector/rector:^0.12.4
67+
composer global require --dev rector/rector
6868
rector process --dry-run --no-progress-bar

src/rector.php

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,69 +27,62 @@
2727
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
2828
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
2929
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
30-
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;
31-
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
3230
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
3331
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
34-
use Rector\PHPUnit\Rector\MethodCall\AssertFalseStrposToContainsRector;
3532
use Rector\PHPUnit\Set\PHPUnitSetList;
3633
use Rector\Set\ValueObject\LevelSetList;
3734
use Rector\Set\ValueObject\SetList;
3835
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
3936

4037
return static function (ContainerConfigurator $containerConfigurator): void {
38+
// Rule sets to apply
4139
$containerConfigurator->import(SetList::DEAD_CODE);
4240
$containerConfigurator->import(LevelSetList::UP_TO_PHP_73);
4341
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);
4442
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_80);
4543

4644
$parameters = $containerConfigurator->parameters();
4745

48-
// paths to refactor; solid alternative to CLI arguments
49-
$parameters->set(Option::PATHS, [__DIR__ . '/app', __DIR__ . '/tests']);
46+
// The paths to refactor (can also be supplied with CLI arguments)
47+
$parameters->set(Option::PATHS, [
48+
__DIR__ . '/app',
49+
__DIR__ . '/tests',
50+
]);
5051

51-
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
52+
// Do you need to include constants, class aliases, or a custom autoloader?
5253
$parameters->set(Option::BOOTSTRAP_FILES, [
53-
realpath(getcwd()) . '/vendor/autoload.php',
5454
realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php',
5555
]);
5656

57-
// is there a file you need to skip?
57+
// Set the target version for refactoring
58+
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
59+
60+
// Auto-import fully qualified class names
61+
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
62+
63+
// Are there files or rules you need to skip?
5864
$parameters->set(Option::SKIP, [
5965
__DIR__ . '/app/Views',
6066

6167
JsonThrowOnErrorRector::class,
6268
StringifyStrNeedlesRector::class,
6369

64-
// requires php 8
70+
// Note: requires php 8
6571
RemoveUnusedPromotedPropertyRector::class,
6672

67-
// call on purpose for nothing happen check
73+
// Ignore tests that might make calls without a result
6874
RemoveEmptyMethodCallRector::class => [
6975
__DIR__ . '/tests',
7076
],
7177

72-
// may cause load view files directly when detecting class that
73-
// make warning
78+
// May load view files directly when detecting classes
7479
StringClassNameToClassConstantRector::class,
7580

76-
// sometime too detail
77-
CountOnNullRector::class,
78-
79-
// may not be unitialized on purpose
81+
// May be uninitialized on purpose
8082
AddDefaultValueForUndefinedVariableRector::class,
81-
82-
// use mt_rand instead of random_int on purpose on non-cryptographically random
83-
RandomFunctionRector::class,
84-
85-
// assertContains() to string can't be used in PHPUnit 9.1
86-
AssertFalseStrposToContainsRector::class,
8783
]);
8884

89-
// auto import fully qualified class names
90-
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
91-
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
92-
85+
// Additional rules to apply
9386
$services = $containerConfigurator->services();
9487
$services->set(SimplifyUselessVariableRector::class);
9588
$services->set(RemoveAlwaysElseRector::class);

0 commit comments

Comments
 (0)