for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Roave\BackwardCompatibility;
use ArrayIterator;
use Countable;
use Generator;
use IteratorAggregate;
use function count;
final class Changes implements IteratorAggregate, Countable
{
/** @var Change[] */
private $changes;
/** Generator|null */
private $generator;
private function __construct()
}
public static function empty() : self
static $empty;
if ($empty) {
return $empty;
$empty = new self();
$empty->changes = [];
/** @param Change[] $changes */
public static function fromIterator(iterable $changes) : self
$instance = new self();
$instance->changes = [];
$instance->generator = (function () use ($changes) : Generator {
foreach ($changes as $change) {
yield $change;
})();
return $instance;
public function mergeWithIterator(iterable $changes) : self
foreach ($this as $change) {
public static function fromList(Change ...$changes) : self
$instance->changes = $changes;
public function mergeWith(self $other) : self
return $this->mergeWithIterator($other);
/**
* {@inheritDoc}
*
* @return ArrayIterator|Change[]
*/
public function getIterator() : iterable
foreach ($this->changes as $change) {
yield $change
Generator
Roave\BackwardCompatibil...\Change[]&ArrayIterator
foreach ($this->generator ?? [] as $change) {
$this->changes[] = $change;
$this->generator = null;
public function count() : int
return count(iterator_to_array($this));