From 292549e4763c42aa9d130bb2c5f673e2e89dcaee Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 10:58:14 +0200 Subject: [PATCH] [perf] Skip reflection in MakeInheritedMethodVisibilitySameAsParentRector when no parent class or no methods --- ...MakeInheritedMethodVisibilitySameAsParentRector.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php b/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php index d187ed6d46a..ee4a5ae6fcc 100644 --- a/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php @@ -5,6 +5,7 @@ namespace Rector\CodingStyle\Rector\ClassMethod; use PhpParser\Node; +use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ClassReflection; @@ -82,6 +83,15 @@ public function refactor(Node $node): ?Node return null; } + // no parent class to align visibility to + if (! $node->extends instanceof Name) { + return null; + } + + if ($node->getMethods() === []) { + return null; + } + $classReflection = $this->reflectionResolver->resolveClassReflection($node); if (! $classReflection instanceof ClassReflection) { return null;