Skip to content

Commit e2727e0

Browse files
committed
add various types
1 parent bbfd6bc commit e2727e0

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
4+
5+
final class MultipleCallsWithVariousTypes
6+
{
7+
public function go()
8+
{
9+
$this->run(['item1', 'item2']);
10+
$this->run([123, 456]);
11+
}
12+
13+
private function run(array $items)
14+
{
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
23+
24+
final class MultipleCallsWithVariousTypes
25+
{
26+
public function go()
27+
{
28+
$this->run(['item1', 'item2']);
29+
$this->run([123, 456]);
30+
}
31+
32+
/**
33+
* @param string[]|int[] $items
34+
*/
35+
private function run(array $items)
36+
{
37+
}
38+
}
39+
40+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
4+
5+
class SkipNonArrayParam
6+
{
7+
public function go()
8+
{
9+
$this->run(['item1', 'item2']);
10+
}
11+
12+
private function run($items)
13+
{
14+
}
15+
}

rules/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Stmt\Class_;
99
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
10-
use PHPStan\Type\ArrayType;
1110
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1211
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
1312
use Rector\PhpParser\NodeFinder\LocalMethodCallFinder;
@@ -95,6 +94,10 @@ public function refactor(Node $node): ?Node
9594
$classMethodParameterTypes = $this->callTypesResolver->resolveStrictTypesFromCalls($methodCalls);
9695

9796
foreach ($classMethod->getParams() as $parameterPosition => $param) {
97+
if ($param->type === null || ! $this->isName($param->type, 'array')) {
98+
continue;
99+
}
100+
98101
$parameterName = $this->getName($param);
99102
$parameterTagValueNode = $classMethodPhpDocInfo->getParamTagValueByName($parameterName);
100103

@@ -104,7 +107,7 @@ public function refactor(Node $node): ?Node
104107
}
105108

106109
$resolvedParameterType = $classMethodParameterTypes[$parameterPosition] ?? null;
107-
if (! $resolvedParameterType instanceof ArrayType) {
110+
if (! $resolvedParameterType instanceof \PHPStan\Type\Type) {
108111
continue;
109112
}
110113

0 commit comments

Comments
 (0)