|
1 | 1 | <?php declare(strict_types=1); |
2 | 2 |
|
3 | 3 | use Rector\Core\Configuration\Option; |
4 | | -use Rector\Core\ValueObject\PhpVersion; |
5 | 4 | use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector; |
6 | 5 | use Rector\DowngradePhp73\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector; |
7 | 6 | use Rector\DowngradePhp74\Rector\Coalesce\DowngradeNullCoalescingOperatorRector; |
8 | 7 | use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector; |
9 | 8 | use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector; |
10 | 9 | use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
11 | 10 |
|
| 11 | + |
| 12 | + |
12 | 13 | return static function (ContainerConfigurator $containerConfigurator): void { |
| 14 | + $parsePhpVersion = static function (string $version, int $defaultPatch = 0): int { |
| 15 | + $parts = array_map('intval', explode('.', $version)); |
| 16 | + |
| 17 | + return $parts[0] * 10000 + $parts[1] * 100 + ($parts[2] ?? $defaultPatch); |
| 18 | + }; |
| 19 | + $targetPhpVersion = getenv('TARGET_PHP_VERSION'); |
| 20 | + $targetPhpVersionId = $parsePhpVersion($targetPhpVersion); |
| 21 | + |
13 | 22 | $parameters = $containerConfigurator->parameters(); |
14 | 23 |
|
15 | | - $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_71); |
| 24 | + $parameters->set(Option::PHP_VERSION_FEATURES, $targetPhpVersionId); |
16 | 25 | $parameters->set(Option::SKIP, [ |
17 | 26 | 'tests/*/data/*', |
18 | 27 | 'tests/PHPStan/Analyser/traits/*', |
|
23 | 32 | ]); |
24 | 33 |
|
25 | 34 | $services = $containerConfigurator->services(); |
26 | | - $services->set(DowngradeTypedPropertyRector::class); |
27 | | - $services->set(DowngradeTrailingCommasInFunctionCallsRector::class); |
28 | | - $services->set(DowngradeObjectTypeDeclarationRector::class); |
29 | | - $services->set(DowngradeNullCoalescingOperatorRector::class); |
30 | | - $services->set(ArrowFunctionToAnonymousFunctionRector::class); |
| 35 | + |
| 36 | + if ($targetPhpVersionId < 70400) { |
| 37 | + $services->set(DowngradeTypedPropertyRector::class); |
| 38 | + $services->set(DowngradeNullCoalescingOperatorRector::class); |
| 39 | + $services->set(ArrowFunctionToAnonymousFunctionRector::class); |
| 40 | + } |
| 41 | + |
| 42 | + if ($targetPhpVersionId < 70300) { |
| 43 | + $services->set(DowngradeTrailingCommasInFunctionCallsRector::class); |
| 44 | + } |
| 45 | + |
| 46 | + if ($targetPhpVersionId < 70200) { |
| 47 | + $services->set(DowngradeObjectTypeDeclarationRector::class); |
| 48 | + } |
31 | 49 | }; |
0 commit comments