From 91a21007675c41e2757067f02f28770324c34690 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 19 Jun 2023 12:50:13 +0200 Subject: [PATCH 1/2] avoid early change in privatize local getter to property --- .../MethodCall/PrivatizeLocalGetterToPropertyRector.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php b/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php index 5aa7e83f2bb..8c06e9d7e1f 100644 --- a/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php +++ b/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php @@ -103,9 +103,13 @@ public function refactor(Node $node): ?Node return null; } - $hasChanged = true; + $propertyFetch = $this->matchLocalPropertyFetchInGetterMethod($classMethod); + if (! $propertyFetch instanceof PropertyFetch) { + return null; + } - return $this->matchLocalPropertyFetchInGetterMethod($classMethod); + $hasChanged = true; + return $propertyFetch; }); if ($hasChanged) { From b5cf72d4b4993236fced87d27306cf36da94964d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 19 Jun 2023 12:54:42 +0200 Subject: [PATCH 2/2] skip rewindable generator from type rename --- .../Fixture/skip_rewindable_generator.php.inc | 12 ++++++++++++ .../Guard/BreakingVariableRenameGuard.php | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_rewindable_generator.php.inc diff --git a/rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_rewindable_generator.php.inc b/rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_rewindable_generator.php.inc new file mode 100644 index 00000000000..5c357d01556 --- /dev/null +++ b/rules-tests/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector/Fixture/skip_rewindable_generator.php.inc @@ -0,0 +1,12 @@ +isGenerator($param)) { + return true; + } + if ($this->isDateTimeAtNamingConvention($param)) { return true; } @@ -222,17 +226,11 @@ private function isUsedInIfAndOtherBranches(Variable $variable, string $currentV return false; } - /** - * @TODO Remove once ParamRenamer created - */ private function isRamseyUuidInterface(Param $param): bool { return $this->nodeTypeResolver->isObjectType($param, new ObjectType('Ramsey\Uuid\UuidInterface')); } - /** - * @TODO Remove once ParamRenamer created - */ private function isDateTimeAtNamingConvention(Param $param): bool { $type = $this->nodeTypeResolver->getType($param); @@ -249,4 +247,12 @@ private function isDateTimeAtNamingConvention(Param $param): bool $currentName = $this->nodeNameResolver->getName($param); return StringUtils::isMatch($currentName, self::AT_NAMING_REGEX . ''); } + + private function isGenerator(Param $param): bool + { + return $this->nodeTypeResolver->isObjectType( + $param, + new ObjectType('Symfony\Component\DependencyInjection\Argument\RewindableGenerator') + ); + } }