forked from rectorphp/rector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
league-event-30.php
101 lines (89 loc) · 4.53 KB
/
league-event-30.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
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
<?php
declare(strict_types=1);
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\VoidType;
use Rector\Composer\Rector\ChangePackageVersionComposerRector;
use Rector\Composer\ValueObject\PackageAndVersion;
use Rector\Core\Configuration\Option;
use Rector\Removing\Rector\Class_\RemoveInterfacesRector;
use Rector\Removing\Rector\Class_\RemoveParentRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\Class_\AddInterfaceByParentRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services = $containerConfigurator->services();
$services->set(ChangePackageVersionComposerRector::class)
->call('configure', [[
ChangePackageVersionComposerRector::PACKAGES_AND_VERSIONS => ValueObjectInliner::inline([
new PackageAndVersion('league/event', '^3.0'),
]),
]]);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
new MethodCallRename('League\Event\EventInterface', 'getName', 'eventName'),
new MethodCallRename('League\Event\EmitterInterface', 'emit', 'dispatch'),
new MethodCallRename('League\Event\EmitterInterface', 'addListener', 'subscribeTo'),
new MethodCallRename('League\Event\EmitterInterface', 'addOneTimeListener', 'subscribeOneTo'),
new MethodCallRename('League\Event\EmitterInterface', 'useListenerProvider', 'subscribeListenersFrom'),
new MethodCallRename('League\Event\ListenerInterface', 'handle', '__invoke'),
]),
]]);
$services->set(AddParamTypeDeclarationRector::class)
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => ValueObjectInliner::inline([
new AddParamTypeDeclaration(
'League\Event\ListenerInterface',
'__invoke',
0,
new ObjectWithoutClassType()
),
]),
]]);
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => ValueObjectInliner::inline([
new AddReturnTypeDeclaration('League\Event\EventInterface', 'eventName', new StringType()),
new AddReturnTypeDeclaration('League\Event\ListenerInterface', '__invoke', new VoidType()),
]),
]]);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'League\Event\Emitter' => 'League\Event\EventDispatcher',
'League\Event\ListenerInterface' => 'League\Event\Listener',
'League\Event\GeneratorInterface' => 'League\Event\EventGenerator',
'League\Event\ListenerProviderInterface' => 'League\Event\ListenerSubscriber',
'League\Event\ListenerAcceptorInterface' => 'League\Event\ListenerRegistry',
],
]]);
$services->set(AddInterfaceByParentRector::class)
->call('configure', [[
AddInterfaceByParentRector::INTERFACE_BY_PARENT => [
'League\Event\AbstractEvent' => 'League\Event\HasEventName',
'League\Event\AbstractListener' => 'League\Event\Listener',
],
]]);
$services->set(RemoveInterfacesRector::class)
->call('configure', [[
RemoveInterfacesRector::INTERFACES_TO_REMOVE => ['League\Event\EventInterface'],
]]);
$services->set(RemoveParentRector::class)
->call('configure', [[
RemoveParentRector::PARENT_TYPES_TO_REMOVE => [
'League\Event\AbstractEvent',
'League\Event\Event',
'League\Event\AbstractListener',
],
]]);
};