rector: Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector applies on a method that should not change
I’ve noticed Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector applied the following change :
use Doctrine\Common\Collections\ArrayCollection;
final class OptimizedPasses extends ArrayCollection
{
// ...
public static function someNamedConstructor(array $commands)
{
// simplified code :
return new static(self::optimizePasses($commands));
}
- private static function optimizePasses(array $commands): array
+ private static function optimizePasses(array $commands): \Iterator
{
// some logic
-
- // Some comment that was meaningful
- return [
- new Pass(ProcessWrapper::SYNCHRONOUS, $synchronousCommands),
- new Pass(ProcessWrapper::ASYNCHRONOUS, $asynchronousCommands),
- ];
+ yield new Pass(ProcessWrapper::SYNCHRONOUS, $synchronousCommands);
+ yield new Pass(ProcessWrapper::ASYNCHRONOUS, $asynchronousCommands);
}
// ...
}
Only issue is, this method is called directly in a static named constructor return new static(self::optimizePasses($commands));, which uses the parent’s constructor : Doctrine\Common\Collections\ArrayCollection::__construct(array $elements). And as it expects an array, it breaks with :
TypeError: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in OptimizedPasses.php on line 50
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (21 by maintainers)
Yes, like this:
(double check the path, it’s from the top of my head)
then
then