mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
c29364dfcf
f3242bfadc
[CodeQuality] Handle crash inside block statement with unreachable statement on OptionalParametersAfterRequiredRector (#6640)
56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace RectorPrefix202501\Illuminate\Container;
|
|
|
|
use Countable;
|
|
use IteratorAggregate;
|
|
use Traversable;
|
|
class RewindableGenerator implements Countable, IteratorAggregate
|
|
{
|
|
/**
|
|
* The generator callback.
|
|
*
|
|
* @var callable
|
|
*/
|
|
protected $generator;
|
|
/**
|
|
* The number of tagged services.
|
|
*
|
|
* @var callable|int
|
|
*/
|
|
protected $count;
|
|
/**
|
|
* Create a new generator instance.
|
|
*
|
|
* @param callable $generator
|
|
* @param callable|int $count
|
|
* @return void
|
|
*/
|
|
public function __construct(callable $generator, $count)
|
|
{
|
|
$this->count = $count;
|
|
$this->generator = $generator;
|
|
}
|
|
/**
|
|
* Get an iterator from the generator.
|
|
*
|
|
* @return \Traversable
|
|
*/
|
|
public function getIterator() : Traversable
|
|
{
|
|
return ($this->generator)();
|
|
}
|
|
/**
|
|
* Get the total number of tagged services.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function count() : int
|
|
{
|
|
if (\is_callable($count = $this->count)) {
|
|
$this->count = $count();
|
|
}
|
|
return $this->count;
|
|
}
|
|
}
|