-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrector.php
More file actions
102 lines (91 loc) · 3.58 KB
/
Copy pathrector.php
File metadata and controls
102 lines (91 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
use PLUS\GrumPHPConfig\RectorSettings;
use PLUS\GrumPHPConfig\VersionUtility;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector;
use Ssch\TYPO3Rector\CodeQuality\General\GeneralUtilityMakeInstanceToConstructorPropertyRector;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;
use Ssch\TYPO3Rector\Set\Typo3SetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();
$rectorConfig->importNames();
$rectorConfig->importShortClasses();
$rectorConfig->cacheClass(FileCacheStorage::class);
$rectorConfig->cacheDirectory('./var/cache/rector');
$paths = array_filter(
explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php|html|typoscript)$'")),
static function ($path): bool {
if (!$path) {
return false;
}
return !str_starts_with($path, 'Tests/');
}
);
$rectorConfig->paths(
$paths
);
$phpVersion = VersionUtility::getMinimalPhpVersion() ?? PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
[$phpMajor, $phpMinor] = explode('.', $phpVersion, 3);
$phpSet = constant(LevelSetList::class . '::UP_TO_PHP_' . $phpMajor . $phpMinor);
$typo3Sets = [];
$minimalTypo3Version = VersionUtility::getMinimalTypo3Version();
if ($minimalTypo3Version !== null) {
[$typo3Major] = explode('.', $minimalTypo3Version, 2);
$typo3LevelSet = match ($typo3Major) {
'10' => Typo3LevelSetList::UP_TO_TYPO3_10,
'11' => Typo3LevelSetList::UP_TO_TYPO3_11,
'12' => Typo3LevelSetList::UP_TO_TYPO3_12,
'13' => Typo3LevelSetList::UP_TO_TYPO3_13,
'14', 'dev-main' => Typo3LevelSetList::UP_TO_TYPO3_14,
default => null,
};
if ($typo3LevelSet !== null) {
$typo3Sets = [
$typo3LevelSet,
Typo3SetList::CODE_QUALITY,
Typo3SetList::GENERAL,
];
}
}
/** @var list<string> $sets */
$sets =
[
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
SetList::TYPE_DECLARATION,
SetList::EARLY_RETURN,
SetList::INSTANCEOF,
$phpSet,
...$typo3Sets,
];
// define sets of rules
$rectorConfig->sets($sets);
// ignore some files
$rectorConfig->skip(
[
...RectorSettings::skip(),
PrivatizeFinalClassPropertyRector::class,
PrivatizeFinalClassMethodRector::class,
RemoveExtraParametersRector::class,
RemoveUnusedPrivateMethodRector::class,
GeneralUtilityMakeInstanceToConstructorPropertyRector::class,
ParamTypeByParentCallTypeRector::class => [
__DIR__ . '/Classes/Cache/CacheManager.php'
],
RemoveUselessParamTagRector::class => [
__DIR__ . '/Classes/Cache/CacheManager.php'
],
]
);
};