diff --git a/src/EmptyResultIterator.php b/src/EmptyResultIterator.php index d590e304..662a09f6 100644 --- a/src/EmptyResultIterator.php +++ b/src/EmptyResultIterator.php @@ -2,15 +2,6 @@ namespace TheCodingMachine\TDBM; -use Psr\Log\NullLogger; -use TheCodingMachine\TDBM\ResultIterator; - class EmptyResultIterator extends ResultIterator { - protected function __construct() - { - $this->totalCount = 0; - $this->logger = new NullLogger(); - } - } diff --git a/src/ResultIterator.php b/src/ResultIterator.php index 0b200dbc..595c37a3 100644 --- a/src/ResultIterator.php +++ b/src/ResultIterator.php @@ -65,15 +65,15 @@ class ResultIterator implements Result, \ArrayAccess, \JsonSerializable private $innerResultIterator; /** @var int|null */ - protected $totalCount; + private $totalCount; /** @var int */ private $mode; /** @var LoggerInterface */ - protected $logger; + private $logger; - protected function __construct() + final private function __construct() { } @@ -83,7 +83,7 @@ protected function __construct() */ public static function createResultIterator(QueryFactory $queryFactory, array $parameters, ObjectStorageInterface $objectStorage, ?string $className, TDBMService $tdbmService, MagicQuery $magicQuery, int $mode, LoggerInterface $logger): self { - $iterator = new self(); + $iterator = new static(); if ($mode !== TDBMService::MODE_CURSOR && $mode !== TDBMService::MODE_ARRAY) { throw new TDBMException("Unknown fetch mode: '".$mode."'"); } @@ -101,7 +101,10 @@ public static function createResultIterator(QueryFactory $queryFactory, array $p public static function createEmpyIterator(): self { - return new EmptyResultIterator(); + $iterator = new static(); + $iterator->totalCount = 0; + $iterator->logger = new NullLogger(); + return $iterator; } protected function executeCountQuery(): void diff --git a/tests/AbstractTDBMObjectTest.php b/tests/AbstractTDBMObjectTest.php index 3a79559d..a0e79532 100644 --- a/tests/AbstractTDBMObjectTest.php +++ b/tests/AbstractTDBMObjectTest.php @@ -44,7 +44,7 @@ public function testEmptyResultIterator() public function testEmptyPageIterator() { - $a = ResultIterator::createEmpyIterator(); + $a = EmptyResultIterator::createEmpyIterator(); $b = $a->take(0, 10); foreach ($b as $empty) { throw new \LogicException("Not supposed to iterate on an empty page iterator.");