We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 21 |
Paths | 92 |
Total Lines | 106 |
Code Lines | 66 |
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 |
||
91 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
92 | { |
||
93 | $dryRun = $input->getOption('dry-run') != false ? true : false; |
||
94 | |||
95 | $io = new SymfonyStyle($input, $output); |
||
96 | $io->title($this->getDescription()); |
||
97 | |||
98 | $this->initializeRepositories($input->getOption('pid')); |
||
99 | |||
100 | if ($this->storagePid == 0) { |
||
101 | $io->error('ERROR: No valid PID (' . $this->storagePid . ') given.'); |
||
102 | return BaseCommand::FAILURE; |
||
103 | } |
||
104 | |||
105 | if ( |
||
106 | !empty($input->getOption('solr')) |
||
107 | && !is_array($input->getOption('solr')) |
||
108 | ) { |
||
109 | $allSolrCores = $this->getSolrCores($this->storagePid); |
||
110 | $solrCoreUid = $this->getSolrCoreUid($allSolrCores, $input->getOption('solr')); |
||
111 | |||
112 | // Abort if solrCoreUid is empty or not in the array of allowed solr cores. |
||
113 | if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) { |
||
114 | $output_solrCores = []; |
||
115 | foreach ($allSolrCores as $index_name => $uid) { |
||
116 | $output_solrCores[] = $uid . ' : ' . $index_name; |
||
117 | } |
||
118 | if (empty($output_solrCores)) { |
||
119 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $this->storagePid . ".\n"); |
||
120 | return BaseCommand::FAILURE; |
||
121 | } else { |
||
122 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n"); |
||
123 | return BaseCommand::FAILURE; |
||
124 | } |
||
125 | } |
||
126 | } else { |
||
127 | $io->error('ERROR: Required parameter --solr|-s is missing or array.'); |
||
128 | return BaseCommand::FAILURE; |
||
129 | } |
||
130 | |||
131 | if ( |
||
132 | empty($input->getOption('doc')) |
||
133 | || is_array($input->getOption('doc')) |
||
134 | || ( |
||
135 | !MathUtility::canBeInterpretedAsInteger($input->getOption('doc')) |
||
136 | && !GeneralUtility::isValidUrl($input->getOption('doc')) |
||
137 | ) |
||
138 | ) { |
||
139 | $io->error('ERROR: Required parameter --doc|-d is not a valid document UID or URL.'); |
||
140 | return BaseCommand::FAILURE; |
||
141 | } |
||
142 | |||
143 | if (!empty($input->getOption('owner'))) { |
||
144 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('owner'))) { |
||
145 | $this->owner = $this->libraryRepository->findByUid(MathUtility::forceIntegerInRange((int) $input->getOption('owner'), 1)); |
||
146 | } else { |
||
147 | $this->owner = $this->libraryRepository->findOneByIndexName((string) $input->getOption('owner')); |
||
|
|||
148 | } |
||
149 | } else { |
||
150 | $this->owner = null; |
||
151 | } |
||
152 | |||
153 | $document = null; |
||
154 | $doc = null; |
||
155 | |||
156 | // Try to find existing document in database |
||
157 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('doc'))) { |
||
158 | |||
159 | $document = $this->documentRepository->findByUid($input->getOption('doc')); |
||
160 | |||
161 | if ($document === null) { |
||
162 | $io->error('ERROR: Document with UID "' . $input->getOption('doc') . '" could not be found on PID ' . $this->storagePid . ' .'); |
||
163 | exit(1); |
||
164 | } else { |
||
165 | $doc = AbstractDocument::getInstance($document->getLocation(), ['storagePid' => $this->storagePid], true); |
||
166 | } |
||
167 | |||
168 | } else if (GeneralUtility::isValidUrl($input->getOption('doc'))) { |
||
169 | $doc = AbstractDocument::getInstance($input->getOption('doc'), ['storagePid' => $this->storagePid], true); |
||
170 | |||
171 | $document = $this->getDocumentFromUrl($doc, $input->getOption('doc')); |
||
172 | } |
||
173 | |||
174 | if ($doc === null) { |
||
175 | $io->error('ERROR: Document "' . $input->getOption('doc') . '" could not be loaded.'); |
||
176 | return BaseCommand::FAILURE; |
||
177 | } |
||
178 | |||
179 | $document->setSolrcore($solrCoreUid); |
||
180 | |||
181 | if ($dryRun) { |
||
182 | $io->section('DRY RUN: Would index ' . $document->getUid() . ' ("' . $document->getLocation() . '") on PID ' . $this->storagePid . ' and Solr core ' . $solrCoreUid . '.'); |
||
183 | } else { |
||
184 | if ($io->isVerbose()) { |
||
185 | $io->section('Indexing ' . $document->getUid() . ' ("' . $document->getLocation() . '") on PID ' . $this->storagePid . ' and Solr core ' . $solrCoreUid . '.'); |
||
186 | } |
||
187 | $document->setCurrentDocument($doc); |
||
188 | // save to database |
||
189 | $this->saveToDatabase($document); |
||
190 | // add to index |
||
191 | Indexer::add($document, $this->documentRepository); |
||
192 | } |
||
193 | |||
194 | $io->success('All done!'); |
||
195 | |||
196 | return BaseCommand::SUCCESS; |
||
197 | } |
||
232 |