| Conditions | 10 |
| Paths | 25 |
| Total Lines | 53 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 33 | public function createSearchIndex(OutputInterface $output, $iterationCount, $commit) |
||
| 34 | { |
||
| 35 | $output->writeln('Creating Elasticsearch Search Engine Index...'); |
||
| 36 | |||
| 37 | if (!$this->searchHandler instanceof SearchHandler) { |
||
| 38 | throw new RuntimeException(sprintf('Expected to find an instance of %s, but found %s', SearchHandler::class, get_class($this->searchHandler))); |
||
| 39 | } |
||
| 40 | |||
| 41 | $stmt = $this->getContentDbFieldsStmt(['count(id)']); |
||
| 42 | $totalCount = intval($stmt->fetchColumn()); |
||
| 43 | $stmt = $this->getContentDbFieldsStmt(['id', 'current_version']); |
||
| 44 | $this->searchHandler->purgeIndex(); |
||
| 45 | /** @var \Symfony\Component\Console\Helper\ProgressBar $progress */ |
||
| 46 | $progress = new ProgressBar($output); |
||
| 47 | $progress->start($totalCount); |
||
| 48 | $i = 0; |
||
| 49 | do { |
||
| 50 | $contentObjects = []; |
||
| 51 | for ($k = 0; $k <= $iterationCount; ++$k) { |
||
| 52 | if (!$row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
||
| 53 | break; |
||
| 54 | } |
||
| 55 | try { |
||
| 56 | $contentObjects[] = $this->persistenceHandler->contentHandler()->load( |
||
| 57 | $row['id'], |
||
| 58 | $row['current_version'] |
||
| 59 | ); |
||
| 60 | } catch (NotFoundException $e) { |
||
| 61 | $this->logWarning($progress, "Could not load current version of Content with id ${row['id']}, so skipped for indexing. Full exception: " . $e->getMessage()); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | foreach ($contentObjects as $contentObject) { |
||
| 65 | try { |
||
| 66 | $this->searchHandler->indexContent($contentObject); |
||
| 67 | // Skip location indexing if search engine does not use it, or if content does not have locations |
||
| 68 | if (empty($contentObject->versionInfo->contentInfo->mainLocationId)) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | $this->indexLocations($contentObject->versionInfo->contentInfo->id, $progress); |
||
| 72 | } catch (NotFoundException $e) { |
||
| 73 | $this->logWarning($progress, 'Content with id ' . $contentObject->versionInfo->id . ' has missing data, so skipped for indexing. Full exception: ' . $e->getMessage()); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | if ($commit) { |
||
| 77 | $this->searchHandler->flush(); |
||
| 78 | } |
||
| 79 | $progress->advance($k); |
||
| 80 | } while (($i += $iterationCount) < $totalCount); |
||
| 81 | $progress->finish(); |
||
| 82 | $output->writeln(''); |
||
| 83 | |||
| 84 | $output->writeln('Finished creating Elasticsearch Search Engine Index'); |
||
| 85 | } |
||
| 86 | |||
| 106 |