Conditions | 43 |
Paths | 100 |
Total Lines | 422 |
Code Lines | 304 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
299 | private function childFacts(Individual $person, Family $family, string $option, string $relation, Date $min_date, Date $max_date): array |
||
300 | { |
||
301 | $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS'); |
||
302 | |||
303 | $birth_of_a_child = [ |
||
304 | 'BIRT' => [ |
||
305 | 'M' => I18N::translate('Birth of a son'), |
||
306 | 'F' => I18N::translate('Birth of a daughter'), |
||
307 | 'U' => I18N::translate('Birth of a child'), |
||
308 | ], |
||
309 | 'CHR' => [ |
||
310 | 'M' => I18N::translate('Christening of a son'), |
||
311 | 'F' => I18N::translate('Christening of a daughter'), |
||
312 | 'U' => I18N::translate('Christening of a child'), |
||
313 | ], |
||
314 | 'BAPM' => [ |
||
315 | 'M' => I18N::translate('Baptism of a son'), |
||
316 | 'F' => I18N::translate('Baptism of a daughter'), |
||
317 | 'U' => I18N::translate('Baptism of a child'), |
||
318 | ], |
||
319 | 'ADOP' => [ |
||
320 | 'M' => I18N::translate('Adoption of a son'), |
||
321 | 'F' => I18N::translate('Adoption of a daughter'), |
||
322 | 'U' => I18N::translate('Adoption of a child'), |
||
323 | ], |
||
324 | ]; |
||
325 | |||
326 | $birth_of_a_sibling = [ |
||
327 | 'BIRT' => [ |
||
328 | 'M' => I18N::translate('Birth of a brother'), |
||
329 | 'F' => I18N::translate('Birth of a sister'), |
||
330 | 'U' => I18N::translate('Birth of a sibling'), |
||
331 | ], |
||
332 | 'CHR' => [ |
||
333 | 'M' => I18N::translate('Christening of a brother'), |
||
334 | 'F' => I18N::translate('Christening of a sister'), |
||
335 | 'U' => I18N::translate('Christening of a sibling'), |
||
336 | ], |
||
337 | 'BAPM' => [ |
||
338 | 'M' => I18N::translate('Baptism of a brother'), |
||
339 | 'F' => I18N::translate('Baptism of a sister'), |
||
340 | 'U' => I18N::translate('Baptism of a sibling'), |
||
341 | ], |
||
342 | 'ADOP' => [ |
||
343 | 'M' => I18N::translate('Adoption of a brother'), |
||
344 | 'F' => I18N::translate('Adoption of a sister'), |
||
345 | 'U' => I18N::translate('Adoption of a sibling'), |
||
346 | ], |
||
347 | ]; |
||
348 | |||
349 | $birth_of_a_half_sibling = [ |
||
350 | 'BIRT' => [ |
||
351 | 'M' => I18N::translate('Birth of a half-brother'), |
||
352 | 'F' => I18N::translate('Birth of a half-sister'), |
||
353 | 'U' => I18N::translate('Birth of a half-sibling'), |
||
354 | ], |
||
355 | 'CHR' => [ |
||
356 | 'M' => I18N::translate('Christening of a half-brother'), |
||
357 | 'F' => I18N::translate('Christening of a half-sister'), |
||
358 | 'U' => I18N::translate('Christening of a half-sibling'), |
||
359 | ], |
||
360 | 'BAPM' => [ |
||
361 | 'M' => I18N::translate('Baptism of a half-brother'), |
||
362 | 'F' => I18N::translate('Baptism of a half-sister'), |
||
363 | 'U' => I18N::translate('Baptism of a half-sibling'), |
||
364 | ], |
||
365 | 'ADOP' => [ |
||
366 | 'M' => I18N::translate('Adoption of a half-brother'), |
||
367 | 'F' => I18N::translate('Adoption of a half-sister'), |
||
368 | 'U' => I18N::translate('Adoption of a half-sibling'), |
||
369 | ], |
||
370 | ]; |
||
371 | |||
372 | $birth_of_a_grandchild = [ |
||
373 | 'BIRT' => [ |
||
374 | 'M' => I18N::translate('Birth of a grandson'), |
||
375 | 'F' => I18N::translate('Birth of a granddaughter'), |
||
376 | 'U' => I18N::translate('Birth of a grandchild'), |
||
377 | ], |
||
378 | 'CHR' => [ |
||
379 | 'M' => I18N::translate('Christening of a grandson'), |
||
380 | 'F' => I18N::translate('Christening of a granddaughter'), |
||
381 | 'U' => I18N::translate('Christening of a grandchild'), |
||
382 | ], |
||
383 | 'BAPM' => [ |
||
384 | 'M' => I18N::translate('Baptism of a grandson'), |
||
385 | 'F' => I18N::translate('Baptism of a granddaughter'), |
||
386 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
387 | ], |
||
388 | 'ADOP' => [ |
||
389 | 'M' => I18N::translate('Adoption of a grandson'), |
||
390 | 'F' => I18N::translate('Adoption of a granddaughter'), |
||
391 | 'U' => I18N::translate('Adoption of a grandchild'), |
||
392 | ], |
||
393 | ]; |
||
394 | |||
395 | $birth_of_a_grandchild1 = [ |
||
396 | 'BIRT' => [ |
||
397 | 'M' => I18N::translateContext('daughter’s son', 'Birth of a grandson'), |
||
398 | 'F' => I18N::translateContext('daughter’s daughter', 'Birth of a granddaughter'), |
||
399 | 'U' => I18N::translate('Birth of a grandchild'), |
||
400 | ], |
||
401 | 'CHR' => [ |
||
402 | 'M' => I18N::translateContext('daughter’s son', 'Christening of a grandson'), |
||
403 | 'F' => I18N::translateContext('daughter’s daughter', 'Christening of a granddaughter'), |
||
404 | 'U' => I18N::translate('Christening of a grandchild'), |
||
405 | ], |
||
406 | 'BAPM' => [ |
||
407 | 'M' => I18N::translateContext('daughter’s son', 'Baptism of a grandson'), |
||
408 | 'F' => I18N::translateContext('daughter’s daughter', 'Baptism of a granddaughter'), |
||
409 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
410 | ], |
||
411 | 'ADOP' => [ |
||
412 | 'M' => I18N::translateContext('daughter’s son', 'Adoption of a grandson'), |
||
413 | 'F' => I18N::translateContext('daughter’s daughter', 'Adoption of a granddaughter'), |
||
414 | 'U' => I18N::translate('Adoption of a grandchild'), |
||
415 | ], |
||
416 | ]; |
||
417 | |||
418 | $birth_of_a_grandchild2 = [ |
||
419 | 'BIRT' => [ |
||
420 | 'M' => I18N::translateContext('son’s son', 'Birth of a grandson'), |
||
421 | 'F' => I18N::translateContext('son’s daughter', 'Birth of a granddaughter'), |
||
422 | 'U' => I18N::translate('Birth of a grandchild'), |
||
423 | ], |
||
424 | 'CHR' => [ |
||
425 | 'M' => I18N::translateContext('son’s son', 'Christening of a grandson'), |
||
426 | 'F' => I18N::translateContext('son’s daughter', 'Christening of a granddaughter'), |
||
427 | 'U' => I18N::translate('Christening of a grandchild'), |
||
428 | ], |
||
429 | 'BAPM' => [ |
||
430 | 'M' => I18N::translateContext('son’s son', 'Baptism of a grandson'), |
||
431 | 'F' => I18N::translateContext('son’s daughter', 'Baptism of a granddaughter'), |
||
432 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
433 | ], |
||
434 | 'ADOP' => [ |
||
435 | 'M' => I18N::translateContext('son’s son', 'Adoption of a grandson'), |
||
436 | 'F' => I18N::translateContext('son’s daughter', 'Adoption of a granddaughter'), |
||
437 | 'U' => I18N::translate('Adoption of a grandchild'), |
||
438 | ], |
||
439 | ]; |
||
440 | |||
441 | $death_of_a_child = [ |
||
442 | 'DEAT' => [ |
||
443 | 'M' => I18N::translate('Death of a son'), |
||
444 | 'F' => I18N::translate('Death of a daughter'), |
||
445 | 'U' => I18N::translate('Death of a child'), |
||
446 | ], |
||
447 | 'BURI' => [ |
||
448 | 'M' => I18N::translate('Burial of a son'), |
||
449 | 'F' => I18N::translate('Burial of a daughter'), |
||
450 | 'U' => I18N::translate('Burial of a child'), |
||
451 | ], |
||
452 | 'CREM' => [ |
||
453 | 'M' => I18N::translate('Cremation of a son'), |
||
454 | 'F' => I18N::translate('Cremation of a daughter'), |
||
455 | 'U' => I18N::translate('Cremation of a child'), |
||
456 | ], |
||
457 | ]; |
||
458 | |||
459 | $death_of_a_sibling = [ |
||
460 | 'DEAT' => [ |
||
461 | 'M' => I18N::translate('Death of a brother'), |
||
462 | 'F' => I18N::translate('Death of a sister'), |
||
463 | 'U' => I18N::translate('Death of a sibling'), |
||
464 | ], |
||
465 | 'BURI' => [ |
||
466 | 'M' => I18N::translate('Burial of a brother'), |
||
467 | 'F' => I18N::translate('Burial of a sister'), |
||
468 | 'U' => I18N::translate('Burial of a sibling'), |
||
469 | ], |
||
470 | 'CREM' => [ |
||
471 | 'M' => I18N::translate('Cremation of a brother'), |
||
472 | 'F' => I18N::translate('Cremation of a sister'), |
||
473 | 'U' => I18N::translate('Cremation of a sibling'), |
||
474 | ], |
||
475 | ]; |
||
476 | |||
477 | $death_of_a_half_sibling = [ |
||
478 | 'DEAT' => [ |
||
479 | 'M' => I18N::translate('Death of a half-brother'), |
||
480 | 'F' => I18N::translate('Death of a half-sister'), |
||
481 | 'U' => I18N::translate('Death of a half-sibling'), |
||
482 | ], |
||
483 | 'BURI' => [ |
||
484 | 'M' => I18N::translate('Burial of a half-brother'), |
||
485 | 'F' => I18N::translate('Burial of a half-sister'), |
||
486 | 'U' => I18N::translate('Burial of a half-sibling'), |
||
487 | ], |
||
488 | 'CREM' => [ |
||
489 | 'M' => I18N::translate('Cremation of a half-brother'), |
||
490 | 'F' => I18N::translate('Cremation of a half-sister'), |
||
491 | 'U' => I18N::translate('Cremation of a half-sibling'), |
||
492 | ], |
||
493 | ]; |
||
494 | |||
495 | $death_of_a_grandchild = [ |
||
496 | 'DEAT' => [ |
||
497 | 'M' => I18N::translate('Death of a grandson'), |
||
498 | 'F' => I18N::translate('Death of a granddaughter'), |
||
499 | 'U' => I18N::translate('Death of a grandchild'), |
||
500 | ], |
||
501 | 'BURI' => [ |
||
502 | 'M' => I18N::translate('Burial of a grandson'), |
||
503 | 'F' => I18N::translate('Burial of a granddaughter'), |
||
504 | 'U' => I18N::translate('Burial of a grandchild'), |
||
505 | ], |
||
506 | 'CREM' => [ |
||
507 | 'M' => I18N::translate('Cremation of a grandson'), |
||
508 | 'F' => I18N::translate('Cremation of a granddaughter'), |
||
509 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
510 | ], |
||
511 | ]; |
||
512 | |||
513 | $death_of_a_grandchild1 = [ |
||
514 | 'DEAT' => [ |
||
515 | 'M' => I18N::translateContext('daughter’s son', 'Death of a grandson'), |
||
516 | 'F' => I18N::translateContext('daughter’s daughter', 'Death of a granddaughter'), |
||
517 | 'U' => I18N::translate('Death of a grandchild'), |
||
518 | ], |
||
519 | 'BURI' => [ |
||
520 | 'M' => I18N::translateContext('daughter’s son', 'Burial of a grandson'), |
||
521 | 'F' => I18N::translateContext('daughter’s daughter', 'Burial of a granddaughter'), |
||
522 | 'U' => I18N::translate('Burial of a grandchild'), |
||
523 | ], |
||
524 | 'CREM' => [ |
||
525 | 'M' => I18N::translateContext('daughter’s son', 'Cremation of a grandson'), |
||
526 | 'F' => I18N::translateContext('daughter’s daughter', 'Cremation of a granddaughter'), |
||
527 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
528 | ], |
||
529 | ]; |
||
530 | |||
531 | $death_of_a_grandchild2 = [ |
||
532 | 'DEAT' => [ |
||
533 | 'M' => I18N::translateContext('son’s son', 'Death of a grandson'), |
||
534 | 'F' => I18N::translateContext('son’s daughter', 'Death of a granddaughter'), |
||
535 | 'U' => I18N::translate('Death of a grandchild'), |
||
536 | ], |
||
537 | 'BURI' => [ |
||
538 | 'M' => I18N::translateContext('son’s son', 'Burial of a grandson'), |
||
539 | 'F' => I18N::translateContext('son’s daughter', 'Burial of a granddaughter'), |
||
540 | 'U' => I18N::translate('Burial of a grandchild'), |
||
541 | ], |
||
542 | 'CREM' => [ |
||
543 | 'M' => I18N::translateContext('son’s son', 'Cremation of a grandson'), |
||
544 | 'F' => I18N::translateContext('son’s daughter', 'Cremation of a granddaughter'), |
||
545 | 'U' => I18N::translate('Cremation of a grandchild'), |
||
546 | ], |
||
547 | ]; |
||
548 | |||
549 | $marriage_of_a_child = [ |
||
550 | 'M' => I18N::translate('Marriage of a son'), |
||
551 | 'F' => I18N::translate('Marriage of a daughter'), |
||
552 | 'U' => I18N::translate('Marriage of a child'), |
||
553 | ]; |
||
554 | |||
555 | $marriage_of_a_grandchild = [ |
||
556 | 'M' => I18N::translate('Marriage of a grandson'), |
||
557 | 'F' => I18N::translate('Marriage of a granddaughter'), |
||
558 | 'U' => I18N::translate('Marriage of a grandchild'), |
||
559 | ]; |
||
560 | |||
561 | $marriage_of_a_grandchild1 = [ |
||
562 | 'M' => I18N::translateContext('daughter’s son', 'Marriage of a grandson'), |
||
563 | 'F' => I18N::translateContext('daughter’s daughter', 'Marriage of a granddaughter'), |
||
564 | 'U' => I18N::translate('Marriage of a grandchild'), |
||
565 | ]; |
||
566 | |||
567 | $marriage_of_a_grandchild2 = [ |
||
568 | 'M' => I18N::translateContext('son’s son', 'Marriage of a grandson'), |
||
569 | 'F' => I18N::translateContext('son’s daughter', 'Marriage of a granddaughter'), |
||
570 | 'U' => I18N::translate('Marriage of a grandchild'), |
||
571 | ]; |
||
572 | |||
573 | $marriage_of_a_sibling = [ |
||
574 | 'M' => I18N::translate('Marriage of a brother'), |
||
575 | 'F' => I18N::translate('Marriage of a sister'), |
||
576 | 'U' => I18N::translate('Marriage of a sibling'), |
||
577 | ]; |
||
578 | |||
579 | $marriage_of_a_half_sibling = [ |
||
580 | 'M' => I18N::translate('Marriage of a half-brother'), |
||
581 | 'F' => I18N::translate('Marriage of a half-sister'), |
||
582 | 'U' => I18N::translate('Marriage of a half-sibling'), |
||
583 | ]; |
||
584 | |||
585 | $facts = []; |
||
586 | |||
587 | // Deal with recursion. |
||
588 | switch ($option) { |
||
589 | case '_CHIL': |
||
590 | // Add grandchildren |
||
591 | foreach ($family->children() as $child) { |
||
592 | foreach ($child->spouseFamilies() as $cfamily) { |
||
593 | switch ($child->sex()) { |
||
594 | case 'M': |
||
595 | foreach ($this->childFacts($person, $cfamily, '_GCHI', 'son', $min_date, $max_date) as $fact) { |
||
596 | $facts[] = $fact; |
||
597 | } |
||
598 | break; |
||
599 | case 'F': |
||
600 | foreach ($this->childFacts($person, $cfamily, '_GCHI', 'dau', $min_date, $max_date) as $fact) { |
||
601 | $facts[] = $fact; |
||
602 | } |
||
603 | break; |
||
604 | default: |
||
605 | foreach ($this->childFacts($person, $cfamily, '_GCHI', 'chi', $min_date, $max_date) as $fact) { |
||
606 | $facts[] = $fact; |
||
607 | } |
||
608 | break; |
||
609 | } |
||
610 | } |
||
611 | } |
||
612 | break; |
||
613 | } |
||
614 | |||
615 | // For each child in the family |
||
616 | foreach ($family->children() as $child) { |
||
617 | if ($child->xref() === $person->xref()) { |
||
618 | // We are not our own sibling! |
||
619 | continue; |
||
620 | } |
||
621 | // add child’s birth |
||
622 | if (str_contains($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option))) { |
||
623 | foreach ($child->facts(['BIRT', 'CHR', 'BAPM', 'ADOP']) as $fact) { |
||
624 | // Always show _BIRT_CHIL, even if the dates are not known |
||
625 | if ($option === '_CHIL' || $this->includeFact($fact, $min_date, $max_date)) { |
||
626 | switch ($option) { |
||
627 | case '_GCHI': |
||
628 | switch ($relation) { |
||
629 | case 'dau': |
||
630 | $facts[] = $this->convertEvent($fact, $birth_of_a_grandchild1[$fact->getTag()][$fact->record()->sex()]); |
||
631 | break; |
||
632 | case 'son': |
||
633 | $facts[] = $this->convertEvent($fact, $birth_of_a_grandchild2[$fact->getTag()][$fact->record()->sex()]); |
||
634 | break; |
||
635 | case 'chil': |
||
636 | $facts[] = $this->convertEvent($fact, $birth_of_a_grandchild[$fact->getTag()][$fact->record()->sex()]); |
||
637 | break; |
||
638 | } |
||
639 | break; |
||
640 | case '_SIBL': |
||
641 | $facts[] = $this->convertEvent($fact, $birth_of_a_sibling[$fact->getTag()][$fact->record()->sex()]); |
||
642 | break; |
||
643 | case '_HSIB': |
||
644 | $facts[] = $this->convertEvent($fact, $birth_of_a_half_sibling[$fact->getTag()][$fact->record()->sex()]); |
||
645 | break; |
||
646 | case '_CHIL': |
||
647 | $facts[] = $this->convertEvent($fact, $birth_of_a_child[$fact->getTag()][$fact->record()->sex()]); |
||
648 | break; |
||
649 | } |
||
650 | } |
||
651 | } |
||
652 | } |
||
653 | // add child’s death |
||
654 | if (str_contains($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option))) { |
||
655 | foreach ($child->facts(['DEAT', 'BURI', 'CREM']) as $fact) { |
||
656 | if ($this->includeFact($fact, $min_date, $max_date)) { |
||
657 | switch ($option) { |
||
658 | case '_GCHI': |
||
659 | switch ($relation) { |
||
660 | case 'dau': |
||
661 | $facts[] = $this->convertEvent($fact, $death_of_a_grandchild1[$fact->getTag()][$fact->record()->sex()]); |
||
662 | break; |
||
663 | case 'son': |
||
664 | $facts[] = $this->convertEvent($fact, $death_of_a_grandchild2[$fact->getTag()][$fact->record()->sex()]); |
||
665 | break; |
||
666 | case 'chi': |
||
667 | $facts[] = $this->convertEvent($fact, $death_of_a_grandchild[$fact->getTag()][$fact->record()->sex()]); |
||
668 | break; |
||
669 | } |
||
670 | break; |
||
671 | case '_SIBL': |
||
672 | $facts[] = $this->convertEvent($fact, $death_of_a_sibling[$fact->getTag()][$fact->record()->sex()]); |
||
673 | break; |
||
674 | case '_HSIB': |
||
675 | $facts[] = $this->convertEvent($fact, $death_of_a_half_sibling[$fact->getTag()][$fact->record()->sex()]); |
||
676 | break; |
||
677 | case '_CHIL': |
||
678 | $facts[] = $this->convertEvent($fact, $death_of_a_child[$fact->getTag()][$fact->record()->sex()]); |
||
679 | break; |
||
680 | } |
||
681 | } |
||
682 | } |
||
683 | } |
||
684 | |||
685 | // add child’s marriage |
||
686 | if (str_contains($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) { |
||
687 | foreach ($child->spouseFamilies() as $sfamily) { |
||
688 | foreach ($sfamily->facts(['MARR']) as $fact) { |
||
689 | if ($this->includeFact($fact, $min_date, $max_date)) { |
||
690 | switch ($option) { |
||
691 | case '_GCHI': |
||
692 | switch ($relation) { |
||
693 | case 'dau': |
||
694 | $facts[] = $this->convertEvent($fact, $marriage_of_a_grandchild1['F']); |
||
695 | break; |
||
696 | case 'son': |
||
697 | $facts[] = $this->convertEvent($fact, $marriage_of_a_grandchild2['M']); |
||
698 | break; |
||
699 | case 'chi': |
||
700 | $facts[] = $this->convertEvent($fact, $marriage_of_a_grandchild['U']); |
||
701 | break; |
||
702 | } |
||
703 | break; |
||
704 | case '_SIBL': |
||
705 | $facts[] = $this->convertEvent($fact, $marriage_of_a_sibling['U']); |
||
706 | break; |
||
707 | case '_HSIB': |
||
708 | $facts[] = $this->convertEvent($fact, $marriage_of_a_half_sibling['U']); |
||
709 | break; |
||
710 | case '_CHIL': |
||
711 | $facts[] = $this->convertEvent($fact, $marriage_of_a_child['U']); |
||
712 | break; |
||
713 | } |
||
714 | } |
||
715 | } |
||
716 | } |
||
717 | } |
||
718 | } |
||
719 | |||
720 | return $facts; |
||
721 | } |
||
967 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.