| Conditions | 12 |
| Paths | 8 |
| Total Lines | 54 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 79 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 80 | { |
||
| 81 | $io = new SymfonyStyle($input, $output); |
||
| 82 | $io->title($this->getDescription()); |
||
| 83 | |||
| 84 | $this->initializeRepositories((int) $input->getOption('pid')); |
||
| 85 | |||
| 86 | if ($this->storagePid == 0) { |
||
| 87 | $io->error('ERROR: No valid PID (' . $this->storagePid . ') given.'); |
||
| 88 | return BaseCommand::FAILURE; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ( |
||
| 92 | !empty($input->getOption('solr')) |
||
| 93 | && !is_array($input->getOption('solr')) |
||
| 94 | ) { |
||
| 95 | $allSolrCores = $this->getSolrCores($this->storagePid); |
||
| 96 | $solrCoreUid = $this->getSolrCoreUid($allSolrCores, $input->getOption('solr')); |
||
| 97 | |||
| 98 | // Abort if solrCoreUid is empty or not in the array of allowed solr cores. |
||
| 99 | if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) { |
||
| 100 | $outputSolrCores = []; |
||
| 101 | foreach ($allSolrCores as $indexName => $uid) { |
||
| 102 | $outputSolrCores[] = $uid . ' : ' . $indexName; |
||
| 103 | } |
||
| 104 | if (empty($outputSolrCores)) { |
||
| 105 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $this->storagePid . ".\n"); |
||
| 106 | return BaseCommand::FAILURE; |
||
| 107 | } else { |
||
| 108 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $outputSolrCores) . "\n"); |
||
| 109 | return BaseCommand::FAILURE; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } else { |
||
| 113 | $io->error('ERROR: Required parameter --solr|-s is missing or array.'); |
||
| 114 | return BaseCommand::FAILURE; |
||
| 115 | } |
||
| 116 | |||
| 117 | if ( |
||
| 118 | empty($input->getOption('doc')) |
||
| 119 | || is_array($input->getOption('doc')) |
||
| 120 | || ( |
||
| 121 | !MathUtility::canBeInterpretedAsInteger($input->getOption('doc')) |
||
| 122 | && !GeneralUtility::isValidUrl($input->getOption('doc')) |
||
| 123 | ) |
||
| 124 | ) { |
||
| 125 | $io->error('ERROR: Required parameter --doc|-d is not a valid document UID or URL.'); |
||
| 126 | return BaseCommand::FAILURE; |
||
| 127 | } |
||
| 128 | |||
| 129 | $this->deleteFromDatabase($input, $io); |
||
| 130 | $this->deleteFromSolr($input, $io, $solrCoreUid); |
||
| 131 | |||
| 132 | return BaseCommand::SUCCESS; |
||
| 133 | } |
||
| 226 |