From 75b7141a5adda5a3e5ed59f67d5b30dd9da797cf Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Sat, 15 Jan 2022 10:59:44 +0000 Subject: [PATCH] Added support for @no-named-arguments on the class phpdoc block --- .../FunctionBased/ParameterNameChanged.php | 4 ++ .../ParameterNameChangedTest.php | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/DetectChanges/BCBreak/FunctionBased/ParameterNameChanged.php b/src/DetectChanges/BCBreak/FunctionBased/ParameterNameChanged.php index f8b32413..5947a8a1 100644 --- a/src/DetectChanges/BCBreak/FunctionBased/ParameterNameChanged.php +++ b/src/DetectChanges/BCBreak/FunctionBased/ParameterNameChanged.php @@ -113,6 +113,10 @@ private function compareParameter(ReflectionParameter $fromParameter, Reflection private function methodHasNoNamedArgumentsAnnotation(ReflectionMethod|ReflectionFunction $function): bool { + if ($function instanceof ReflectionMethod && str_contains($function->getDeclaringClass()->getDocComment(), self::NO_NAMED_ARGUMENTS_ANNOTATION)) { + return true; + } + return str_contains($function->getDocComment(), self::NO_NAMED_ARGUMENTS_ANNOTATION); } } diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterNameChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterNameChangedTest.php index b16b8137..10032357 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterNameChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterNameChangedTest.php @@ -120,4 +120,43 @@ function removedArgumentsShouldNotBeDetected($a, $b) {} ) ); } + + public function testMethodWhereClassIsAnnotatedNoNamedParameterDoesNotCauseBreak(): void + { + $astLocator = (new BetterReflection())->astLocator(); + + $fromLocator = new StringSourceLocator( + <<<'PHP' +reflectClass('TheClass')->getMethod('theMethod'); + $toMethod = $toClassReflector->reflectClass('TheClass')->getMethod('theMethod'); + + $changes = (new ParameterNameChanged())($fromMethod, $toMethod); + self::assertCount(0, $changes); + } }