We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 27 |
Paths | 49 |
Total Lines | 103 |
Code Lines | 60 |
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 |
||
183 | protected function saveToDatabase(Document $document) |
||
184 | { |
||
185 | $success = false; |
||
186 | |||
187 | $doc = $document->getDoc(); |
||
188 | if ($doc === null) { |
||
189 | return $success; |
||
190 | } |
||
191 | $doc->cPid = $this->storagePid; |
||
192 | |||
193 | $metadata = $doc->getTitledata($this->storagePid); |
||
194 | |||
195 | // set title data |
||
196 | $document->setTitle($metadata['title'][0] ? : ''); |
||
197 | $document->setTitleSorting($metadata['title_sorting'][0]); |
||
198 | $document->setPlace(implode('; ', $metadata['place'])); |
||
199 | $document->setYear(implode('; ', $metadata['year'])); |
||
200 | |||
201 | // Remove appended "valueURI" from authors' names for storing in database. |
||
202 | foreach ($metadata['author'] as $i => $author) { |
||
203 | $splitName = explode(chr(31), $author); |
||
204 | $metadata['author'][$i] = $splitName[0]; |
||
205 | } |
||
206 | $document->setAuthor(implode('; ', $metadata['author'])); |
||
207 | $document->setThumbnail($doc->thumbnail ? : ''); |
||
208 | $document->setMetsLabel($metadata['mets_label'][0] ? : ''); |
||
209 | $document->setMetsOrderlabel($metadata['mets_orderlabel'][0] ? : ''); |
||
210 | |||
211 | $document->setStructure(Helper::getUidFromIndexName($metadata['type'][0], 'tx_dlf_structures') ? : 0); |
||
212 | |||
213 | $collections = $this->collectionRepository->findCollectionsBySettings(['index_name' => $metadata['collection']]); |
||
214 | if ($collections) { |
||
215 | foreach ($collections as $collection) { |
||
216 | $document->addCollection($collection); |
||
217 | } |
||
218 | } |
||
219 | |||
220 | // set identifiers |
||
221 | $document->setProdId($metadata['prod_id'][0] ? : ''); |
||
222 | $document->setOpacId($metadata['opac_id'][0] ? : ''); |
||
223 | $document->setUnionId($metadata['union_id'][0] ? : ''); |
||
224 | |||
225 | $document->setRecordId($metadata['record_id'][0] ? : ''); // (?) $doc->recordId |
||
226 | $document->setUrn($metadata['urn'][0] ? : ''); |
||
227 | $document->setPurl($metadata['purl'][0] ? : ''); |
||
228 | $document->setDocumentFormat($metadata['document_format'][0] ? : ''); |
||
229 | |||
230 | // set access |
||
231 | $document->setLicense($metadata['license'][0] ? : ''); |
||
232 | $document->setTerms($metadata['terms'][0] ? : ''); |
||
233 | $document->setRestrictions($metadata['restrictions'][0] ? : ''); |
||
234 | $document->setOutOfPrint($metadata['out_of_print'][0] ? : ''); |
||
235 | $document->setRightsInfo($metadata['rights_info'][0] ? : ''); |
||
236 | $document->setStatus(0); |
||
237 | |||
238 | if ($this->owner) { |
||
239 | // library / owner is set by parameter --> take it. |
||
240 | $document->setOwner($this->owner); |
||
241 | } else { |
||
242 | // owner is not set set but found by metadata --> take it or take default library |
||
243 | $owner = $metadata['owner'][0] ? : 'default'; |
||
244 | $this->owner = $this->libraryRepository->findOneByIndexName($owner); |
||
245 | if ($this->owner) { |
||
246 | $document->setOwner($this->owner); |
||
247 | } else { |
||
248 | // create library |
||
249 | $this->owner = GeneralUtility::makeInstance(Library::class); |
||
250 | |||
251 | $this->owner->setLabel($owner); |
||
252 | $this->owner->setIndexName($owner); |
||
253 | $this->libraryRepository->add($this->owner); |
||
254 | $document->setOwner($this->owner); |
||
255 | } |
||
256 | } |
||
257 | |||
258 | // to be still (re-) implemented |
||
259 | // 'metadata' => serialize($listed), |
||
260 | // 'metadata_sorting' => serialize($sortable), |
||
261 | // 'volume' => $metadata['volume'][0], |
||
262 | // 'volume_sorting' => $metadata['volume_sorting'][0], |
||
263 | |||
264 | // Get UID of parent document. |
||
265 | if ($document->getDocumentFormat() === 'METS') { |
||
266 | $document->setPartof($this->getParentDocumentUidForSaving($document)); |
||
267 | } |
||
268 | |||
269 | $document->setMetadata(''); |
||
270 | $document->setMetadataSorting(''); |
||
271 | |||
272 | if ($document->getUid() === null) { |
||
273 | // new document |
||
274 | $this->documentRepository->add($document); |
||
275 | } else { |
||
276 | // update of existing document |
||
277 | $this->documentRepository->update($document); |
||
278 | } |
||
279 | |||
280 | $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
||
281 | $persistenceManager->persistAll(); |
||
282 | |||
283 | $success = true; |
||
284 | |||
285 | return $success; |
||
286 | } |
||
337 |