Skip to content

Commit

Permalink
Make child classes inherit @no-named-args
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor authored and ondrejmirtes committed May 28, 2022
1 parent 82f3af5 commit 598bda2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/PhpDoc/ResolvedPhpDocBlock.php
Expand Up @@ -180,9 +180,11 @@ public function merge(array $parents, array $parentPhpDocBlocks): self
// skip $result->phpDocNode
// skip $result->phpDocString - just for stubs
$phpDocNodes = $this->phpDocNodes;
$acceptsNamedArguments = $this->acceptsNamedArguments();
foreach ($parents as $parent) {
foreach ($parent->phpDocNodes as $phpDocNode) {
$phpDocNodes[] = $phpDocNode;
$acceptsNamedArguments = $acceptsNamedArguments && $parent->acceptsNamedArguments();
}
}
$result->phpDocNodes = $phpDocNodes;
Expand Down Expand Up @@ -210,7 +212,7 @@ public function merge(array $parents, array $parentPhpDocBlocks): self
$result->isPure = $this->isPure();
$result->isReadOnly = $this->isReadOnly();
$result->hasConsistentConstructor = $this->hasConsistentConstructor();
$result->acceptsNamedArguments = $this->acceptsNamedArguments();
$result->acceptsNamedArguments = $acceptsNamedArguments;

return $result;
}
Expand Down
28 changes: 27 additions & 1 deletion tests/PHPStan/Analyser/data/no-named-arguments.php
Expand Up @@ -12,7 +12,7 @@ function noNamedArgumentsInFunction(float ...$args)
assertType('array<int, float>', $args);
}

class Baz
class Baz extends Foo implements Bar
{
/**
* @no-named-arguments
Expand All @@ -21,4 +21,30 @@ public function noNamedArgumentsInMethod(float ...$args)
{
assertType('array<int, float>', $args);
}

public function noNamedArgumentsInParent(float ...$args)
{
assertType('array<int, float>', $args);
}

public function noNamedArgumentsInInterface(float ...$args)
{
assertType('array<int, float>', $args);
}
}

abstract class Foo
{
/**
* @no-named-arguments
*/
abstract public function noNamedArgumentsInParent(float ...$args);
}

interface Bar
{
/**
* @no-named-arguments
*/
public function noNamedArgumentsInInterface();
}

0 comments on commit 598bda2

Please sign in to comment.