From 4f07a4f30f341a516aa8f6bbbb5f97f44469cee2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 7 Jun 2022 13:34:00 +0700 Subject: [PATCH] [Php74] Remove ReservedFnFunctionRector (#2447) * [Php74] Remove ReservedFnFunctionRector * unregister rule * phpstan --- .../docs/rector_rules_overview.md | 29 +---- config/set/php74.php | 3 - phpstan.neon | 1 + .../Fixture/fixture.php.inc | 37 ------ .../skip_variable_func_call.php.inc | 16 --- .../RenameNameNodeTest.php | 33 ------ .../ReservedFnFunctionRectorTest.php | 34 ------ .../config/configured_rule.php | 10 -- .../Function_/ReservedFnFunctionRector.php | 109 ------------------ 9 files changed, 3 insertions(+), 269 deletions(-) delete mode 100644 rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/FixtureRenameNameNode/skip_variable_func_call.php.inc delete mode 100644 rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/RenameNameNodeTest.php delete mode 100644 rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/ReservedFnFunctionRectorTest.php delete mode 100644 rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/config/configured_rule.php delete mode 100644 rules/Php74/Rector/Function_/ReservedFnFunctionRector.php diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 6b0b730de8e..12e7dff2dac 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 518 Rules Overview +# 517 Rules Overview
@@ -70,7 +70,7 @@ - [Php73](#php73) (9) -- [Php74](#php74) (14) +- [Php74](#php74) (13) - [Php80](#php80) (18) @@ -8058,31 +8058,6 @@ Change deprecated (real) to (float)
-### ReservedFnFunctionRector - -Change `fn()` function name to `f()`, since it will be reserved keyword - -- class: [`Rector\Php74\Rector\Function_\ReservedFnFunctionRector`](../rules/Php74/Rector/Function_/ReservedFnFunctionRector.php) - -```diff - class SomeClass - { - public function run() - { -- function fn($value) -+ function f($value) - { - return $value; - } - -- fn(5); -+ f(5); - } - } -``` - -
- ### RestoreDefaultNullToNullableTypePropertyRector Add null default to properties with PHP 7.4 property nullable type diff --git a/config/set/php74.php b/config/set/php74.php index e71f4bcb9d4..3080918a3fc 100644 --- a/config/set/php74.php +++ b/config/set/php74.php @@ -11,7 +11,6 @@ use Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector; use Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector; use Rector\Php74\Rector\FuncCall\FilterVarToAddSlashesRector; use Rector\Php74\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector; -use Rector\Php74\Rector\Function_\ReservedFnFunctionRector; use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector; use Rector\Php74\Rector\MethodCall\ChangeReflectionTypeToStringToGetNameRector; use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; @@ -56,6 +55,4 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->rule(RestoreDefaultNullToNullableTypePropertyRector::class); $rectorConfig->rule(CurlyToSquareBracketArrayStringRector::class); - - $rectorConfig->rule(ReservedFnFunctionRector::class); }; diff --git a/phpstan.neon b/phpstan.neon index 3f7d9e1bd39..443cbd8ef66 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -725,3 +725,4 @@ parameters: # resolve later with configurable types - '#On passing a constant, the method should have an enum type\. See https\://phpstan\.org/writing\-php\-code/phpdoc\-types\#literals\-and\-constants#' + - '#Instead of calling all public methods of value object, pass it directly#' diff --git a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/Fixture/fixture.php.inc b/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/Fixture/fixture.php.inc deleted file mode 100644 index b307dbb1eef..00000000000 --- a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/FixtureRenameNameNode/skip_variable_func_call.php.inc b/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/FixtureRenameNameNode/skip_variable_func_call.php.inc deleted file mode 100644 index 62027f6567f..00000000000 --- a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/FixtureRenameNameNode/skip_variable_func_call.php.inc +++ /dev/null @@ -1,16 +0,0 @@ - */ - private array $callbacks = []; - - public function run() - { - foreach ($this->callbacks as $fn) { - $fn(); - } - } -} diff --git a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/RenameNameNodeTest.php b/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/RenameNameNodeTest.php deleted file mode 100644 index 8525b68f3df..00000000000 --- a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/RenameNameNodeTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureRenameNameNode'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/ReservedFnFunctionRectorTest.php b/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/ReservedFnFunctionRectorTest.php deleted file mode 100644 index 26776034f83..00000000000 --- a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/ReservedFnFunctionRectorTest.php +++ /dev/null @@ -1,34 +0,0 @@ -markTestSkipped('Requires tweaked PHP Parser to verify `fn` as valid function to simulate php <7.4'); - $this->doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/config/configured_rule.php b/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/config/configured_rule.php deleted file mode 100644 index 17ca931f0f5..00000000000 --- a/rules-tests/Php74/Rector/Function_/ReservedFnFunctionRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(ReservedFnFunctionRector::class); -}; diff --git a/rules/Php74/Rector/Function_/ReservedFnFunctionRector.php b/rules/Php74/Rector/Function_/ReservedFnFunctionRector.php deleted file mode 100644 index c63e666befc..00000000000 --- a/rules/Php74/Rector/Function_/ReservedFnFunctionRector.php +++ /dev/null @@ -1,109 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Function_::class, FuncCall::class]; - } - - /** - * @param Function_|FuncCall $node - */ - public function refactor(Node $node): ?Node - { - if ($node instanceof FuncCall && ! $node->name instanceof Name) { - return null; - } - - if (! $this->isName($node->name, 'fn')) { - return null; - } - - $newName = self::NEW_ORIGINAL_NAME; - $count = 1; - - while ($this->reflectionProvider->hasFunction(new Name($newName), null)) { - $newName = self::NEW_ORIGINAL_NAME . $count; - ++$count; - } - - $node->name = $node instanceof FuncCall ? new Name($newName) : new Identifier($newName); - return $node; - } -}