Skip to content

Commit 43d1eae

Browse files
authored
cover iterable in AddParamArrayDocblockFromDataProviderRector (#7361)
1 parent 1e6ced6 commit 43d1eae

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDataProviderRector\Fixture;
4+
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\TestCase;
7+
8+
final class CovertIterable extends TestCase
9+
{
10+
#[DataProvider('provideData')]
11+
public function test(iterable $names): void
12+
{
13+
}
14+
15+
public static function provideData()
16+
{
17+
yield [['Tom', 'John']];
18+
yield [[]];
19+
yield [['John', 'Doe']];
20+
}
21+
}
22+
23+
?>
24+
-----
25+
<?php
26+
27+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDataProviderRector\Fixture;
28+
29+
use PHPUnit\Framework\Attributes\DataProvider;
30+
use PHPUnit\Framework\TestCase;
31+
32+
final class CovertIterable extends TestCase
33+
{
34+
/**
35+
* @param string[] $names
36+
*/
37+
#[DataProvider('provideData')]
38+
public function test(iterable $names): void
39+
{
40+
}
41+
42+
public static function provideData()
43+
{
44+
yield [['Tom', 'John']];
45+
yield [[]];
46+
yield [['John', 'Doe']];
47+
}
48+
}
49+
50+
?>

rules/TypeDeclaration/Rector/ClassMethod/AddParamArrayDocblockBasedOnCallableNativeFuncCallRector.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ function (Node $subNode) use ($variableNamesWithArrayType, $node, &$paramsWithTy
124124

125125
$funcCallName = (string) $this->getName($subNode);
126126

127-
$arrayArg = $subNode->getArg('array', NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['array']);
127+
$arrayArg = $subNode->getArg(
128+
'array',
129+
NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['array']
130+
);
128131
if (! $arrayArg instanceof Arg) {
129132
return null;
130133
}
@@ -146,7 +149,10 @@ function (Node $subNode) use ($variableNamesWithArrayType, $node, &$paramsWithTy
146149
return null;
147150
}
148151

149-
$callbackArg = $subNode->getArg('callback', NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['callback']);
152+
$callbackArg = $subNode->getArg(
153+
'callback',
154+
NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['callback']
155+
);
150156
if (! $callbackArg instanceof Arg) {
151157
return null;
152158
}

rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddParamArrayDocblockFromDataProviderRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function refactor(Node $node): ?Node
127127
continue;
128128
}
129129

130-
if (! $this->isName($param->type, 'array')) {
130+
if (! $this->isNames($param->type, ['array', 'iterable'])) {
131131
continue;
132132
}
133133

0 commit comments

Comments
 (0)