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