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