Skip to content

Commit d7c7d35

Browse files
authored
[TypeDeclarationDocblocks] Handle crash on next empty array on ClassMethodArrayDocblockParamFromLocalCallsRector (#7325)
* [TypeDeclarationDocblocks] Handle crash on next empty array on ClassMethodArrayDocblockParamFromLocalCallsRector * Fix
1 parent 552bc66 commit d7c7d35

File tree

2 files changed

+42
-8
lines changed

2 files changed

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

rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,13 @@ private function unionToSingleType(array $staticTypesByArgumentPosition): array
124124
$staticTypeByArgumentPosition[$position] = $this->narrowParentObjectTreeToSingleObjectChildType(
125125
$unionedType
126126
);
127-
}
128-
129-
if (count($staticTypeByArgumentPosition) !== 1) {
130-
return $staticTypeByArgumentPosition;
131-
}
132127

133-
if (! $staticTypeByArgumentPosition[0]->isNull()->yes()) {
134-
return $staticTypeByArgumentPosition;
128+
if ($staticTypeByArgumentPosition[$position]->isNull()->yes()) {
129+
$staticTypeByArgumentPosition[$position] = new MixedType();
130+
}
135131
}
136132

137-
return [new MixedType()];
133+
return $staticTypeByArgumentPosition;
138134
}
139135

140136
private function narrowParentObjectTreeToSingleObjectChildType(Type $type): Type

0 commit comments

Comments
 (0)