| Conditions | 19 |
| Paths | 3841 |
| Total Lines | 113 |
| Code Lines | 66 |
| 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 |
||
| 244 | public function index($document) |
||
| 245 | { |
||
| 246 | $data = json_decode($this->elasticsearchMapper->getElasticsearchJson($document)); |
||
| 247 | |||
| 248 | if ($data) { |
||
| 249 | |||
| 250 | $data->state = $document->getState(); |
||
| 251 | $data->aliasState = DocumentWorkflow::STATE_TO_ALIASSTATE_MAPPING[$document->getState()]; |
||
| 252 | |||
| 253 | $data->objectIdentifier = $document->getObjectIdentifier(); |
||
| 254 | |||
| 255 | if (!$data->identifier || !is_array($data->identifier)) { |
||
| 256 | $data->identifier = []; |
||
| 257 | } |
||
| 258 | $data->identifier[] = $document->getObjectIdentifier(); |
||
| 259 | $data->identifier[] = $document->getProcessNumber(); |
||
| 260 | |||
| 261 | if ($document->getCreator()) { |
||
| 262 | $data->creator = $document->getCreator(); |
||
| 263 | } else { |
||
| 264 | $data->creator = null; |
||
| 265 | } |
||
| 266 | |||
| 267 | |||
| 268 | if ($document->getCreator()) { |
||
| 269 | /** @var \EWW\Dpf\Domain\Model\FrontendUser $creatorFeUser */ |
||
| 270 | $creatorFeUser = $this->frontendUserRepository->findByUid($document->getCreator()); |
||
| 271 | $data->creatorRole = $creatorFeUser->getUserRole(); |
||
| 272 | } else { |
||
| 273 | $data->creatorRole = ''; |
||
| 274 | } |
||
| 275 | |||
| 276 | $creationDate = new \DateTime($document->getCreationDate()); |
||
| 277 | |||
| 278 | $data->creationDate = $creationDate->format('Y-m-d'); |
||
| 279 | |||
| 280 | $data->year = $document->getPublicationYear(); |
||
| 281 | |||
| 282 | $notes = $document->getNotes(); |
||
| 283 | |||
| 284 | if ($notes && is_array($notes)) { |
||
| 285 | $data->notes = $notes; |
||
| 286 | } else { |
||
| 287 | $data->notes = array(); |
||
| 288 | } |
||
| 289 | |||
| 290 | $files = $document->getFile(); |
||
| 291 | if ($files->count() > 0) { |
||
| 292 | $data->hasFiles = true; |
||
| 293 | } else { |
||
| 294 | $data->hasFiles = false; |
||
| 295 | } |
||
| 296 | |||
| 297 | |||
| 298 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
| 299 | |||
| 300 | //$persons = array_merge($internalFormat->getAuthors(), $internalFormat->getPublishers()); |
||
| 301 | $persons = $internalFormat->getPersons(); |
||
| 302 | |||
| 303 | $fobIdentifiers = []; |
||
| 304 | $personData = []; |
||
| 305 | foreach ($persons as $person) { |
||
| 306 | $fobIdentifiers[] = $person['fobId']; |
||
| 307 | $personData[] = $person; |
||
| 308 | //$data->persons[] = $person['name']; |
||
| 309 | $data->persons[] = $person['fobId']; |
||
| 310 | |||
| 311 | foreach ($person['affiliations'] as $affiliation) { |
||
| 312 | $data->affiliation[] = $affiliation; |
||
| 313 | } |
||
| 314 | |||
| 315 | foreach ($person['affiliationIdentifiers'] as $affiliationIdentifier) { |
||
| 316 | $data->affiliation[] = $affiliationIdentifier; |
||
| 317 | } |
||
| 318 | } |
||
| 319 | |||
| 320 | $data->fobIdentifiers = $fobIdentifiers; |
||
| 321 | $data->personData = $personData; |
||
| 322 | |||
| 323 | if (sizeof($persons) > 0) { |
||
| 324 | if (array_key_exists('family', $persons[0])) { |
||
| 325 | $data->personsSort = $persons[0]['family']; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | |||
| 329 | $data->source = $document->getSourceDetails(); |
||
| 330 | |||
| 331 | $data->universityCollection = false; |
||
| 332 | if ($data->collections && is_array($data->collections)) { |
||
| 333 | foreach ($data->collections as $collection) { |
||
| 334 | if ($collection == $this->getSettings()['universityCollection']) { |
||
| 335 | $data->universityCollection = true; |
||
| 336 | break; |
||
| 337 | } |
||
| 338 | } |
||
| 339 | } |
||
| 340 | |||
| 341 | //$embargoDate = $document->getEmbargoDate(); |
||
| 342 | if ($embargoDate instanceof \DateTime) { |
||
|
|
|||
| 343 | $data->embargoDate = $embargoDate->format("Y-m-d"); |
||
| 344 | } else { |
||
| 345 | $data->embargoDate = null; |
||
| 346 | } |
||
| 347 | |||
| 348 | $data->originalSourceTitle = $internalFormat->getOriginalSourceTitle(); |
||
| 349 | |||
| 350 | $data->fobIdentifiers = $internalFormat->getPersonFisIdentifiers(); |
||
| 351 | |||
| 352 | $this->client->index([ |
||
| 353 | 'refresh' => 'wait_for', |
||
| 354 | 'index' => $this->indexName, |
||
| 355 | 'id' => $document->getDocumentIdentifier(), |
||
| 356 | 'body' => $data |
||
| 357 | ]); |
||
| 451 |