Conditions | 22 |
Paths | > 20000 |
Total Lines | 127 |
Code Lines | 77 |
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 |
||
255 | public function index($document) |
||
256 | { |
||
257 | try { |
||
258 | $data = json_decode($this->elasticsearchMapper->getElasticsearchJson($document)); |
||
259 | } catch (\Throwable $throwable) { |
||
260 | // Fixme: The solution via json_decode and the XSLT file needs to be replaced. |
||
261 | } |
||
262 | |||
263 | if (!$data) { |
||
264 | $data->title[] = $document->getTitle(); |
||
265 | $data->doctype = $document->getDocumentType()->getName(); |
||
266 | } |
||
267 | |||
268 | if ($data) { |
||
269 | |||
270 | $data->state = $document->getState(); |
||
271 | $data->aliasState = DocumentWorkflow::STATE_TO_ALIASSTATE_MAPPING[$document->getState()]; |
||
272 | |||
273 | $data->objectIdentifier = $document->getObjectIdentifier(); |
||
274 | |||
275 | if (!$data->identifier || !is_array($data->identifier)) { |
||
276 | $data->identifier = []; |
||
277 | } |
||
278 | $data->identifier[] = $document->getObjectIdentifier(); |
||
279 | $data->identifier[] = $document->getProcessNumber(); |
||
280 | |||
281 | if ($document->getCreator()) { |
||
282 | $data->creator = $document->getCreator(); |
||
283 | } else { |
||
284 | $data->creator = null; |
||
285 | } |
||
286 | |||
287 | if ($document->getCreator()) { |
||
288 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
||
289 | $frontendUserRepository = $objectManager->get(FrontendUserRepository::class); |
||
290 | |||
291 | /** @var \EWW\Dpf\Domain\Model\FrontendUser $creatorFeUser */ |
||
292 | $creatorFeUser = $frontendUserRepository->findByUid($document->getCreator()); |
||
293 | if ($creatorFeUser) { |
||
294 | $data->creatorRole = $creatorFeUser->getUserRole(); |
||
295 | } else { |
||
296 | $data->creatorRole = ''; |
||
297 | } |
||
298 | } else { |
||
299 | $data->creatorRole = ''; |
||
300 | } |
||
301 | |||
302 | $creationDate = new \DateTime($document->getCreationDate()); |
||
303 | |||
304 | $data->creationDate = $creationDate->format('Y-m-d'); |
||
305 | |||
306 | $data->year = $document->getPublicationYear(); |
||
307 | |||
308 | $notes = $document->getNotes(); |
||
309 | |||
310 | if ($notes && is_array($notes)) { |
||
311 | $data->notes = $notes; |
||
312 | } else { |
||
313 | $data->notes = array(); |
||
314 | } |
||
315 | |||
316 | $files = $document->getFile(); |
||
317 | if ($files->count() > 0) { |
||
318 | $data->hasFiles = true; |
||
319 | } else { |
||
320 | $data->hasFiles = false; |
||
321 | } |
||
322 | |||
323 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData(), $this->clientPid); |
||
324 | |||
325 | //$persons = array_merge($internalFormat->getAuthors(), $internalFormat->getPublishers()); |
||
326 | $persons = $internalFormat->getPersons(); |
||
327 | |||
328 | $fobIdentifiers = []; |
||
329 | $personData = []; |
||
330 | foreach ($persons as $person) { |
||
331 | $fobIdentifiers[] = $person['fobId']; |
||
332 | $personData[] = $person; |
||
333 | //$data->persons[] = $person['name']; |
||
334 | $data->persons[] = $person['fobId']; |
||
335 | |||
336 | foreach ($person['affiliations'] as $affiliation) { |
||
337 | $data->affiliation[] = $affiliation; |
||
338 | } |
||
339 | |||
340 | foreach ($person['affiliationIdentifiers'] as $affiliationIdentifier) { |
||
341 | $data->affiliation[] = $affiliationIdentifier; |
||
342 | } |
||
343 | } |
||
344 | |||
345 | $data->fobIdentifiers = $fobIdentifiers; |
||
346 | $data->personData = $personData; |
||
347 | |||
348 | if (sizeof($persons) > 0) { |
||
349 | if (array_key_exists('family', $persons[0])) { |
||
350 | $data->personsSort = $persons[0]['family']; |
||
351 | } |
||
352 | } |
||
353 | |||
354 | $data->source = $document->getSourceDetails(); |
||
355 | |||
356 | $data->universityCollection = false; |
||
357 | if ($data->collections && is_array($data->collections)) { |
||
358 | foreach ($data->collections as $collection) { |
||
359 | if ($collection == $this->clientConfigurationManager->getUniversityCollection()) { |
||
360 | $data->universityCollection = true; |
||
361 | break; |
||
362 | } |
||
363 | } |
||
364 | } |
||
365 | |||
366 | $embargoDate = $document->getEmbargoDate(); |
||
367 | if ($embargoDate instanceof \DateTime) { |
||
368 | $data->embargoDate = $embargoDate->format("Y-m-d"); |
||
369 | } else { |
||
370 | $data->embargoDate = null; |
||
371 | } |
||
372 | |||
373 | $data->originalSourceTitle = $internalFormat->getOriginalSourceTitle(); |
||
374 | |||
375 | $data->fobIdentifiers = $internalFormat->getPersonFisIdentifiers(); |
||
376 | |||
377 | $this->client->index([ |
||
378 | 'refresh' => 'wait_for', |
||
379 | 'index' => $this->getIndexName(), |
||
380 | 'id' => $document->getDocumentIdentifier(), |
||
381 | 'body' => $data |
||
382 | ]); |
||
476 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: