We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 20 |
Paths | 168 |
Total Lines | 88 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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); |
||
95 | } |
||
96 | |||
97 | if ( |
||
98 | !empty($input->getOption('solr')) |
||
99 | && !is_array($input->getOption('solr')) |
||
100 | ) { |
||
101 | $allSolrCores = $this->getSolrCores($startingPoint); |
||
102 | if (MathUtility::canBeInterpretedAsInteger($input->getOption('solr'))) { |
||
103 | $solrCoreUid = MathUtility::forceIntegerInRange((int) $input->getOption('solr'), 0); |
||
104 | } else { |
||
105 | $solrCoreUid = $allSolrCores[$input->getOption('solr')]; |
||
106 | } |
||
107 | // Abort if solrCoreUid is empty or not in the array of allowed solr cores. |
||
108 | if (empty($solrCoreUid) || !in_array($solrCoreUid, $allSolrCores)) { |
||
109 | $output_solrCores = []; |
||
110 | foreach ($allSolrCores as $index_name => $uid) { |
||
111 | $output_solrCores[] = $uid . ' : ' . $index_name; |
||
112 | } |
||
113 | if (empty($output_solrCores)) { |
||
114 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. No valid cores found on PID ' . $startingPoint . ".\n"); |
||
115 | exit(1); |
||
116 | } else { |
||
117 | $io->error('ERROR: No valid Solr core ("' . $input->getOption('solr') . '") given. ' . "Valid cores are (<uid>:<index_name>):\n" . implode("\n", $output_solrCores) . "\n"); |
||
118 | exit(1); |
||
119 | } |
||
120 | } |
||
121 | } else { |
||
122 | $io->error('ERROR: Required parameter --solr|-s is missing or array.'); |
||
123 | exit(1); |
||
124 | } |
||
125 | |||
126 | if (!empty($input->getOption('all'))) { |
||
127 | // Get all documents. |
||
128 | $documents = $this->getAllDocuments($startingPoint); |
||
129 | } elseif ( |
||
130 | !empty($input->getOption('coll')) |
||
131 | && !is_array($input->getOption('coll')) |
||
132 | ) { |
||
133 | // "coll" may be a single integer or a comma-separated list of integers. |
||
134 | if (empty(array_filter(GeneralUtility::intExplode(',', $input->getOption('coll'), TRUE)))) { |
||
1 ignored issue
–
show
|
|||
135 | $io->error('ERROR: Parameter --coll|-c is not a valid comma-separated list of collection UIDs.'); |
||
136 | exit(1); |
||
137 | } |
||
138 | $documents = $this->getDocumentsToProceed($input->getOption('coll'), $startingPoint); |
||
139 | } else { |
||
140 | $io->error('ERROR: One of parameters --all|-a or --coll|-c must be given.'); |
||
141 | exit(1); |
||
142 | } |
||
143 | |||
144 | foreach ($documents as $id => $document) { |
||
145 | $doc = Document::getInstance($document, $startingPoint, TRUE); |
||
146 | if ($doc->ready) { |
||
147 | if ($dryRun) { |
||
148 | $io->writeln('DRY RUN: Would index ' . $id . '/' . count($documents) . ' ' . $doc->uid . ' ("' . $doc->location . '") on UID ' . $startingPoint . ' and Solr core ' . $solrCoreUid . '.'); |
||
149 | } else { |
||
150 | if ($io->isVerbose()) { |
||
151 | $io->writeln(date('Y-m-d H:i:s') . ' Indexing ' . $id . '/' . count($documents) . ' ' . $doc->uid . ' ("' . $doc->location . '") on UID ' . $startingPoint . ' and Solr core ' . $solrCoreUid . '.'); |
||
152 | } |
||
153 | // ...and save it to the database... |
||
154 | if (!$doc->save($startingPoint, $solrCoreUid)) { |
||
155 | $io->error('ERROR: Document "' . $id . '" not saved and indexed.'); |
||
156 | } |
||
157 | } |
||
158 | } else { |
||
159 | $io->error('ERROR: Document "' . $id . '" could not be loaded.'); |
||
160 | } |
||
161 | // Clear document registry to prevent memory exhaustion. |
||
162 | Document::clearRegistry(); |
||
163 | } |
||
164 | |||
165 | $io->success('All done!'); |
||
166 | } |
||
302 |