Skip to content

Commit

Permalink
IBX-5385 fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
papcio122 committed Sep 12, 2023
1 parent 76557f4 commit 2354584
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/
namespace Ibexa\Bundle\Core\Command;

use ArrayIterator;
use function count;
use DateTime;
use const DIRECTORY_SEPARATOR;
use Generator;
use Ibexa\Contracts\Core\Persistence\Content\Location\Handler;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
use Ibexa\Contracts\Core\Search\Content\IndexerGateway;
Expand Down Expand Up @@ -84,6 +85,7 @@ public function __construct(
$this->isDebug = $isDebug;
$this->projectDir = $projectDir;
$this->contentService = $contentService;
$this->phpPath = $phpPath;

parent::__construct();
}
Expand Down Expand Up @@ -275,9 +277,12 @@ protected function indexIncrementally(
->withCriterion(
new Query\Criterion\ContentTypeIdentifier($contentType)
);
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\ContentList $contentList */
$contentList = $this->contentService->find($filter);
$count = $contentList->getTotalCount();
$generator = $this->fetchIterationFromContentList($contentList, $iterationCount);
/** @var ArrayIterator<int, Content> $contentListIterator */
$contentListIterator = $contentList->getIterator();
$generator = $this->fetchIterationFromContentListIterator($contentListIterator, $iterationCount);
$purge = false;
} else {
$count = $this->gateway->countAllContent();
Expand Down Expand Up @@ -478,21 +483,26 @@ public function getDeprecatedAliases(): array
return ['ezplatform:reindex'];
}

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

yield $contentIds;
Expand Down

0 comments on commit 2354584

Please sign in to comment.