diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2022-11-06 18:04:41 +0000 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2022-11-06 18:29:40 +0000 |
| commit | ef475b14d08542378dc3f165515f9182552984ef (patch) | |
| tree | f090477be532108cca20582cfa8baee9b2db6f4a /app | |
| parent | f934075922fa819544d437a7c258b0c884f11178 (diff) | |
| download | webtrees-ef475b14d08542378dc3f165515f9182552984ef.tar.gz webtrees-ef475b14d08542378dc3f165515f9182552984ef.tar.bz2 webtrees-ef475b14d08542378dc3f165515f9182552984ef.zip | |
Strict types
Diffstat (limited to 'app')
32 files changed, 137 insertions, 124 deletions
diff --git a/app/GedcomRecord.php b/app/GedcomRecord.php index 8c21b44989..da8b3ba417 100644 --- a/app/GedcomRecord.php +++ b/app/GedcomRecord.php @@ -956,7 +956,7 @@ class GedcomRecord } elseif (preg_match_all('/\n(\d) ' . Gedcom::REGEX_TAG . ' ' . $value . '/', $fact->gedcom(), $matches, PREG_SET_ORDER)) { $gedcom = $fact->gedcom(); foreach ($matches as $match) { - $next_level = $match[1] + 1; + $next_level = 1 + (int) $match[1]; $next_levels = '[' . $next_level . '-9]'; $gedcom = preg_replace('/' . $match[0] . '(\n' . $next_levels . '.*)*/', '', $gedcom); } diff --git a/app/Individual.php b/app/Individual.php index 460102fbbc..8478f95b32 100644 --- a/app/Individual.php +++ b/app/Individual.php @@ -974,8 +974,8 @@ class Individual extends GedcomRecord //////////////////////////////////////////////////////////////////////////// $sublevel = 1 + (int) substr($gedcom, 0, 1); - $GIVN = preg_match('/\n' . $sublevel . ' GIVN (.+)/', $gedcom, $match) ? $match[1] : ''; - $SURN = preg_match('/\n' . $sublevel . ' SURN (.+)/', $gedcom, $match) ? $match[1] : ''; + $GIVN = preg_match('/\n' . $sublevel . ' GIVN (.+)/', $gedcom, $match) === 1 ? $match[1] : ''; + $SURN = preg_match('/\n' . $sublevel . ' SURN (.+)/', $gedcom, $match) === 1 ? $match[1] : ''; // SURN is an comma-separated list of surnames... if ($SURN !== '') { diff --git a/app/Services/GedcomImportService.php b/app/Services/GedcomImportService.php index b45b4f2c18..e0f07fb2a0 100644 --- a/app/Services/GedcomImportService.php +++ b/app/Services/GedcomImportService.php @@ -157,12 +157,18 @@ class GedcomImportService // Consistent commas $data = preg_replace('/ *[,,،] */u', ', ', $data); // The Master Genealogist stores LAT/LONG data in the PLAC field, e.g. Pennsylvania, USA, 395945N0751013W - if (preg_match('/(.*), (\d\d)(\d\d)(\d\d)([NS])(\d\d\d)(\d\d)(\d\d)([EW])$/', $data, $match)) { + if (preg_match('/(.*), (\d\d)(\d\d)(\d\d)([NS])(\d\d\d)(\d\d)(\d\d)([EW])$/', $data, $match) === 1) { + $degns = (int) $match[2]; + $minns = (int) $match[3]; + $secns = (int) $match[4]; + $degew = (int) $match[6]; + $minew = (int) $match[7]; + $secew = (int) $match[8]; $data = $match[1] . "\n" . - ($level + 1) . " MAP\n" . - ($level + 2) . ' LATI ' . ($match[5] . round($match[2] + ($match[3] / 60) + ($match[4] / 3600), 4)) . "\n" . - ($level + 2) . ' LONG ' . ($match[9] . round($match[6] + ($match[7] / 60) + ($match[8] / 3600), 4)); + (1 + (int) $level) . " MAP\n" . + (2 + (int) $level) . ' LATI ' . ($match[5] . round($degns + $minns / 60 + $secns / 3600, 4)) . "\n" . + (2 + (int) $level) . ' LONG ' . ($match[9] . round($degew + $minew / 60 + $secew / 3600, 4)); } break; case 'SEX': diff --git a/app/Services/RelationshipService.php b/app/Services/RelationshipService.php index c63bb9fb2f..97e9a789e5 100644 --- a/app/Services/RelationshipService.php +++ b/app/Services/RelationshipService.php @@ -333,9 +333,9 @@ class RelationshipService // The sex of the last person in the relationship determines the name in // many cases. e.g. great-aunt / great-uncle - if (preg_match('/(fat|hus|son|bro)$/', $path)) { + if (preg_match('/(fat|hus|son|bro)$/', $path) === 1) { $sex2 = 'M'; - } elseif (preg_match('/(mot|wif|dau|sis)$/', $path)) { + } elseif (preg_match('/(mot|wif|dau|sis)$/', $path) === 1) { $sex2 = 'F'; } else { $sex2 = 'U'; @@ -1198,116 +1198,116 @@ class RelationshipService } // Some “special case” level five relationships that have specific names in certain languages - if (preg_match('/^(mot|fat|par)fatbro(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)fatbro(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandfather’s brother’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatbro(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)fatbro(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandfather’s brother’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatbro(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)fatbro(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandfather’s brother’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatsis(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)fatsis(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandfather’s sister’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatsis(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)fatsis(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandfather’s sister’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatsis(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)fatsis(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandfather’s sister’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatsib(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)fatsib(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandfather’s sibling’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatsib(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)fatsib(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandfather’s sibling’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)fatsib(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)fatsib(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandfather’s sibling’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motbro(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)motbro(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandmother’s brother’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motbro(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)motbro(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandmother’s brother’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motbro(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)motbro(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandmother’s brother’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motsis(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)motsis(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandmother’s sister’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motsis(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)motsis(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandmother’s sister’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motsis(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)motsis(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandmother’s sister’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motsib(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)motsib(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandmother’s sibling’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motsib(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)motsib(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandmother’s sibling’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)motsib(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)motsib(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandmother’s sibling’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parbro(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)parbro(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandparent’s brother’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parbro(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)parbro(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandparent’s brother’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parbro(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)parbro(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandparent’s brother’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parsis(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)parsis(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandparent’s sister’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parsis(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)parsis(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandparent’s sister’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parsis(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)parsis(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandparent’s sister’s grandchild', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parsib(son|dau|chi)dau$/', $path)) { + if (preg_match('/^(mot|fat|par)parsib(son|dau|chi)dau$/', $path) === 1) { return I18N::translateContext('grandparent’s sibling’s granddaughter', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parsib(son|dau|chi)son$/', $path)) { + if (preg_match('/^(mot|fat|par)parsib(son|dau|chi)son$/', $path) === 1) { return I18N::translateContext('grandparent’s sibling’s grandson', 'second cousin'); } - if (preg_match('/^(mot|fat|par)parsib(son|dau|chi)chi$/', $path)) { + if (preg_match('/^(mot|fat|par)parsib(son|dau|chi)chi$/', $path) === 1) { return I18N::translateContext('grandparent’s sibling’s grandchild', 'second cousin'); } // Look for generic/pattern relationships. - if (preg_match('/^((?:mot|fat|par)+)(bro|sis|sib)$/', $path, $match)) { + if (preg_match('/^((?:mot|fat|par)+)(bro|sis|sib)$/', $path, $match) === 1) { // siblings of direct ancestors $up = intdiv(strlen($match[1]), 3); $bef_last = substr($path, -6, 3); @@ -1515,7 +1515,7 @@ class RelationshipService } } } - if (preg_match('/^(?:bro|sis|sib)((?:son|dau|chi)+)$/', $path, $match)) { + if (preg_match('/^(?:bro|sis|sib)((?:son|dau|chi)+)$/', $path, $match) === 1) { // direct descendants of siblings $down = intdiv(strlen($match[1]), 3) + 1; // Add one, as we count generations from the common ancestor $first = substr($path, 0, 3); @@ -1808,7 +1808,7 @@ class RelationshipService } } } - if (preg_match('/^((?:mot|fat|par)*)$/', $path, $match)) { + if (preg_match('/^((?:mot|fat|par)*)$/', $path, $match) === 1) { // direct ancestors $up = intdiv(strlen($match[1]), 3); switch ($up) { @@ -1965,7 +1965,7 @@ class RelationshipService } } } - if (preg_match('/^((?:son|dau|chi)*)$/', $path, $match)) { + if (preg_match('/^((?:son|dau|chi)*)$/', $path, $match) === 1) { // direct descendants $up = intdiv(strlen($match[1]), 3); switch ($up) { @@ -2099,7 +2099,7 @@ class RelationshipService } } } - if (preg_match('/^((?:mot|fat|par)+)(?:bro|sis|sib)((?:son|dau|chi)+)$/', $path, $match)) { + if (preg_match('/^((?:mot|fat|par)+)(?:bro|sis|sib)((?:son|dau|chi)+)$/', $path, $match) === 1) { // cousins in English $ascent = $match[1]; $descent = $match[2]; diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php index de30265d79..d4fb041613 100644 --- a/app/Services/SearchService.php +++ b/app/Services/SearchService.php @@ -516,7 +516,7 @@ class SearchService */ public function searchIndividualsAdvanced(array $trees, array $fields, array $modifiers): Collection { - $fields = array_filter($fields); + $fields = array_filter($fields, static fn (string $x): bool => $x !== ''); $query = DB::table('individuals') ->select(['individuals.*']) @@ -535,28 +535,26 @@ class SearchService $fam_plac = false; foreach ($fields as $field_name => $field_value) { - if ($field_value !== '') { - if (str_starts_with($field_name, 'FATHER:NAME')) { - $father_name = true; - } elseif (str_starts_with($field_name, 'MOTHER:NAME')) { - $mother_name = true; - } elseif (str_starts_with($field_name, 'INDI:NAME:GIVN')) { - $indi_name = true; - } elseif (str_starts_with($field_name, 'INDI:NAME:SURN')) { - $indi_name = true; - } elseif (str_starts_with($field_name, 'FAM:')) { - $spouse_family = true; - if (str_ends_with($field_name, ':DATE')) { - $fam_dates[] = explode(':', $field_name)[1]; - } elseif (str_ends_with($field_name, ':PLAC')) { - $fam_plac = true; - } - } elseif (str_starts_with($field_name, 'INDI:')) { - if (str_ends_with($field_name, ':DATE')) { - $indi_dates[] = explode(':', $field_name)[1]; - } elseif (str_ends_with($field_name, ':PLAC')) { - $indi_plac = true; - } + if (str_starts_with($field_name, 'FATHER:NAME')) { + $father_name = true; + } elseif (str_starts_with($field_name, 'MOTHER:NAME')) { + $mother_name = true; + } elseif (str_starts_with($field_name, 'INDI:NAME:GIVN')) { + $indi_name = true; + } elseif (str_starts_with($field_name, 'INDI:NAME:SURN')) { + $indi_name = true; + } elseif (str_starts_with($field_name, 'FAM:')) { + $spouse_family = true; + if (str_ends_with($field_name, ':DATE')) { + $fam_dates[] = explode(':', $field_name)[1]; + } elseif (str_ends_with($field_name, ':PLAC')) { + $fam_plac = true; + } + } elseif (str_starts_with($field_name, 'INDI:')) { + if (str_ends_with($field_name, ':DATE')) { + $indi_dates[] = explode(':', $field_name)[1]; + } elseif (str_ends_with($field_name, ':PLAC')) { + $indi_plac = true; } } } @@ -882,7 +880,7 @@ class SearchService if (str_starts_with($field_name, 'INDI:NAME:') && $field_name !== 'INDI:NAME:GIVN' && $field_name !== 'INDI:NAME:SURN') { $regex = '/\n1 NAME.*(?:\n2.*)*\n2 ' . $parts[2] . ' .*' . preg_quote($field_value, '/') . '/i'; - if (preg_match($regex, $individual->gedcom())) { + if (preg_match($regex, $individual->gedcom()) === 1) { continue; } @@ -893,7 +891,7 @@ class SearchService if (str_starts_with($field_name, 'INDI:') && str_ends_with($field_name, ':PLAC')) { foreach ($individual->facts([$parts[1]]) as $fact) { - if (preg_match($regex, $fact->place()->gedcomName())) { + if (preg_match($regex, $fact->place()->gedcomName()) === 1) { continue 2; } } @@ -903,7 +901,7 @@ class SearchService if (str_starts_with($field_name, 'FAM:') && str_ends_with($field_name, ':PLAC')) { foreach ($individual->spouseFamilies() as $family) { foreach ($family->facts([$parts[1]]) as $fact) { - if (preg_match($regex, $fact->place()->gedcomName())) { + if (preg_match($regex, $fact->place()->gedcomName()) === 1) { continue 3; } } @@ -913,7 +911,7 @@ class SearchService if ($field_name === 'INDI:FACT:TYPE' || $field_name === 'INDI:EVEN:TYPE' || $field_name === 'INDI:CHAN:_WT_USER') { foreach ($individual->facts([$parts[1]]) as $fact) { - if (preg_match($regex, $fact->attribute($parts[2]))) { + if (preg_match($regex, $fact->attribute($parts[2])) === 1) { continue 2; } } @@ -923,7 +921,7 @@ class SearchService if (str_starts_with($field_name, 'INDI:')) { foreach ($individual->facts([$parts[1]]) as $fact) { - if (preg_match($regex, $fact->value())) { + if (preg_match($regex, $fact->value()) === 1) { continue 2; } } @@ -934,7 +932,7 @@ class SearchService if (str_starts_with($field_name, 'FAM:')) { foreach ($individual->spouseFamilies() as $family) { foreach ($family->facts([$parts[1]]) as $fact) { - if (preg_match($regex, $fact->value())) { + if (preg_match($regex, $fact->value()) === 1) { continue 3; } } diff --git a/app/Soundex.php b/app/Soundex.php index 7c92f5d2bb..5835c14f95 100644 --- a/app/Soundex.php +++ b/app/Soundex.php @@ -712,7 +712,7 @@ class Soundex // Loop through the input string. // Stop when the string is exhausted or when no more partial results remain - while (count($partialResult) !== 0 && $currPos <= $lastPos) { + while ($partialResult !== [] && $currPos <= $lastPos) { // Find the DM coding table entry for the chunk at the current position $thisEntry = substr($name, $currPos, self::MAXCHAR); // Get maximum length chunk while ($thisEntry !== '') { @@ -781,7 +781,7 @@ class Soundex // We're looking for 7 entries because the first is '!' and doesn't count $tempResult = str_replace('!', '', implode('', $workingEntry)); // Only return codes from recognisable sounds - if ($tempResult) { + if ($tempResult !== '') { $result[] = substr($tempResult . '000000', 0, 6); } } @@ -795,7 +795,7 @@ class Soundex foreach ($partialResult as $workingEntry) { $tempResult = str_replace('!', '', implode('', $workingEntry)); // Only return codes from recognisable sounds - if ($tempResult) { + if ($tempResult !== '') { $result[] = substr($tempResult . '000000', 0, 6); } } diff --git a/app/Source.php b/app/Source.php index 81ea5f9843..a8293d5274 100644 --- a/app/Source.php +++ b/app/Source.php @@ -44,7 +44,7 @@ class Source extends GedcomRecord preg_match_all('/\n1 REPO @(.+)@/', $this->gedcom, $matches); foreach ($matches[1] as $match) { $repo = Registry::repositoryFactory()->make($match, $this->tree); - if ($repo && !$repo->canShow($access_level)) { + if ($repo instanceof Repository && !$repo->canShow($access_level)) { return false; } } diff --git a/app/Statistics/Google/ChartFamilyLargest.php b/app/Statistics/Google/ChartFamilyLargest.php index b8e48206fc..b89c8ab563 100644 --- a/app/Statistics/Google/ChartFamilyLargest.php +++ b/app/Statistics/Google/ChartFamilyLargest.php @@ -19,6 +19,7 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Statistics\Google; +use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Statistics\Service\ColorService; @@ -94,7 +95,7 @@ class ChartFamilyLargest foreach ($this->queryRecords($total) as $record) { $family = Registry::familyFactory()->make($record->id, $this->tree); - if ($family && $family->canShow()) { + if ($family instanceof Family && $family->canShow()) { $data[] = [ htmlspecialchars_decode(strip_tags($family->fullName())), $record->total diff --git a/app/Statistics/Google/ChartFamilyWithSources.php b/app/Statistics/Google/ChartFamilyWithSources.php index 514dda4457..6114264b0f 100644 --- a/app/Statistics/Google/ChartFamilyWithSources.php +++ b/app/Statistics/Google/ChartFamilyWithSources.php @@ -66,7 +66,7 @@ class ChartFamilyWithSources ], ]; - if ($tot_fam || $tot_fam_source) { + if ($tot_fam > 0 || $tot_fam_source > 0) { $data[] = [ I18N::translate('Without sources'), $tot_fam - $tot_fam_source diff --git a/app/Statistics/Google/ChartIndividualWithSources.php b/app/Statistics/Google/ChartIndividualWithSources.php index 1e2815b99a..114bba0b62 100644 --- a/app/Statistics/Google/ChartIndividualWithSources.php +++ b/app/Statistics/Google/ChartIndividualWithSources.php @@ -66,7 +66,7 @@ class ChartIndividualWithSources ], ]; - if ($tot_indi || $tot_indi_source) { + if ($tot_indi > 0 || $tot_indi_source > 0) { $data[] = [ I18N::translate('Without sources'), $tot_indi - $tot_indi_source diff --git a/app/Statistics/Google/ChartMortality.php b/app/Statistics/Google/ChartMortality.php index c997fbcff6..3cfeca5b48 100644 --- a/app/Statistics/Google/ChartMortality.php +++ b/app/Statistics/Google/ChartMortality.php @@ -66,7 +66,7 @@ class ChartMortality ] ]; - if ($tot_l || $tot_d) { + if ($tot_l > 0 || $tot_d > 0) { $data[] = [ I18N::translate('Living'), $tot_l diff --git a/app/Statistics/Google/ChartNoChildrenFamilies.php b/app/Statistics/Google/ChartNoChildrenFamilies.php index 305a967b2f..7e848aa096 100644 --- a/app/Statistics/Google/ChartNoChildrenFamilies.php +++ b/app/Statistics/Google/ChartNoChildrenFamilies.php @@ -109,7 +109,7 @@ class ChartNoChildrenFamilies ]; } - if ($total) { + if ($total > 0) { $data[] = [ I18N::translateContext('unknown century', 'Unknown'), $no_child_fam - $total, diff --git a/app/Statistics/Google/ChartSex.php b/app/Statistics/Google/ChartSex.php index abff9e7b4f..a34a680593 100644 --- a/app/Statistics/Google/ChartSex.php +++ b/app/Statistics/Google/ChartSex.php @@ -57,7 +57,7 @@ class ChartSex ], ]; - if ($tot_m || $tot_f || $tot_u) { + if ($tot_m > 0 || $tot_f > 0 || $tot_u > 0) { $data[] = [ I18N::translate('Males'), $tot_m diff --git a/app/Statistics/Repository/EventRepository.php b/app/Statistics/Repository/EventRepository.php index ebbc4cac3e..b0a59fed7d 100644 --- a/app/Statistics/Repository/EventRepository.php +++ b/app/Statistics/Repository/EventRepository.php @@ -24,6 +24,7 @@ use Fisharebest\Webtrees\Elements\UnknownElement; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\Gedcom; +use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\Header; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; @@ -243,10 +244,10 @@ class EventRepository implements EventRepositoryInterface $row = $this->eventQuery($direction); $result = I18N::translate('This information is not available.'); - if ($row) { + if ($row !== null) { $record = Registry::gedcomRecordFactory()->make($row->id, $this->tree); - if ($record && $record->canShow()) { + if ($record instanceof GedcomRecord && $record->canShow()) { $result = $record->formatList(); } else { $result = I18N::translate('This information is private and cannot be shown.'); @@ -283,7 +284,7 @@ class EventRepository implements EventRepositoryInterface { $row = $this->eventQuery($direction); - if (!$row) { + if ($row === null) { return ''; } @@ -360,10 +361,10 @@ class EventRepository implements EventRepositoryInterface { $row = $this->eventQuery($direction); - if ($row) { + if ($row !== null) { $record = Registry::gedcomRecordFactory()->make($row->id, $this->tree); - if ($record) { + if ($record instanceof GedcomRecord) { return '<a href="' . e($record->url()) . '">' . $record->fullName() . '</a>'; } } @@ -398,11 +399,11 @@ class EventRepository implements EventRepositoryInterface { $row = $this->eventQuery($direction); - if ($row) { + if ($row !== null) { $record = Registry::gedcomRecordFactory()->make($row->id, $this->tree); $fact = null; - if ($record) { + if ($record instanceof GedcomRecord) { $fact = $record->facts([$row->fact])->first(); } diff --git a/app/Statistics/Repository/FamilyDatesRepository.php b/app/Statistics/Repository/FamilyDatesRepository.php index 462a683040..fe69e8b58d 100644 --- a/app/Statistics/Repository/FamilyDatesRepository.php +++ b/app/Statistics/Repository/FamilyDatesRepository.php @@ -21,6 +21,7 @@ namespace Fisharebest\Webtrees\Statistics\Repository; use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Fact; +use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Statistics\Repository\Interfaces\FamilyDatesRepositoryInterface; @@ -97,10 +98,10 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface $row = $this->eventQuery($type, $operation); $result = I18N::translate('This information is not available.'); - if ($row) { + if ($row !== null) { $record = Registry::gedcomRecordFactory()->make($row->id, $this->tree); - if ($record && $record->canShow()) { + if ($record instanceof GedcomRecord && $record->canShow()) { $result = $record->formatList(); } else { $result = I18N::translate('This information is private and cannot be shown.'); @@ -186,7 +187,7 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface { $row = $this->eventQuery($type, $operation); - if (!$row) { + if ($row === null) { return ''; } @@ -274,10 +275,10 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface { $row = $this->eventQuery($type, $operation); - if ($row) { + if ($row !== null) { $record = Registry::gedcomRecordFactory()->make($row->id, $this->tree); - if ($record) { + if ($record instanceof GedcomRecord) { return '<a href="' . e($record->url()) . '">' . $record->fullName() . '</a>'; } } @@ -361,11 +362,11 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface { $row = $this->eventQuery($type, $operation); - if ($row) { + if ($row != null) { $record = Registry::gedcomRecordFactory()->make($row->id, $this->tree); $fact = null; - if ($record) { + if ($record instanceof GedcomRecord) { $fact = $record->facts([$row->fact])->first(); } diff --git a/app/Statistics/Repository/FamilyRepository.php b/app/Statistics/Repository/FamilyRepository.php index 7b88261e04..7a6d397b10 100644 --- a/app/Statistics/Repository/FamilyRepository.php +++ b/app/Statistics/Repository/FamilyRepository.php @@ -1128,7 +1128,12 @@ class FamilyRepository $husb = $family->husband(); $wife = $family->wife(); - if ($husb && ($husb->getAllDeathDates() || !$husb->isDead()) && $wife && ($wife->getAllDeathDates() || !$wife->isDead())) { + if ( + $husb instanceof Individual && + $wife instanceof Individual && + ($husb->getAllDeathDates() || !$husb->isDead()) && + ($wife->getAllDeathDates() || !$wife->isDead()) + ) { if ($family->canShow()) { if ($type === 'list') { $top10[] = '<li><a href="' . e($family->url()) . '">' . $family->fullName() . '</a> (' . $age . ')' . '</li>'; diff --git a/app/Statistics/Repository/HitCountRepository.php b/app/Statistics/Repository/HitCountRepository.php index 1075659e47..656a44b025 100644 --- a/app/Statistics/Repository/HitCountRepository.php +++ b/app/Statistics/Repository/HitCountRepository.php @@ -20,6 +20,7 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Statistics\Repository; use Fisharebest\Webtrees\Auth; +use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\Services\UserService; use Fisharebest\Webtrees\Statistics\Repository\Interfaces\HitCountRepositoryInterface; use Fisharebest\Webtrees\Tree; @@ -63,7 +64,7 @@ class HitCountRepository implements HitCountRepositoryInterface } elseif ($page_name === 'index.php') { // index.php?context=user $user = $this->user_service->findByIdentifier($page_parameter); - $page_parameter = 'user:' . ($user ? $user->id() : Auth::id()); + $page_parameter = 'user:' . ($user instanceof UserInterface ? $user->id() : Auth::id()); } $count = (int) DB::table('hit_counter') diff --git a/app/Statistics/Repository/IndividualRepository.php b/app/Statistics/Repository/IndividualRepository.php index 9224110cba..73989656c6 100644 --- a/app/Statistics/Repository/IndividualRepository.php +++ b/app/Statistics/Repository/IndividualRepository.php @@ -135,7 +135,7 @@ class IndividualRepository implements IndividualRepositoryInterface // Split “John Thomas” into “John” and “Thomas” and count against both totals foreach (explode(' ', (string) $n_givn) as $given) { // Exclude initials and particles. - if (!preg_match('/^([A-Z]|[a-z]{1,3})$/', $given)) { + if (preg_match('/^([A-Z]|[a-z]{1,3})$/', $given) !== 1) { if (array_key_exists($given, $nameList)) { $nameList[$given] += (int) $count; } else { diff --git a/app/Statistics/Repository/LatestUserRepository.php b/app/Statistics/Repository/LatestUserRepository.php index 622adb9541..a3663e74ad 100644 --- a/app/Statistics/Repository/LatestUserRepository.php +++ b/app/Statistics/Repository/LatestUserRepository.php @@ -151,6 +151,6 @@ class LatestUserRepository implements LatestUserRepositoryInterface ->where('user_id', '=', $user->id()) ->first(); - return $is_logged_in ? $yes : $no; + return $is_logged_in !== null ? $yes : $no; } } diff --git a/app/Statistics/Repository/PlaceRepository.php b/app/Statistics/Repository/PlaceRepository.php index 2c108fbd77..ef1917771b 100644 --- a/app/Statistics/Repository/PlaceRepository.php +++ b/app/Statistics/Repository/PlaceRepository.php @@ -91,7 +91,7 @@ class PlaceRepository implements PlaceRepositoryInterface $placelist = []; foreach ($rows as $row) { - if (preg_match('/\n1 ' . $fact . '(?:\n[2-9].*)*\n2 PLAC (.+)/', $row->tree, $match)) { + if (preg_match('/\n1 ' . $fact . '(?:\n[2-9].*)*\n2 PLAC (.+)/', $row->tree, $match) === 1) { $place = $match[1]; $placelist[$place] = ($placelist[$place] ?? 0) + 1; diff --git a/app/Statistics/Repository/UserRepository.php b/app/Statistics/Repository/UserRepository.php index ba41ff5688..9a3439a08f 100644 --- a/app/Statistics/Repository/UserRepository.php +++ b/app/Statistics/Repository/UserRepository.php @@ -86,7 +86,7 @@ class UserRepository implements UserRepositoryInterface } if ($count_logged_in > 0) { - if ($anonymous) { + if ($anonymous !== 0) { if ($type === 'list') { $content .= '<br><br>'; } else { diff --git a/app/Statistics/Service/ColorService.php b/app/Statistics/Service/ColorService.php index 0dc3d84c82..4cb4b22eeb 100644 --- a/app/Statistics/Service/ColorService.php +++ b/app/Statistics/Service/ColorService.php @@ -41,7 +41,7 @@ class ColorService */ public function interpolateRgb(string $startColor, string $endColor, int $steps): array { - if (!$steps) { + if ($steps === 0) { return []; } diff --git a/app/SurnameTradition/IcelandicSurnameTradition.php b/app/SurnameTradition/IcelandicSurnameTradition.php index b5ba309039..a371d9149c 100644 --- a/app/SurnameTradition/IcelandicSurnameTradition.php +++ b/app/SurnameTradition/IcelandicSurnameTradition.php @@ -73,7 +73,7 @@ class IcelandicSurnameTradition extends DefaultSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match)) { + if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match) === 1) { switch ($sex) { case 'M': $givn = $match['GIVN'] . 'sson'; @@ -106,13 +106,13 @@ class IcelandicSurnameTradition extends DefaultSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match)) { + if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match) === 1) { return [ $this->buildName($match['GIVN'], ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $match['GIVN']]), ]; } - if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match)) { + if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match) === 1) { return [ $this->buildName($match['GIVN'], ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $match['GIVN']]), ]; diff --git a/app/SurnameTradition/LithuanianSurnameTradition.php b/app/SurnameTradition/LithuanianSurnameTradition.php index ed1afa2e6a..9adbce8e73 100644 --- a/app/SurnameTradition/LithuanianSurnameTradition.php +++ b/app/SurnameTradition/LithuanianSurnameTradition.php @@ -89,7 +89,7 @@ class LithuanianSurnameTradition extends PaternalSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) { + if (preg_match(self::REGEX_SURN, $this->extractName($father), $match) === 1) { if ($sex === 'F') { $name = $this->inflect($match['NAME'], self::INFLECT_DAUGHTER); $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); @@ -118,7 +118,7 @@ class LithuanianSurnameTradition extends PaternalSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) { + if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match) === 1) { $name = $this->inflect($match['NAME'], self::INFLECT_MALE); $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); @@ -142,7 +142,7 @@ class LithuanianSurnameTradition extends PaternalSurnameTradition */ public function newSpouseNames(Individual $spouse, string $sex): array { - if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match) === 1) { $name = $this->inflect($match['NAME'], self::INFLECT_WIFE); $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); diff --git a/app/SurnameTradition/MatrilinealSurnameTradition.php b/app/SurnameTradition/MatrilinealSurnameTradition.php index 3b3560f6a6..c73fd647e6 100644 --- a/app/SurnameTradition/MatrilinealSurnameTradition.php +++ b/app/SurnameTradition/MatrilinealSurnameTradition.php @@ -61,7 +61,7 @@ class MatrilinealSurnameTradition extends DefaultSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($mother), $match)) { + if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($mother), $match) === 1) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; @@ -84,7 +84,7 @@ class MatrilinealSurnameTradition extends DefaultSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match) === 1) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; diff --git a/app/SurnameTradition/PaternalSurnameTradition.php b/app/SurnameTradition/PaternalSurnameTradition.php index 22896ff385..51a459fa35 100644 --- a/app/SurnameTradition/PaternalSurnameTradition.php +++ b/app/SurnameTradition/PaternalSurnameTradition.php @@ -61,7 +61,7 @@ class PaternalSurnameTradition extends PatrilinealSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match) === 1) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; @@ -85,7 +85,7 @@ class PaternalSurnameTradition extends PatrilinealSurnameTradition */ public function newSpouseNames(Individual $spouse, string $sex): array { - if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($spouse), $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($spouse), $match) === 1) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; diff --git a/app/SurnameTradition/PatrilinealSurnameTradition.php b/app/SurnameTradition/PatrilinealSurnameTradition.php index 098f05de3a..fa1c7ce49e 100644 --- a/app/SurnameTradition/PatrilinealSurnameTradition.php +++ b/app/SurnameTradition/PatrilinealSurnameTradition.php @@ -61,7 +61,7 @@ class PatrilinealSurnameTradition extends DefaultSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($father), $match)) { + if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($father), $match) === 1) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; @@ -84,7 +84,7 @@ class PatrilinealSurnameTradition extends DefaultSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if ($sex === 'M' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) { + if ($sex === 'M' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match) === 1) { $name = $match['NAME']; $spfx = $match['SPFX']; $surn = $match['SURN']; diff --git a/app/SurnameTradition/PolishSurnameTradition.php b/app/SurnameTradition/PolishSurnameTradition.php index 05be7a6c74..7ebc96ee3d 100644 --- a/app/SurnameTradition/PolishSurnameTradition.php +++ b/app/SurnameTradition/PolishSurnameTradition.php @@ -79,7 +79,7 @@ class PolishSurnameTradition extends PaternalSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) { + if (preg_match(self::REGEX_SURN, $this->extractName($father), $match) === 1) { if ($sex === 'F') { $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); } else { @@ -104,7 +104,7 @@ class PolishSurnameTradition extends PaternalSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) { + if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match) === 1) { $name = $this->inflect($match['NAME'], self::INFLECT_MALE); $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); @@ -126,7 +126,7 @@ class PolishSurnameTradition extends PaternalSurnameTradition */ public function newSpouseNames(Individual $spouse, string $sex): array { - if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) { + if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match) === 1) { $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); diff --git a/app/SurnameTradition/PortugueseSurnameTradition.php b/app/SurnameTradition/PortugueseSurnameTradition.php index 937d4d5ea9..bb962d1a69 100644 --- a/app/SurnameTradition/PortugueseSurnameTradition.php +++ b/app/SurnameTradition/PortugueseSurnameTradition.php @@ -74,13 +74,13 @@ class PortugueseSurnameTradition extends DefaultSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father) === 1) { $father_surname = $match_father['SURN2']; } else { $father_surname = ''; } - if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother) === 1) { $mother_surname = $match_mother['SURN2']; } else { $mother_surname = ''; @@ -104,7 +104,7 @@ class PortugueseSurnameTradition extends DefaultSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match) === 1) { switch ($sex) { case 'M': return [ diff --git a/app/SurnameTradition/SpanishSurnameTradition.php b/app/SurnameTradition/SpanishSurnameTradition.php index 6318f09307..ddb1163cc9 100644 --- a/app/SurnameTradition/SpanishSurnameTradition.php +++ b/app/SurnameTradition/SpanishSurnameTradition.php @@ -74,13 +74,13 @@ class SpanishSurnameTradition extends DefaultSurnameTradition */ public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array { - if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father) === 1) { $father_surname = $match_father['SURN1']; } else { $father_surname = ''; } - if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother) === 1) { $mother_surname = $match_mother['SURN1']; } else { $mother_surname = ''; @@ -104,7 +104,7 @@ class SpanishSurnameTradition extends DefaultSurnameTradition */ public function newParentNames(Individual $child, string $sex): array { - if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { + if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match) === 1) { switch ($sex) { case 'M': return [ diff --git a/app/Tree.php b/app/Tree.php index 9026e2a941..cc85f53f38 100644 --- a/app/Tree.php +++ b/app/Tree.php @@ -362,7 +362,7 @@ class Tree */ public function createRecord(string $gedcom): GedcomRecord { - if (!preg_match('/^0 @@ ([_A-Z]+)/', $gedcom, $match)) { + if (preg_match('/^0 @@ ([_A-Z]+)/', $gedcom, $match) !== 1) { throw new InvalidArgumentException('GedcomRecord::createRecord(' . $gedcom . ') does not begin 0 @@'); } diff --git a/app/Validator.php b/app/Validator.php index 85ac46cc55..ab1a1438b2 100644 --- a/app/Validator.php +++ b/app/Validator.php @@ -257,7 +257,7 @@ class Validator $value ??= []; $check_utf8 = static function ($v, $k) use ($parameter) { - if (is_string($k) && !preg_match('//u', $k) || is_string($v) && !preg_match('//u', $v)) { + if (is_string($k) && preg_match('//u', $k) !== 1 || is_string($v) && preg_match('//u', $v) !== 1) { throw new HttpBadRequestException(I18N::translate('The parameter “%s” is missing.', $parameter)); } }; |
