-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathrector-php.php
162 lines (153 loc) · 6.09 KB
/
rector-php.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
declare(strict_types=1);
use AmazonPHP\Rector\ClassMethod\FixArgumentDefaultValuesNotMatchingTypeRector;
use AmazonPHP\Rector\ClassMethod\SetNullableFunctionReturnTypeRector;
use AmazonPHP\Rector\ValueObject\NullableReturnTypeDeclaration;
use AmazonPHP\SellingPartner\Model\CatalogItem\Item as CatalogItem;
use AmazonPHP\SellingPartner\Model\CatalogItem\ItemSearchResults;
use AmazonPHP\SellingPartner\Model\FulfillmentInboundV0\InboundShipmentInfo;
use AmazonPHP\SellingPartner\Model\ListingsItems\Item as ListingsItem;
use AmazonPHP\SellingPartner\Model\ListingsItems\ItemProcurement;
use AmazonPHP\SellingPartner\Model\ListingsItems\ListingsItemPutRequest;
use AmazonPHP\SellingPartner\Model\Messaging\GetSchemaResponse;
use AmazonPHP\SellingPartner\Model\Orders\Address;
use AmazonPHP\SellingPartner\Model\ProductPricing\GetOffersResult;
use AmazonPHP\SellingPartner\Model\Uploads\UploadDestination;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
return static function (RectorConfig $config): void {
$config->parallel(seconds: 1200);
$config->autoloadPaths([
__DIR__ ,
]);
$config->paths([
__DIR__ . '/src/AmazonPHP/SellingPartner/Api',
__DIR__ . '/src/AmazonPHP/SellingPartner/Model',
]);
$config->cacheClass(MemoryCacheStorage::class);
$config->rules([
FixArgumentDefaultValuesNotMatchingTypeRector::class,
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
]);
$config->sets([
SetList::PHP_73,
SetList::PHP_74,
SetList::PHP_80,
SetList::PHP_81,
SetList::TYPE_DECLARATION,
]);
/**
* Explanation here: https://github.com/amazon-php/sp-api-sdk/issues/101#issuecomment-1002159988
*/
$config->ruleWithConfiguration(
AddParamTypeDeclarationRector::class,
[
new AddParamTypeDeclaration(
CatalogItem::class,
'setAttributes',
0,
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())])
),
new AddParamTypeDeclaration(
ListingsItemPutRequest::class,
'setAttributes',
0,
new ArrayType(new MixedType(), new MixedType())
),
new AddParamTypeDeclaration(
ListingsItem::class,
'setAttributes',
0,
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())])
),
new AddParamTypeDeclaration(
GetSchemaResponse::class,
'setPayload',
0,
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())])
),
new AddParamTypeDeclaration(
UploadDestination::class,
'setHeaders',
0,
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())])
),
]
);
$config->ruleWithConfiguration(
AddReturnTypeDeclarationRector::class,
[
new AddReturnTypeDeclaration(
GetOffersResult::class,
'getMarketplaceId',
new UnionType([new NullType(), new StringType()]),
),
new AddReturnTypeDeclaration(
CatalogItem::class,
'getAttributes',
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]),
),
new AddReturnTypeDeclaration(
ListingsItemPutRequest::class,
'getAttributes',
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]),
),
new AddReturnTypeDeclaration(
GetSchemaResponse::class,
'getPayload',
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]),
),
new AddReturnTypeDeclaration(
GetSchemaResponse::class,
'getHeaders',
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]),
),
// https://github.com/amazon-php/sp-api-sdk/pull/118
new AddReturnTypeDeclaration(
Address::class,
'getName',
new UnionType([new NullType(), new StringType()]),
),
new AddReturnTypeDeclaration(
ListingsItem::class,
'getAttributes',
new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]),
),
]
);
/**
* Contrary to Amazon's schema, some of the properties are in fact nullable - this rule will fix that.
*/
$config->ruleWithConfiguration(
SetNullableFunctionReturnTypeRector::class,
[
/**
* Fulfillment Inbound API
*/
new NullableReturnTypeDeclaration(InboundShipmentInfo::class, 'getAreCasesRequired'),
/**
* Listings API
*/
new NullableReturnTypeDeclaration(ItemProcurement::class, 'getCostPrice'),
/**
* Catalog Items API
*/
new NullableReturnTypeDeclaration(ItemSearchResults::class, 'getPagination'),
new NullableReturnTypeDeclaration(ItemSearchResults::class, 'getRefinements'),
]
);
};