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 f89cc1b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 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 All @@ -35,7 +36,7 @@ class ReindexCommand extends Command implements BackwardCompatibleCommand
/** @var \Ibexa\Core\Search\Common\Indexer|\Ibexa\Core\Search\Common\IncrementalIndexer */
private $searchIndexer;

/** @var string */
/** @var string|false|null */
private $phpPath;

/** @var \Psr\Log\LoggerInterface */
Expand Down Expand Up @@ -275,9 +276,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 +482,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 f89cc1b

Please sign in to comment.