We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 14 |
Paths | 20 |
Total Lines | 53 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
109 | protected function loadDocument($requestData) |
||
110 | { |
||
111 | // Try to get document format from database |
||
112 | if (!empty($requestData['id'])) { |
||
113 | |||
114 | $doc = null; |
||
115 | |||
116 | if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) { |
||
117 | // find document from repository by uid |
||
118 | $this->document = $this->documentRepository->findOneByIdAndSettings((int) $requestData['id']); |
||
119 | if ($this->document) { |
||
120 | $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
||
121 | } else { |
||
122 | $this->logger->error('Invalid UID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); |
||
123 | } |
||
124 | } else if (GeneralUtility::isValidUrl($requestData['id'])) { |
||
125 | |||
126 | $doc = Doc::getInstance($requestData['id'], $this->settings, true); |
||
127 | |||
128 | if ($doc !== null) { |
||
129 | if ($doc->recordId) { |
||
130 | $this->document = $this->documentRepository->findOneByRecordId($doc->recordId); |
||
|
|||
131 | } |
||
132 | |||
133 | if ($this->document === null) { |
||
134 | // create new dummy Document object |
||
135 | $this->document = GeneralUtility::makeInstance(Document::class); |
||
136 | } |
||
137 | |||
138 | $this->document->setLocation($requestData['id']); |
||
139 | } else { |
||
140 | $this->logger->error('Invalid location given "' . $requestData['id'] . '" for document loading'); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | if ($this->document !== null && $doc !== null) { |
||
145 | $this->document->setDoc($doc); |
||
146 | } |
||
147 | |||
148 | } elseif (!empty($requestData['recordId'])) { |
||
149 | |||
150 | $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']); |
||
151 | |||
152 | if ($this->document !== null) { |
||
153 | $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
||
154 | if ($this->document !== null && $doc !== null) { |
||
155 | $this->document->setDoc($doc); |
||
156 | } else { |
||
157 | $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"'); |
||
158 | } |
||
159 | } |
||
160 | } else { |
||
161 | $this->logger->error('Invalid ID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); |
||
162 | } |
||
203 |