Skip to content

Commit 050cf1e

Browse files
authored
Merge pull request #411 from Roave/409-support-no-named-arguments-on-classes
Added support for `@no-named-arguments` on the class phpdoc block
2 parents cac327c + 75b7141 commit 050cf1e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/DetectChanges/BCBreak/FunctionBased/ParameterNameChanged.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ private function compareParameter(ReflectionParameter $fromParameter, Reflection
113113

114114
private function methodHasNoNamedArgumentsAnnotation(ReflectionMethod|ReflectionFunction $function): bool
115115
{
116+
if ($function instanceof ReflectionMethod && str_contains($function->getDeclaringClass()->getDocComment(), self::NO_NAMED_ARGUMENTS_ANNOTATION)) {
117+
return true;
118+
}
119+
116120
return str_contains($function->getDocComment(), self::NO_NAMED_ARGUMENTS_ANNOTATION);
117121
}
118122
}

test/unit/DetectChanges/BCBreak/FunctionBased/ParameterNameChangedTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,43 @@ function removedArgumentsShouldNotBeDetected($a, $b) {}
120120
)
121121
);
122122
}
123+
124+
public function testMethodWhereClassIsAnnotatedNoNamedParameterDoesNotCauseBreak(): void
125+
{
126+
$astLocator = (new BetterReflection())->astLocator();
127+
128+
$fromLocator = new StringSourceLocator(
129+
<<<'PHP'
130+
<?php
131+
132+
/** @no-named-arguments */
133+
class TheClass {
134+
public function theMethod(int $a) {}
135+
}
136+
PHP
137+
,
138+
$astLocator
139+
);
140+
141+
$toLocator = new StringSourceLocator(
142+
<<<'PHP'
143+
<?php
144+
145+
/** @no-named-arguments */
146+
class TheClass {
147+
public function theMethod(int $b) {}
148+
}
149+
PHP
150+
,
151+
$astLocator
152+
);
153+
154+
$fromClassReflector = new DefaultReflector($fromLocator);
155+
$toClassReflector = new DefaultReflector($toLocator);
156+
$fromMethod = $fromClassReflector->reflectClass('TheClass')->getMethod('theMethod');
157+
$toMethod = $toClassReflector->reflectClass('TheClass')->getMethod('theMethod');
158+
159+
$changes = (new ParameterNameChanged())($fromMethod, $toMethod);
160+
self::assertCount(0, $changes);
161+
}
123162
}

0 commit comments

Comments
 (0)