|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use AmazonPHP\Rector\ClassMethod\FixArgumentDefaultValuesNotMatchingTypeRector; |
| 6 | +use AmazonPHP\Rector\ClassMethod\SetNullableFunctionReturnTypeRector; |
| 7 | +use AmazonPHP\Rector\ValueObject\NullableReturnTypeDeclaration; |
| 8 | +use AmazonPHP\SellingPartner\Model\CatalogItem\Item as CatalogItem; |
| 9 | +use AmazonPHP\SellingPartner\Model\CatalogItem\ItemSearchResults; |
| 10 | +use AmazonPHP\SellingPartner\Model\FulfillmentInboundV0\InboundShipmentInfo; |
| 11 | +use AmazonPHP\SellingPartner\Model\ListingsItems\Item as ListingsItem; |
| 12 | +use AmazonPHP\SellingPartner\Model\ListingsItems\ItemProcurement; |
| 13 | +use AmazonPHP\SellingPartner\Model\ListingsItems\ListingsItemPutRequest; |
| 14 | +use AmazonPHP\SellingPartner\Model\Messaging\GetSchemaResponse; |
| 15 | +use AmazonPHP\SellingPartner\Model\Orders\Address; |
| 16 | +use AmazonPHP\SellingPartner\Model\ProductPricing\GetOffersResult; |
| 17 | +use AmazonPHP\SellingPartner\Model\Uploads\UploadDestination; |
| 18 | +use PHPStan\Type\ArrayType; |
| 19 | +use PHPStan\Type\BooleanType; |
| 20 | +use PHPStan\Type\MixedType; |
| 21 | +use PHPStan\Type\NullType; |
| 22 | +use PHPStan\Type\StringType; |
| 23 | +use PHPStan\Type\UnionType; |
| 24 | +use Rector\Caching\ValueObject\Storage\MemoryCacheStorage; |
| 25 | +use Rector\Config\RectorConfig; |
| 26 | +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; |
| 27 | +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; |
| 28 | +use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector; |
| 29 | +use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector; |
| 30 | +use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration; |
| 31 | +use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration; |
| 32 | + |
| 33 | +return static function (RectorConfig $config): void { |
| 34 | + |
| 35 | + $config->parallel(seconds: 1200); |
| 36 | + |
| 37 | + $config->autoloadPaths([ |
| 38 | + __DIR__ , |
| 39 | + ]); |
| 40 | + |
| 41 | + $config->paths([ |
| 42 | + __DIR__ . '/src/AmazonPHP/SellingPartner/Api', |
| 43 | + __DIR__ . '/src/AmazonPHP/SellingPartner/Model', |
| 44 | + ]); |
| 45 | + |
| 46 | + $config->cacheClass(MemoryCacheStorage::class); |
| 47 | + |
| 48 | + $config->rules([ |
| 49 | + FixArgumentDefaultValuesNotMatchingTypeRector::class, |
| 50 | + RemoveUselessParamTagRector::class, |
| 51 | + RemoveUselessReturnTagRector::class, |
| 52 | + ]); |
| 53 | + |
| 54 | + /** |
| 55 | + * Explanation here: https://github.com/amazon-php/sp-api-sdk/issues/101#issuecomment-1002159988 |
| 56 | + */ |
| 57 | + $config->ruleWithConfiguration( |
| 58 | + AddParamTypeDeclarationRector::class, |
| 59 | + [ |
| 60 | + new AddParamTypeDeclaration( |
| 61 | + CatalogItem::class, |
| 62 | + 'setAttributes', |
| 63 | + 0, |
| 64 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]) |
| 65 | + ), |
| 66 | + new AddParamTypeDeclaration( |
| 67 | + ListingsItemPutRequest::class, |
| 68 | + 'setAttributes', |
| 69 | + 0, |
| 70 | + new ArrayType(new MixedType(), new MixedType()) |
| 71 | + ), |
| 72 | + new AddParamTypeDeclaration( |
| 73 | + ListingsItem::class, |
| 74 | + 'setAttributes', |
| 75 | + 0, |
| 76 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]) |
| 77 | + ), |
| 78 | + new AddParamTypeDeclaration( |
| 79 | + GetSchemaResponse::class, |
| 80 | + 'setPayload', |
| 81 | + 0, |
| 82 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]) |
| 83 | + ), |
| 84 | + new AddParamTypeDeclaration( |
| 85 | + UploadDestination::class, |
| 86 | + 'setHeaders', |
| 87 | + 0, |
| 88 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]) |
| 89 | + ), |
| 90 | + ] |
| 91 | + ); |
| 92 | + |
| 93 | + $config->ruleWithConfiguration( |
| 94 | + AddReturnTypeDeclarationRector::class, |
| 95 | + [ |
| 96 | + new AddReturnTypeDeclaration( |
| 97 | + GetOffersResult::class, |
| 98 | + 'getMarketplaceId', |
| 99 | + new UnionType([new NullType(), new StringType()]), |
| 100 | + ), |
| 101 | + new AddReturnTypeDeclaration( |
| 102 | + CatalogItem::class, |
| 103 | + 'getAttributes', |
| 104 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]), |
| 105 | + ), |
| 106 | + new AddReturnTypeDeclaration( |
| 107 | + ListingsItemPutRequest::class, |
| 108 | + 'getAttributes', |
| 109 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]), |
| 110 | + ), |
| 111 | + new AddReturnTypeDeclaration( |
| 112 | + GetSchemaResponse::class, |
| 113 | + 'getPayload', |
| 114 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]), |
| 115 | + ), |
| 116 | + new AddReturnTypeDeclaration( |
| 117 | + GetSchemaResponse::class, |
| 118 | + 'getHeaders', |
| 119 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]), |
| 120 | + ), |
| 121 | + // https://github.com/amazon-php/sp-api-sdk/pull/118 |
| 122 | + new AddReturnTypeDeclaration( |
| 123 | + Address::class, |
| 124 | + 'getName', |
| 125 | + new UnionType([new NullType(), new StringType()]), |
| 126 | + ), |
| 127 | + new AddReturnTypeDeclaration( |
| 128 | + ListingsItem::class, |
| 129 | + 'getAttributes', |
| 130 | + new UnionType([new NullType(), new ArrayType(new MixedType(), new MixedType())]), |
| 131 | + ), |
| 132 | + ] |
| 133 | + ); |
| 134 | + |
| 135 | + /** |
| 136 | + * Contrary to Amazon's schema, some of the properties are in fact nullable - this rule will fix that. |
| 137 | + */ |
| 138 | + $config->ruleWithConfiguration( |
| 139 | + SetNullableFunctionReturnTypeRector::class, |
| 140 | + [ |
| 141 | + /** |
| 142 | + * Fulfillment Inbound API |
| 143 | + */ |
| 144 | + new NullableReturnTypeDeclaration(InboundShipmentInfo::class, 'getAreCasesRequired'), |
| 145 | + /** |
| 146 | + * Listings API |
| 147 | + */ |
| 148 | + new NullableReturnTypeDeclaration(ItemProcurement::class, 'getCostPrice'), |
| 149 | + /** |
| 150 | + * Catalog Items API |
| 151 | + */ |
| 152 | + new NullableReturnTypeDeclaration(ItemSearchResults::class, 'getPagination'), |
| 153 | + new NullableReturnTypeDeclaration(ItemSearchResults::class, 'getRefinements'), |
| 154 | + ] |
| 155 | + ); |
| 156 | +}; |
0 commit comments