Skip to content

Commit 641bc81

Browse files
committed
skip publc method with mixed[] param on ClassMethodArrayDocblockParamFromLocalCallsRector
1 parent 17215ca commit 641bc81

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
4+
5+
final class SkipOverrideDummyArrayMixedOnPublic
6+
{
7+
public function go()
8+
{
9+
$this->run([2512, 3423]);
10+
11+
$this->run([324, 534]);
12+
}
13+
14+
/**
15+
* @param mixed[] $items
16+
*/
17+
public function run(array $items)
18+
{
19+
}
20+
}
21+
22+
?>

rules/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Param;
99
use PhpParser\Node\Stmt\Class_;
10+
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
1011
use PHPStan\Type\Type;
1112
use PHPStan\Type\TypeCombinator;
1213
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
@@ -106,6 +107,13 @@ public function refactor(Node $node): ?Node
106107
continue;
107108
}
108109

110+
if ($parameterTagValueNode instanceof ParamTagValueNode
111+
&& $classMethod->isPublic() &&
112+
$this->usefulArrayTagNodeAnalyzer->isMixedArray($parameterTagValueNode->type)) {
113+
// on public method, skip if there is mixed[], as caller can be anything
114+
continue;
115+
}
116+
109117
$resolvedParameterType = $classMethodParameterTypes[$parameterPosition] ?? $classMethodParameterTypes[$parameterName] ?? null;
110118
if (! $resolvedParameterType instanceof Type) {
111119
continue;

rules/TypeDeclarationDocblocks/TagNodeAnalyzer/UsefulArrayTagNodeAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isUsefulArrayTag(null|ReturnTagValueNode|ParamTagValueNode|VarTa
2727
return $type->name !== 'array';
2828
}
2929

30-
private function isMixedArray(TypeNode $typeNode): bool
30+
public function isMixedArray(TypeNode $typeNode): bool
3131
{
3232
return $typeNode instanceof SpacingAwareArrayTypeNode && $typeNode->type instanceof IdentifierTypeNode && $typeNode->type->name === 'mixed';
3333
}

0 commit comments

Comments
 (0)