We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 14 |
| Paths | 26 |
| Total Lines | 47 |
| Code Lines | 25 |
| 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 |
||
| 68 | protected function loadDocument($requestData) |
||
| 69 | { |
||
| 70 | // Try to get document format from database |
||
| 71 | if (!empty($requestData['id'])) { |
||
| 72 | |||
| 73 | if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) { |
||
| 74 | // find document from repository by uid |
||
| 75 | $this->document = $this->documentRepository->findByUid((int) $requestData['id']); |
||
| 76 | if ($this->document) { |
||
| 77 | $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
||
| 78 | } |
||
| 79 | } else if (GeneralUtility::isValidUrl($requestData['id'])) { |
||
| 80 | |||
| 81 | $doc = Doc::getInstance($requestData['id'], $this->settings, true); |
||
| 82 | |||
| 83 | if ($doc->recordId) { |
||
| 84 | $this->document = $this->documentRepository->findOneByRecordId($doc->recordId); |
||
|
|
|||
| 85 | } |
||
| 86 | |||
| 87 | if ($this->document === null) { |
||
| 88 | // create new dummy Document object |
||
| 89 | $this->document = $this->objectManager->get(Document::class); |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($this->document) { |
||
| 93 | $this->document->setLocation($requestData['id']); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($this->document !== null && $doc !== null) { |
||
| 98 | $this->document->setDoc($doc); |
||
| 99 | } |
||
| 100 | |||
| 101 | } elseif (!empty($requestData['recordId'])) { |
||
| 102 | |||
| 103 | $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']); |
||
| 104 | |||
| 105 | if ($this->document !== null) { |
||
| 106 | $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
||
| 107 | if ($this->document !== null && $doc !== null) { |
||
| 108 | $this->document->setDoc($doc); |
||
| 109 | } else { |
||
| 110 | $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"'); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } else { |
||
| 114 | $this->logger->error('Invalid UID ' . $requestData['id'] . ' or PID ' . $this->settings['pages'] . ' for document loading'); |
||
| 115 | } |
||
| 129 |