forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rector-upgrade-compatibility.php
67 lines (57 loc) · 2.4 KB
/
rector-upgrade-compatibility.php
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
<?php
declare(strict_types=1);
use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Repositories\ModuleRepository;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector;
use Rector\Renaming\Rector\Namespace_\RenameNamespaceRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector;
use Rector\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddPropertyTypeDeclaration;
return static function (RectorConfig $config): void {
$paths = [
getcwd() . '/app/',
getcwd() . '/resources/',
getcwd() . '/routes/',
getcwd() . '/config/',
];
$enablePaths = [];
foreach ($paths as $path) {
if (file_exists($path)) {
$enablePaths[] = $path;
}
}
// Update compatibility.
$config->paths($enablePaths);
$config->importNames(false);
$config->importShortClasses(false);
$config->phpVersion(PhpVersion::PHP_80);
$config->disableParallel();
$config->ruleWithConfiguration(RenameNamespaceRector::class, [
'App\Http\Controllers\Admin' => 'App\Http\Controllers\Twill',
'App\Http\Requests\Admin' => 'App\Http\Requests\Twill',
]);
$config->rule(AddReturnTypeDeclarationBasedOnParentClassMethodRector::class);
$config->rule(AddMethodCallBasedStrictParamTypeRector::class);
$config->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
$config->rule(ParamTypeByParentCallTypeRector::class);
$config->rule(AddParamBasedOnParentClassMethodRector::class);
$config->ruleWithConfiguration(AddPropertyTypeDeclarationRector::class, [
new AddPropertyTypeDeclaration(
ModuleRepository::class,
'fieldsGroups',
new ArrayType(new MixedType(), new MixedType())
),
new AddPropertyTypeDeclaration(
ModuleRepository::class,
'model',
new PHPStan\Type\ObjectType(TwillModelContract::class)
),
]);
};