We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 19 |
| Paths | 96 |
| Total Lines | 81 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 71 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 72 | { |
||
| 73 | // Make sure the _cli_ user is loaded |
||
| 74 | Bootstrap::getInstance()->initializeBackendAuthentication(); |
||
| 75 | |||
| 76 | $dryRun = $input->getOption('dry-run') != FALSE ? TRUE : FALSE; |
||
| 77 | |||
| 78 | $io = new SymfonyStyle($input, $output); |
||
| 79 | $io->title($this->getDescription()); |
||
| 80 | |||
| 81 | $startingPoint = 0; |
||
| 82 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('pid'))) { |
||
| 83 | $startingPoint = MathUtility::forceIntegerInRange((int) $input->getOption('pid'), 0); |
||
| 84 | } |
||
| 85 | if ($startingPoint == 0) { |
||
| 86 | $io->error('ERROR: No valid PID (' . $startingPoint . ') given.'); |
||
| 87 | exit(1); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ( |
||
| 91 | !empty($input->getOption('solr')) |
||
| 92 | && !is_array($input->getOption('solr')) |
||
| 93 | ) { |
||
| 94 | $allSolrCores = $this->getSolrCores($startingPoint); |
||
| 95 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('solr'))) { |
||
| 96 | $solrCoreUid = MathUtility::forceIntegerInRange((int) $input->getOption('solr'), 0); |
||
| 97 | } else { |
||
| 98 | $solrCoreUid = $allSolrCores[$input->getOption('solr')]; |
||
| 99 | } |
||
| 100 | // Abort if solrCoreUid is empty or not in the array of allowed solr cores. |
||
| 101 | if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) { |
||
| 102 | $output_solrCores = []; |
||
| 103 | foreach ($allSolrCores as $index_name => $uid) { |
||
| 104 | $output_solrCores[] = $uid . ' : ' . $index_name; |
||
| 105 | } |
||
| 106 | if (empty($output_solrCores)) { |
||
| 107 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $startingPoint . ".\n"); |
||
| 108 | exit(1); |
||
| 109 | } else { |
||
| 110 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n"); |
||
| 111 | exit(1); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } else { |
||
| 115 | $io->error('ERROR: Required parameter --solr|-s is missing or array.'); |
||
| 116 | exit(1); |
||
| 117 | } |
||
| 118 | |||
| 119 | if ( |
||
| 120 | empty($input->getOption('doc')) |
||
| 121 | || is_array($input->getOption('doc')) |
||
| 122 | || ( |
||
| 123 | !MathUtility::canBeInterpretedAsInteger($input->getOption('doc')) |
||
| 124 | && !GeneralUtility::isValidUrl($input->getOption('doc')) |
||
|
1 ignored issue
–
show
|
|||
| 125 | ) |
||
| 126 | ) { |
||
| 127 | $io->error('ERROR: Required parameter --doc|-d is not a valid document UID or URL.'); |
||
| 128 | exit(1); |
||
| 129 | } |
||
| 130 | |||
| 131 | // Get the document... |
||
| 132 | $doc = Document::getInstance($input->getOption('doc'), $startingPoint, TRUE); |
||
| 133 | if ($doc->ready) { |
||
| 134 | if ($dryRun) { |
||
| 135 | $io->section('DRY RUN: Would index ' . $doc->uid . ' ("' . $doc->location . '") on UID ' . $startingPoint . ' and Solr core ' . $solrCoreUid . '.'); |
||
| 136 | } else { |
||
| 137 | if ($io->isVerbose()) { |
||
| 138 | $io->section('Indexing ' . $doc->uid . ' ("' . $doc->location . '") on UID ' . $startingPoint . ' and Solr core ' . $solrCoreUid . '.'); |
||
| 139 | } |
||
| 140 | // ...and save it to the database... |
||
| 141 | if (!$doc->save($startingPoint, $solrCoreUid)) { |
||
| 142 | $io->error('ERROR: Document "' . $input->getOption('doc') . '" not saved and indexed.'); |
||
| 143 | exit(1); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } else { |
||
| 147 | $io->error('ERROR: Document "' . $input->getOption('doc') . '" could not be loaded.'); |
||
| 148 | exit(1); |
||
| 149 | } |
||
| 150 | |||
| 151 | $io->success('All done!'); |
||
| 152 | } |
||
| 188 |