Skip to content

Commit

Permalink
IBX-5385 after review changes, replace type ArrayIterator with Traver…
Browse files Browse the repository at this point in the history
…sable type
  • Loading branch information
papcio122 committed Sep 12, 2023
1 parent 2354584 commit dc99d72
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
namespace Ibexa\Bundle\Core\Command;

use ArrayIterator;
use function count;
use DateTime;
use const DIRECTORY_SEPARATOR;
Expand All @@ -30,6 +29,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Traversable;

class ReindexCommand extends Command implements BackwardCompatibleCommand
{
Expand Down Expand Up @@ -280,7 +280,6 @@ protected function indexIncrementally(
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentList $contentList */
$contentList = $this->contentService->find($filter);
$count = $contentList->getTotalCount();
/** @var ArrayIterator<int, Content> $contentListIterator */
$contentListIterator = $contentList->getIterator();
$generator = $this->fetchIterationFromContentListIterator($contentListIterator, $iterationCount);
$purge = false;
Expand Down Expand Up @@ -484,29 +483,23 @@ public function getDeprecatedAliases(): array
}

/**
* @param ArrayIterator<int, Content> $contentListIterator
* @param Traversable<Content> $contentListIterator
* @param int $iterationCount
*
* @return \Generator
*/
private function fetchIterationFromContentListIterator(ArrayIterator $contentListIterator, int $iterationCount): Generator
private function fetchIterationFromContentListIterator(Traversable $contentListIterator, int $iterationCount): Generator
{
do {
$contentIds = [];
for ($i = 0; $i < $iterationCount; ++$i) {
$content = $contentListIterator->current();
if ($content) {
$contentIds[] = $content->id;
} elseif (empty($contentIds)) {
return;
} else {
break;
}
$contentListIterator->next();
$i = 0;
$contentIds = [];
foreach ($contentListIterator as $content) {
$contentIds[] = $content->id;
if ($iterationCount <= $i) {
break;
}

yield $contentIds;
} while (!empty($content));
++$i;
}
yield $contentIds;
}
}

Expand Down

0 comments on commit dc99d72

Please sign in to comment.