Skip to content

Commit b0b0bf3

Browse files
committed
Adding Rector to ease backporting to PHP7.4
1 parent 3959179 commit b0b0bf3

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ phpcs:
2222
test:
2323
@docker run --rm -it -v$(PWD):/app composer test
2424

25-
# test
25+
# downgrade
26+
downgrade:
27+
@docker run --rm -it -v$(PWD):/app --workdir=/app php:8.1-cli-alpine vendor/bin/rector process src
28+
29+
# sandbox
2630
sandbox:
2731
@docker run --rm -it -v$(PWD):/app php:8.1-cli-alpine php ./app/test.php
2832

29-
.PHONY: install update phpunit phpstan phpcs test
33+
.PHONY: install update phpunit phpstan phpcs test sandbox downgrade

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"phpstan/phpstan-strict-rules": "^1.1",
3535
"phpstan/phpstan-phpunit": "^1.0",
3636
"phpstan/phpstan-deprecation-rules": "^1.0",
37-
"phpunit/phpunit": "^9.5.20"
37+
"phpunit/phpunit": "^9.5.20",
38+
"rector/rector": "~0.12.21"
3839
},
3940
"autoload": {
4041
"psr-4": {

rector.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Core\Configuration\Option;
6+
use Rector\DowngradePhp74\Rector\Coalesce\DowngradeNullCoalescingOperatorRector;
7+
use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector;
8+
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
9+
use Rector\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector;
10+
use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector;
11+
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector;
12+
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector;
13+
use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector;
14+
use Rector\DowngradePhp80\Rector\NullsafeMethodCall\DowngradeNullsafeToTernaryOperatorRector;
15+
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeStaticTypeDeclarationRector;
16+
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector;
17+
use Rector\DowngradePhp80\Rector\Expression\DowngradeThrowExprRector;
18+
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector;
19+
use Rector\DowngradePhp81\Rector\Array_\DowngradeArraySpreadStringKeyRector;
20+
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector;
21+
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector;
22+
use Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector;
23+
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
24+
25+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
26+
27+
return static function (ContainerConfigurator $containerConfigurator): void {
28+
29+
$parameters = $containerConfigurator->parameters();
30+
31+
$parameters->set(Option::PATHS, __DIR__.'/src');
32+
$parameters->set(Option::PHP_VERSION_FEATURES, 70400);
33+
34+
$services = $containerConfigurator->services();
35+
36+
$services->set(DowngradeTrailingCommasInParamUseRector::class);
37+
$services->set(DowngradeNonCapturingCatchesRector::class);
38+
$services->set(DowngradeUnionTypeTypedPropertyRector::class);
39+
$services->set(DowngradePropertyPromotionRector::class);
40+
$services->set(DowngradeUnionTypeDeclarationRector::class);
41+
$services->set(DowngradeNullsafeToTernaryOperatorRector::class);
42+
$services->set(DowngradeStaticTypeDeclarationRector::class);
43+
$services->set(DowngradeStrContainsRector::class);
44+
$services->set(DowngradeThrowExprRector::class);
45+
$services->set(DowngradeArrayIsListRector::class);
46+
$services->set(DowngradeArraySpreadStringKeyRector::class);
47+
$services->set(DowngradeFirstClassCallableSyntaxRector::class);
48+
$services->set(DowngradeNewInInitializerRector::class);
49+
$services->set(DowngradeReadonlyPropertyRector::class);
50+
$services->set(DowngradeMatchToSwitchRector::class);
51+
};

0 commit comments

Comments
 (0)