diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-10-16 00:46:23 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-10-16 01:21:44 +0100 |
| commit | 83d28054ad99bacc7b0ad8fd08949f4c8e215244 (patch) | |
| tree | 14cc3b15588f6b5e5a3a2e25c1339a2103254549 | |
| parent | f3874e197f9762d298de9838533175b6115261e9 (diff) | |
| download | webtrees-83d28054ad99bacc7b0ad8fd08949f4c8e215244.tar.gz webtrees-83d28054ad99bacc7b0ad8fd08949f4c8e215244.tar.bz2 webtrees-83d28054ad99bacc7b0ad8fd08949f4c8e215244.zip | |
Simplify logic
| -rw-r--r-- | app/Census/CensusColumnChildrenLiving.php | 13 | ||||
| -rw-r--r-- | app/Functions/FunctionsPrint.php | 15 | ||||
| -rw-r--r-- | app/Http/Controllers/AdminTreesController.php | 26 | ||||
| -rw-r--r-- | app/Http/Controllers/BranchesController.php | 10 | ||||
| -rw-r--r-- | app/Module/StoriesModule.php | 2 |
5 files changed, 37 insertions, 29 deletions
diff --git a/app/Census/CensusColumnChildrenLiving.php b/app/Census/CensusColumnChildrenLiving.php index bd4728bc5f..8293748c61 100644 --- a/app/Census/CensusColumnChildrenLiving.php +++ b/app/Census/CensusColumnChildrenLiving.php @@ -43,12 +43,13 @@ class CensusColumnChildrenLiving extends AbstractCensusColumn implements CensusC $count = 0; foreach ($individual->spouseFamilies() as $family) { foreach ($family->children() as $child) { - if ( - $child->getBirthDate()->isOK() && - Date::compare($child->getBirthDate(), $this->date()) < 0 && - $child->getBirthDate() != $child->getDeathDate() && - (!$child->getDeathDate()->isOK() || Date::compare($child->getDeathDate(), $this->date()) > 0) - ) { + $birth = $child->getBirthDate(); + $death = $child->getDeathDate(); + + $born_before = $birth->isOK() && Date::compare($birth, $this->date()) < 0; + $died_after = $death->isOK() && Date::compare($death, $this->date()) > 0 || !$death->isOK(); + + if ($born_before && $died_after) { $count++; } } diff --git a/app/Functions/FunctionsPrint.php b/app/Functions/FunctionsPrint.php index 3d6875f03c..e393d20d4f 100644 --- a/app/Functions/FunctionsPrint.php +++ b/app/Functions/FunctionsPrint.php @@ -266,17 +266,18 @@ class FunctionsPrint $death_date = new Date(''); } $ageText = ''; - if ((Date::compare($date, $death_date) <= 0 || !$record->isDead()) || $fact === 'DEAT') { + if ($fact === 'DEAT' || (Date::compare($date, $death_date) <= 0 || !$record->isDead())) { // Before death, print age $age = Date::getAgeGedcom($birth_date, $date); // Only show calculated age if it differs from recorded age if ($age !== '' && $age !== '0d') { - if ( - $fact_age !== '' && $fact_age !== $age || - $fact_age === '' && $husb_age === '' && $wife_age === '' || - $husb_age !== '' && $record->sex() === 'M' && $husb_age !== $age || - $wife_age !== '' && $record->sex() === 'F' && $wife_age !== $age - ) { + if ($fact_age !== '' && $fact_age !== $age) { + $ageText = '(' . I18N::translate('Age') . ' ' . FunctionsDate::getAgeAtEvent($age) . ')'; + } elseif ($fact_age === '' && $husb_age === '' && $wife_age === '') { + $ageText = '(' . I18N::translate('Age') . ' ' . FunctionsDate::getAgeAtEvent($age) . ')'; + } elseif ($husb_age !== '' && $husb_age !== $age && $record->sex() === 'M') { + $ageText = '(' . I18N::translate('Age') . ' ' . FunctionsDate::getAgeAtEvent($age) . ')'; + } elseif ($wife_age !== '' && $wife_age !== $age && $record->sex() === 'F') { $ageText = '(' . I18N::translate('Age') . ' ' . FunctionsDate::getAgeAtEvent($age) . ')'; } } diff --git a/app/Http/Controllers/AdminTreesController.php b/app/Http/Controllers/AdminTreesController.php index bde81f2151..6a6091100c 100644 --- a/app/Http/Controllers/AdminTreesController.php +++ b/app/Http/Controllers/AdminTreesController.php @@ -62,6 +62,7 @@ use Throwable; use function addcslashes; use function app; +use function array_key_exists; use function assert; use function fclose; use function fopen; @@ -299,11 +300,11 @@ class AdminTreesController extends AbstractBaseController /* I18N: %1$s is an internal ID number such as R123. %2$s and %3$s are record types, such as INDI or SOUR */ I18N::translate('%1$s is a %2$s but a %3$s is expected.', $this->checkLink($tree, $xref2), $this->formatType($type3), $this->formatType($type2)); } elseif ( - $type2 === 'FAMC' && (!array_key_exists($xref1, $all_links[$xref2]) || $all_links[$xref2][$xref1] !== 'CHIL') || - $type2 === 'FAMS' && (!array_key_exists($xref1, $all_links[$xref2]) || $all_links[$xref2][$xref1] !== 'HUSB' && $all_links[$xref2][$xref1] !== 'WIFE') || - $type2 === 'CHIL' && (!array_key_exists($xref1, $all_links[$xref2]) || $all_links[$xref2][$xref1] !== 'FAMC') || - $type2 === 'HUSB' && (!array_key_exists($xref1, $all_links[$xref2]) || $all_links[$xref2][$xref1] !== 'FAMS') || - $type2 === 'WIFE' && (!array_key_exists($xref1, $all_links[$xref2]) || $all_links[$xref2][$xref1] !== 'FAMS') + $this->checkReverseLink($type2, $all_links, $xref1, $xref2, 'FAMC', ['CHIL']) || + $this->checkReverseLink($type2, $all_links, $xref1, $xref2, 'FAMS', ['HUSB', 'WIFE']) || + $this->checkReverseLink($type2, $all_links, $xref1, $xref2, 'CHIL', ['FAMC']) || + $this->checkReverseLink($type2, $all_links, $xref1, $xref2, 'HUSB', ['FAMS']) || + $this->checkReverseLink($type2, $all_links, $xref1, $xref2, 'WIFE', ['FAMS']) ) { /* I18N: %1$s and %2$s are internal ID numbers such as R123 */ $errors[] = $this->checkLinkMessage($tree, $type1, $xref1, $type2, $xref2) . ' ' . I18N::translate('%1$s does not have a link back to %2$s.', $this->checkLink($tree, $xref2), $this->checkLink($tree, $xref1)); @@ -322,6 +323,21 @@ class AdminTreesController extends AbstractBaseController } /** + * @param string $type + * @param array $links + * @param string $xref1 + * @param string $xref2 + * @param string $link + * @param array $reciprocal + * + * @return bool + */ + private function checkReverseLink(string $type, array $links, string $xref1, string $xref2, string $link, array $reciprocal): bool + { + return $type === $link && (!array_key_exists($xref1, $links[$xref2]) || !in_array($links[$xref2][$xref1], $reciprocal, true)); + } + + /** * Create a message linking one record to another. * * @param Tree $tree diff --git a/app/Http/Controllers/BranchesController.php b/app/Http/Controllers/BranchesController.php index 079a2f21b3..a3fdd66dc8 100644 --- a/app/Http/Controllers/BranchesController.php +++ b/app/Http/Controllers/BranchesController.php @@ -269,16 +269,6 @@ class BranchesController extends AbstractBaseController $person_name = ''; foreach ($individual->getAllNames() as $name) { [$surn1] = explode(',', $name['sort']); - if (// one name is a substring of the other - stripos($surn1, $surname) !== false || - stripos($surname, $surn1) !== false || - // one name sounds like the other - $soundex_std && Soundex::compare(Soundex::russell($surn1), Soundex::russell($surname)) || - $soundex_dm && Soundex::compare(Soundex::daitchMokotoff($surn1), Soundex::daitchMokotoff($surname)) - ) { - $person_name = $name['full']; - break; - } if ($this->surnamesMatch($surn1, $surname, $soundex_std, $soundex_dm)) { $person_name = $name['full']; break; diff --git a/app/Module/StoriesModule.php b/app/Module/StoriesModule.php index fe001ada56..4c8573123a 100644 --- a/app/Module/StoriesModule.php +++ b/app/Module/StoriesModule.php @@ -28,8 +28,8 @@ use Illuminate\Database\Capsule\Manager as DB; use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; - use stdClass; + use function assert; /** |
