-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.php
63 lines (56 loc) · 3.33 KB
/
upgrade.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
<?php
declare(strict_types=1);
use PHPStan\Type\VoidType;
use Rector\Composer\Rector\ChangePackageVersionComposerRector;
use Rector\Composer\ValueObject\PackageAndVersion;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\Namespace_\RenameNamespaceRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
function upgradeEventSauceFrom0to1(ContainerConfigurator $containerConfigurator, $version = '^1.0'): void {
$services = $containerConfigurator->services();
$services->set(ChangePackageVersionComposerRector::class)
->call('configure', [[
ChangePackageVersionComposerRector::PACKAGES_AND_VERSIONS => ValueObjectInliner::inline([
new PackageAndVersion('eventsauce/eventsauce', $version),
]),
]]);
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => ValueObjectInliner::inline([
new AddReturnTypeDeclaration('EventSauce\\EventSourcing\\Consumer', 'handle', new VoidType()),
new AddReturnTypeDeclaration('EventSauce\\EventSourcing\\MessageConsumer', 'handle', new VoidType()),
new AddReturnTypeDeclaration('EventSauce\\EventSourcing\\MessageRepository', 'persist', new VoidType()),
new AddReturnTypeDeclaration('EventSauce\\EventSourcing\\MessageRepository', 'persistEvents', new VoidType()),
])
]]);
$services->set(RenameNamespaceRector::class)
->call('configure', [[
RenameNamespaceRector::OLD_TO_NEW_NAMESPACES => [
'EventSauce\\EventSourcing\\Time\\' => 'EventSauce\\Clock\\',
]
]]);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
'EventSauce\\EventSourcing\\InvalidAggregateRootReconstitutionException' => 'EventSauce\\EventSourcing\\UnableToReconstituteAggregateRoot',
'EventSauce\\EventSourcing\\Consumer' => 'EventSauce\\EventSourcing\\MessageConsumer',
'EventSauce\\EventSourcing\\AggregateRootTestCase' => 'EventSauce\\EventSourcing\\TestUtilities\\AggregateRootTestCase',
]
]]);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => ValueObjectInliner::inline([
new MethodCallRename('EventSauce\\Clock\\Clock', 'dateTime', 'now'),
new MethodCallRename('EventSauce\\Clock\\TestClock', 'dateTime', 'now'),
new MethodCallRename('EventSauce\\EventSourcing\\Time\\Clock', 'dateTime', 'now'),
new MethodCallRename('EventSauce\\EventSourcing\\Time\\TestClock', 'dateTime', 'now'),
new MethodCallRename('EventSauce\\EventSourcing\\Time\\SystemClock', 'dateTime', 'now'),
new MethodCallRename('EventSauce\\EventSourcing\\Time\\SystemTestClock', 'dateTime', 'now'),
])
]]);
}