Skip to content

Commit dd30700

Browse files
authored
Skip null pass in ClassMethodArrayDocblockParamFromLocalCallsRector, as array param type declaration is already checked (#7336)
1 parent 98c1d3a commit dd30700

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
4+
5+
final class RemoveNullable
6+
{
7+
public function go()
8+
{
9+
$this->run($this->getNames());
10+
}
11+
12+
private function run(array $items)
13+
{
14+
}
15+
16+
/**
17+
* @return string[]|null
18+
*/
19+
private function getNames(): ?array
20+
{
21+
return ['Jim', 'Rohn'];
22+
}
23+
}
24+
25+
?>
26+
-----
27+
<?php
28+
29+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;
30+
31+
final class RemoveNullable
32+
{
33+
public function go()
34+
{
35+
$this->run($this->getNames());
36+
}
37+
38+
/**
39+
* @param string[] $items
40+
*/
41+
private function run(array $items)
42+
{
43+
}
44+
45+
/**
46+
* @return string[]|null
47+
*/
48+
private function getNames(): ?array
49+
{
50+
return ['Jim', 'Rohn'];
51+
}
52+
}
53+
54+
?>

rules/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
1010
use PHPStan\Type\MixedType;
1111
use PHPStan\Type\Type;
12+
use PHPStan\Type\TypeCombinator;
1213
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1314
use Rector\PhpParser\NodeFinder\LocalMethodCallFinder;
1415
use Rector\Rector\AbstractRector;
@@ -112,10 +113,14 @@ public function refactor(Node $node): ?Node
112113
if (! $resolvedParameterType instanceof Type) {
113114
continue;
114115
}
116+
115117
if ($resolvedParameterType instanceof MixedType) {
116118
continue;
117119
}
118120

121+
// in case of array type declaration, null cannot be passed or is already casted
122+
$resolvedParameterType = TypeCombinator::removeNull($resolvedParameterType);
123+
119124
$hasClassMethodChanged = $this->nodeDocblockTypeDecorator->decorateGenericIterableParamType(
120125
$resolvedParameterType,
121126
$classMethodPhpDocInfo,

0 commit comments

Comments
 (0)