diff --git a/rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php b/rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php index b5d8cb5f4e0..2ad08db9190 100644 --- a/rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php +++ b/rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php @@ -57,10 +57,11 @@ public function renamePropertyPromotion(Class_ $class): bool return false; } - $classReflection = $this->reflectionResolver->resolveClassReflection($class); - if (! $classReflection instanceof ClassReflection) { - return false; - } + // only needed for the trait usage check below; resolving it requires scope, + // which is missing right after another rule rewrote the class + $classReflection = $class->getTraitUses() === [] + ? null + : $this->reflectionResolver->resolveClassReflection($class); // resolve possible and existing param names $blockingParamNames = $this->resolveBlockingParamNames($constructClassMethod); @@ -94,7 +95,10 @@ public function renamePropertyPromotion(Class_ $class): bool continue; } - if ($this->propertyManipulator->isUsedByTrait($classReflection, $currentParamName)) { + if ($classReflection instanceof ClassReflection && $this->propertyManipulator->isUsedByTrait( + $classReflection, + $currentParamName + )) { continue; }