We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 15 |
Paths | 28 |
Total Lines | 58 |
Code Lines | 32 |
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 |
||
115 | protected function loadDocument($requestData) |
||
116 | { |
||
117 | // Try to get document format from database |
||
118 | if (!empty($requestData['id'])) { |
||
119 | |||
120 | $doc = null; |
||
121 | |||
122 | if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) { |
||
123 | // find document from repository by uid |
||
124 | $this->document = $this->documentRepository->findOneByIdAndSettings((int) $requestData['id']); |
||
125 | if ($this->document) { |
||
126 | $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
||
127 | } else { |
||
128 | $this->logger->error('Invalid UID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); |
||
129 | } |
||
130 | } else if (GeneralUtility::isValidUrl($requestData['id'])) { |
||
131 | |||
132 | $doc = Doc::getInstance($requestData['id'], $this->settings, true); |
||
133 | |||
134 | if ($doc !== null) { |
||
135 | if ($doc->recordId) { |
||
136 | $this->document = $this->documentRepository->findOneByRecordId($doc->recordId); |
||
|
|||
137 | } |
||
138 | |||
139 | if ($this->document === null) { |
||
140 | // create new dummy Document object |
||
141 | $this->document = GeneralUtility::makeInstance(Document::class); |
||
142 | } |
||
143 | |||
144 | // Make sure configuration PID is set when applicable |
||
145 | if ($doc->cPid == 0) { |
||
146 | $doc->cPid = max(intval($this->settings['storagePid']), 0); |
||
147 | } |
||
148 | |||
149 | $this->document->setLocation($requestData['id']); |
||
150 | } else { |
||
151 | $this->logger->error('Invalid location given "' . $requestData['id'] . '" for document loading'); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | if ($this->document !== null && $doc !== null) { |
||
156 | $this->document->setDoc($doc); |
||
157 | } |
||
158 | |||
159 | } elseif (!empty($requestData['recordId'])) { |
||
160 | |||
161 | $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']); |
||
162 | |||
163 | if ($this->document !== null) { |
||
164 | $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true); |
||
165 | if ($this->document !== null && $doc !== null) { |
||
166 | $this->document->setDoc($doc); |
||
167 | } else { |
||
168 | $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"'); |
||
169 | } |
||
170 | } |
||
171 | } else { |
||
172 | $this->logger->error('Invalid ID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); |
||
173 | } |
||
258 |