Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDataProviderRector\Fixture;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class CovertIterable extends TestCase
{
#[DataProvider('provideData')]
public function test(iterable $names): void
{
}

public static function provideData()
{
yield [['Tom', 'John']];
yield [[]];
yield [['John', 'Doe']];
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDataProviderRector\Fixture;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class CovertIterable extends TestCase
{
/**
* @param string[] $names
*/
#[DataProvider('provideData')]
public function test(iterable $names): void
{
}

public static function provideData()
{
yield [['Tom', 'John']];
yield [[]];
yield [['John', 'Doe']];
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ function (Node $subNode) use ($variableNamesWithArrayType, $node, &$paramsWithTy

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

$arrayArg = $subNode->getArg('array', NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['array']);
$arrayArg = $subNode->getArg(
'array',
NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['array']
);
if (! $arrayArg instanceof Arg) {
return null;
}
Expand All @@ -146,7 +149,10 @@ function (Node $subNode) use ($variableNamesWithArrayType, $node, &$paramsWithTy
return null;
}

$callbackArg = $subNode->getArg('callback', NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['callback']);
$callbackArg = $subNode->getArg(
'callback',
NativeFuncCallPositions::ARRAY_AND_CALLBACK_POSITIONS[$funcCallName]['callback']
);
if (! $callbackArg instanceof Arg) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function refactor(Node $node): ?Node
continue;
}

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

Expand Down
Loading