We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 160 |
| Total Lines | 79 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 78 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 79 | { |
||
| 80 | // Make sure the _cli_ user is loaded |
||
| 81 | Bootstrap::getInstance()->initializeBackendAuthentication(); |
||
| 82 | |||
| 83 | $dryRun = $input->getOption('dry-run') != false ? true : false; |
||
| 84 | |||
| 85 | $io = new SymfonyStyle($input, $output); |
||
| 86 | $io->title($this->getDescription()); |
||
| 87 | |||
| 88 | $startingPoint = 0; |
||
| 89 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('pid'))) { |
||
| 90 | $startingPoint = MathUtility::forceIntegerInRange((int)$input->getOption('pid'), 0); |
||
| 91 | } |
||
| 92 | if ($startingPoint == 0) { |
||
| 93 | $io->error('ERROR: No valid PID (' . $startingPoint . ') given.'); |
||
| 94 | exit(1); |
||
|
1 ignored issue
–
show
|
|||
| 95 | } |
||
| 96 | |||
| 97 | if ($input->getOption('solr')) { |
||
| 98 | $allSolrCores = $this->getSolrCores($startingPoint); |
||
| 99 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('solr'))) { |
||
| 100 | $solrCoreUid = MathUtility::forceIntegerInRange((int)$input->getOption('solr'), 0); |
||
| 101 | } else { |
||
| 102 | $solrCoreName = $input->getOption('solr'); |
||
| 103 | $solrCoreUid = $allSolrCores[$solrCoreName]; |
||
| 104 | } |
||
| 105 | // Abort if solrCoreUid is empty or not in the array of allowed solr cores. |
||
| 106 | if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) { |
||
| 107 | foreach ($allSolrCores as $index_name => $uid) { |
||
| 108 | $output_solrCores .= ' ' . $uid . ' : ' . $index_name ."\n"; |
||
| 109 | } |
||
| 110 | if (empty($output_solrCores)) { |
||
| 111 | $io->error('ERROR: No valid solr core ("'. $input->getOption('solr') . '") given. ' . "No valid cores found on PID " . $startingPoint .".\n" . $output_solrCores); |
||
| 112 | exit(1); |
||
|
1 ignored issue
–
show
|
|||
| 113 | } else { |
||
| 114 | $io->error('ERROR: No valid solr core ("'. $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . $output_solrCores); |
||
| 115 | exit(1); |
||
|
1 ignored issue
–
show
|
|||
| 116 | } |
||
| 117 | } |
||
| 118 | } else { |
||
| 119 | $io->error('ERROR: Required parameter --solr|-s is missing.'); |
||
| 120 | exit(1); |
||
|
1 ignored issue
–
show
|
|||
| 121 | } |
||
| 122 | |||
| 123 | if ($input->getOption('all')) { |
||
| 124 | // Get the document... |
||
| 125 | $documents = $this->getAllDocuments($startingPoint); |
||
| 126 | } else { |
||
| 127 | // coll may be a single integer, a list of integer |
||
| 128 | if (empty(array_filter(GeneralUtility::intExplode(',', $input->getOption('coll'), true)))) { |
||
|
1 ignored issue
–
show
|
|||
| 129 | $io->error('ERROR: "' . $input->getOption('coll') . '" is not a valid list of collection UIDs for --coll|-c.'); |
||
| 130 | exit(1); |
||
|
1 ignored issue
–
show
|
|||
| 131 | } |
||
| 132 | $documents = $this->getDocumentsToProceed($input->getOption('coll'), $startingPoint); |
||
| 133 | } |
||
| 134 | |||
| 135 | foreach ($documents as $id => $document) { |
||
| 136 | $doc = Document::getInstance($document, $startingPoint, TRUE); |
||
| 137 | if ($doc->ready) { |
||
| 138 | if ($dryRun) { |
||
| 139 | $io->writeln('DRY RUN: Would index ' . $id . '/' . count($documents) . ' ' . $doc->uid . ' ' . $doc->location . ' on UID ' . $startingPoint . ' and solr core ' . $solrCoreUid .'.'); |
||
| 140 | } else { |
||
| 141 | if ($io->isVerbose()) { |
||
| 142 | $io->writeln(date('Y-m-d H:i:s') . ' ' . $id . '/' . count($documents) . ' ' . $doc->uid . ' ' . $doc->location . ' on UID ' . $startingPoint . ' and solr core ' . $solrCoreUid .'.'); |
||
| 143 | } |
||
| 144 | // ...and save it to the database... |
||
| 145 | if (!$doc->save($startingPoint, $solrCoreUid)) { |
||
| 146 | $io->error('ERROR: Document "'.$id.'" not saved and indexed.'); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | $io->error('ERROR: Document "'.$id.'" could not be loaded.'); |
||
| 151 | } |
||
| 152 | // Clear document registry to prevent memory exhaustion. |
||
| 153 | Document::clearRegistry(); |
||
| 154 | } |
||
| 155 | |||
| 156 | $io->success('All done!'); |
||
| 157 | } |
||
| 293 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.