We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 13 |
| Paths | 20 |
| Total Lines | 44 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 170 | protected function loadDocument(array $requestData, int $pid): void |
||
| 171 | { |
||
| 172 | // Try to get document format from database |
||
| 173 | if (!empty($requestData['id'])) { |
||
| 174 | $this->initializeRepositories($pid); |
||
| 175 | $doc = null; |
||
| 176 | if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) { |
||
| 177 | // find document from repository by uid |
||
| 178 | $this->document = $this->documentRepository->findOneByIdAndSettings((int) $requestData['id'], ['storagePid' => $pid]); |
||
| 179 | if ($this->document) { |
||
| 180 | $doc = AbstractDocument::getInstance($this->document->getLocation(), ['storagePid' => $pid], true); |
||
| 181 | } else { |
||
| 182 | $this->logger->error('Invalid UID "' . $requestData['id'] . '" or PID "' . $pid . '" for document loading'); |
||
| 183 | } |
||
| 184 | } elseif (GeneralUtility::isValidUrl($requestData['id'])) { |
||
| 185 | $doc = AbstractDocument::getInstance($requestData['id'], ['storagePid' => $pid], true); |
||
| 186 | if ($doc !== null) { |
||
| 187 | if ($doc->recordId) { |
||
| 188 | $this->document = $this->documentRepository->findOneByRecordId($doc->recordId); |
||
| 189 | } |
||
| 190 | if (!isset($this->document)) { |
||
| 191 | // create new dummy Document object |
||
| 192 | $this->document = GeneralUtility::makeInstance(Document::class); |
||
| 193 | } |
||
| 194 | $this->document->setLocation($requestData['id']); |
||
| 195 | } else { |
||
| 196 | $this->logger->error('Invalid location given "' . $requestData['id'] . '" for document loading'); |
||
| 197 | } |
||
| 198 | } |
||
| 199 | if ($this->document !== null && $doc !== null) { |
||
| 200 | $this->document->setCurrentDocument($doc); |
||
| 201 | } |
||
| 202 | } elseif (!empty($requestData['recordId'])) { |
||
| 203 | $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']); |
||
|
|
|||
| 204 | if ($this->document !== null) { |
||
| 205 | $doc = AbstractDocument::getInstance($this->document->getLocation(), ['storagePid' => $pid], true); |
||
| 206 | if ($doc !== null) { |
||
| 207 | $this->document->setCurrentDocument($doc); |
||
| 208 | } else { |
||
| 209 | $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"'); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } else { |
||
| 213 | $this->logger->error('Empty UID or invalid PID "' . $pid . '" for document loading'); |
||
| 214 | } |
||
| 233 |