From 838d315a76b12fbb070b37939ea89d686b091f44 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Tue, 22 Sep 2020 15:50:14 +0200 Subject: [PATCH] [Downgrade PHP 7.3] Trailing commas in function calls --- composer.json | 2 + config/set/downgrade-php73.php | 11 +++ ...adeTrailingCommasInFunctionCallsRector.php | 72 +++++++++++++++++++ ...railingCommasInFunctionCallsRectorTest.php | 40 +++++++++++ .../Fixture/fixture.php.inc | 33 +++++++++ 5 files changed, 158 insertions(+) create mode 100644 config/set/downgrade-php73.php create mode 100644 rules/downgrade-php73/src/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php create mode 100644 rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/DowngradeTrailingCommasInFunctionCallsRectorTest.php create mode 100644 rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc diff --git a/composer.json b/composer.json index 67630432f9ff..942823b2f476 100644 --- a/composer.json +++ b/composer.json @@ -150,6 +150,7 @@ "Rector\\NetteCodeQuality\\": "rules/nette-code-quality/src", "Rector\\DowngradePhp71\\": "rules/downgrade-php71/src", "Rector\\DowngradePhp72\\": "rules/downgrade-php72/src", + "Rector\\DowngradePhp73\\": "rules/downgrade-php73/src", "Rector\\DowngradePhp74\\": "rules/downgrade-php74/src", "Rector\\DowngradePhp80\\": "rules/downgrade-php80/src", "Rector\\SymfonyPhpConfig\\": "rules/symfony-php-config/src" @@ -238,6 +239,7 @@ "Rector\\NetteCodeQuality\\Tests\\": "rules/nette-code-quality/tests", "Rector\\DowngradePhp71\\Tests\\": "rules/downgrade-php71/tests", "Rector\\DowngradePhp72\\Tests\\": "rules/downgrade-php72/tests", + "Rector\\DowngradePhp73\\Tests\\": "rules/downgrade-php73/tests", "Rector\\DowngradePhp74\\Tests\\": "rules/downgrade-php74/tests", "Rector\\DowngradePhp80\\Tests\\": "rules/downgrade-php80/tests", "Rector\\SymfonyPhpConfig\\Tests\\": "rules/symfony-php-config/tests", diff --git a/config/set/downgrade-php73.php b/config/set/downgrade-php73.php new file mode 100644 index 000000000000..6fd54b9cc090 --- /dev/null +++ b/config/set/downgrade-php73.php @@ -0,0 +1,11 @@ +services(); + $services->set(DowngradeTrailingCommasInFunctionCallsRector::class); +}; diff --git a/rules/downgrade-php73/src/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php b/rules/downgrade-php73/src/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php new file mode 100644 index 000000000000..85ea41e40b83 --- /dev/null +++ b/rules/downgrade-php73/src/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php @@ -0,0 +1,72 @@ +args){ + if(! $node->getAttribute(AttributeKey::PARENT_NODE) instanceof Node\Scalar\Encapsed){ + $node->setAttribute(AttributeKey::ORIGINAL_NODE,null); + } + } + return $node; + } +} diff --git a/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/DowngradeTrailingCommasInFunctionCallsRectorTest.php b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/DowngradeTrailingCommasInFunctionCallsRectorTest.php new file mode 100644 index 000000000000..1685dd3abc88 --- /dev/null +++ b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/DowngradeTrailingCommasInFunctionCallsRectorTest.php @@ -0,0 +1,40 @@ += 7.3 + * @dataProvider provideData() + */ + public function test(SmartFileInfo $fileInfo): void + { + $this->doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return DowngradeTrailingCommasInFunctionCallsRector::class; + } + + protected function getPhpVersion(): string + { + return '7.2'; +// TODO: create constant +// return PhpVersionFeature::; + } +} diff --git a/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc new file mode 100644 index 000000000000..8f13bb6bd77c --- /dev/null +++ b/rules/downgrade-php73/tests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc @@ -0,0 +1,33 @@ +setData('posts','units',); + self::run('posts','units',); + $this->setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId,)}"); + } +} + +?> +----- +setData('posts', 'units'); + self::run('posts', 'units'); + $this->setOnClick("[Zip ID: {$modelid}] {$e->getMessage($modelId)}"); + } +} + +?>