diff --git a/src/Mutator/FunctionSignature/ProtectedVisibility.php b/src/Mutator/FunctionSignature/ProtectedVisibility.php index 22292f1d9..807e1aa27 100644 --- a/src/Mutator/FunctionSignature/ProtectedVisibility.php +++ b/src/Mutator/FunctionSignature/ProtectedVisibility.php @@ -65,6 +65,11 @@ private function hasSameProtectedParentMethod(Node $node): bool /** @var \ReflectionClass $reflection */ $reflection = $node->getAttribute(ReflectionVisitor::REFLECTION_CLASS_KEY); + if (!$reflection instanceof \ReflectionClass) { + // assuming the worst where interface has the same method + return true; + } + $parent = $reflection->getParentClass(); while ($parent) { diff --git a/src/Mutator/FunctionSignature/PublicVisibility.php b/src/Mutator/FunctionSignature/PublicVisibility.php index 6defd96ed..0e3c92aee 100644 --- a/src/Mutator/FunctionSignature/PublicVisibility.php +++ b/src/Mutator/FunctionSignature/PublicVisibility.php @@ -100,6 +100,11 @@ private function hasSamePublicMethodInInterface(Node $node): bool /** @var \ReflectionClass $reflection */ $reflection = $node->getAttribute(ReflectionVisitor::REFLECTION_CLASS_KEY); + if (!$reflection instanceof \ReflectionClass) { + // assuming the worst where interface has the same method + return true; + } + foreach ($reflection->getInterfaces() as $reflectionInterface) { try { $method = $reflectionInterface->getMethod($node->name->name); @@ -121,6 +126,11 @@ private function hasSamePublicMethodInParentClass(Node $node): bool /** @var \ReflectionClass $reflection */ $reflection = $node->getAttribute(ReflectionVisitor::REFLECTION_CLASS_KEY); + if (!$reflection instanceof \ReflectionClass) { + // assuming the worst where interface has the same method + return true; + } + $parent = $reflection->getParentClass(); while ($parent) { diff --git a/tests/Mutator/FunctionSignature/ProtectedVisibilityTest.php b/tests/Mutator/FunctionSignature/ProtectedVisibilityTest.php index dc8f1b17a..bd3b2673e 100644 --- a/tests/Mutator/FunctionSignature/ProtectedVisibilityTest.php +++ b/tests/Mutator/FunctionSignature/ProtectedVisibilityTest.php @@ -179,6 +179,22 @@ private function bar() { } } +PHP + ]; + + yield 'it does not mutate an anonymous class because reflection is not avalable' => [ + <<<'PHP' + [ + <<<'PHP' +