Skip to content

Commit

Permalink
Merge pull request #411 from Roave/409-support-no-named-arguments-on-…
Browse files Browse the repository at this point in the history
…classes

Added support for `@no-named-arguments` on the class phpdoc block
  • Loading branch information
Ocramius authored Jan 15, 2022
2 parents cac327c + 75b7141 commit 050cf1e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,43 @@ function removedArgumentsShouldNotBeDetected($a, $b) {}
)
);
}

public function testMethodWhereClassIsAnnotatedNoNamedParameterDoesNotCauseBreak(): void
{
$astLocator = (new BetterReflection())->astLocator();

$fromLocator = new StringSourceLocator(
<<<'PHP'
<?php
/** @no-named-arguments */
class TheClass {
public function theMethod(int $a) {}
}
PHP
,
$astLocator
);

$toLocator = new StringSourceLocator(
<<<'PHP'
<?php
/** @no-named-arguments */
class TheClass {
public function theMethod(int $b) {}
}
PHP
,
$astLocator
);

$fromClassReflector = new DefaultReflector($fromLocator);
$toClassReflector = new DefaultReflector($toLocator);
$fromMethod = $fromClassReflector->reflectClass('TheClass')->getMethod('theMethod');
$toMethod = $toClassReflector->reflectClass('TheClass')->getMethod('theMethod');

$changes = (new ParameterNameChanged())($fromMethod, $toMethod);
self::assertCount(0, $changes);
}
}

0 comments on commit 050cf1e

Please sign in to comment.