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