diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2023-06-27 22:06:17 +0100 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2023-06-27 22:14:11 +0100 |
| commit | 2cd72788e6dec614793bbb2b319ea5a74dff28a7 (patch) | |
| tree | 4c8a5cc9be18133bef1cc9d61011f1e96859a467 | |
| parent | 1db8f5a0ed4e2f14f98b6e19cc538cbabf6319fe (diff) | |
| download | webtrees-2cd72788e6dec614793bbb2b319ea5a74dff28a7.tar.gz webtrees-2cd72788e6dec614793bbb2b319ea5a74dff28a7.tar.bz2 webtrees-2cd72788e6dec614793bbb2b319ea5a74dff28a7.zip | |
Fix: events BC break statistics
| -rw-r--r-- | app/Statistics/Repository/EventRepository.php | 15 | ||||
| -rw-r--r-- | app/Statistics/Repository/FamilyDatesRepository.php | 10 | ||||
| -rw-r--r-- | phpstan-baseline.php | 30 |
3 files changed, 53 insertions, 2 deletions
diff --git a/app/Statistics/Repository/EventRepository.php b/app/Statistics/Repository/EventRepository.php index bb14f8695e..ac77cc4e5a 100644 --- a/app/Statistics/Repository/EventRepository.php +++ b/app/Statistics/Repository/EventRepository.php @@ -33,6 +33,7 @@ use Fisharebest\Webtrees\Statistics\Repository\Interfaces\EventRepositoryInterfa use Fisharebest\Webtrees\Tree; use Illuminate\Database\Capsule\Manager as DB; +use function abs; use function array_map; use function array_merge; use function e; @@ -217,7 +218,7 @@ class EventRepository implements EventRepositoryInterface * * @param string $direction The sorting direction of the query (To return first or last record) * - * @return object|null + * @return object{id:string,year:int,fact:string,type:string}|null */ private function eventQuery(string $direction): ?object { @@ -229,6 +230,14 @@ class EventRepository implements EventRepositoryInterface ->where('d_julianday1', '<>', 0) ->orderBy('d_julianday1', $direction) ->orderBy('d_type') + ->limit(1) + ->get() + ->map(static fn (object $row): object => (object) [ + 'id' => $row->id, + 'year' => (int) $row->year, + 'fact' => $row->fact, + 'type' => $row->type, + ]) ->first(); } @@ -288,6 +297,10 @@ class EventRepository implements EventRepositoryInterface return ''; } + if ($row->year < 0) { + $row->year = abs($row->year) . ' B.C.'; + } + return (new Date($row->type . ' ' . $row->year)) ->display(); } diff --git a/app/Statistics/Repository/FamilyDatesRepository.php b/app/Statistics/Repository/FamilyDatesRepository.php index 4c6eb84241..c4691652a4 100644 --- a/app/Statistics/Repository/FamilyDatesRepository.php +++ b/app/Statistics/Repository/FamilyDatesRepository.php @@ -67,7 +67,7 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface * @param string $fact * @param string $operation * - * @return object|null + * @return object{id:string,year:int,fact:string,type:string}|null */ private function eventQuery(string $fact, string $operation): ?object { @@ -82,6 +82,14 @@ class FamilyDatesRepository implements FamilyDatesRepositoryInterface ->where('d_fact', '=', $fact) ->where('d_julianday1', '<>', 0); }) + ->limit(1) + ->get() + ->map(static fn (object $row): object => (object) [ + 'id' => $row->id, + 'year' => (int) $row->year, + 'fact' => $row->fact, + 'type' => $row->type, + ]) ->first(); } diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 70ad038038..6de0c2f289 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3694,6 +3694,36 @@ $ignoreErrors[] = [ 'path' => __DIR__ . '/app/Statistics/Repository/ContactRepository.php', ]; $ignoreErrors[] = [ + 'message' => '#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:map\\(\\) expects callable\\(mixed, int\\|string\\)\\: \\(object\\{id\\: mixed, year\\: int, fact\\: mixed, type\\: mixed\\}&stdClass\\), Closure\\(object\\)\\: \\(object\\{id\\: mixed, year\\: int, fact\\: mixed, type\\: mixed\\}&stdClass\\) given\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Statistics/Repository/EventRepository.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property object\\{id\\: string, year\\: int, fact\\: string, type\\: string\\}\\:\\:\\$year is not writable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Statistics/Repository/EventRepository.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Return type of call to method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:map\\(\\) contains unresolvable type\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Statistics/Repository/EventRepository.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:map\\(\\) expects callable\\(mixed, int\\|string\\)\\: \\(object\\{id\\: mixed, year\\: int, fact\\: mixed, type\\: mixed\\}&stdClass\\), Closure\\(object\\)\\: \\(object\\{id\\: mixed, year\\: int, fact\\: mixed, type\\: mixed\\}&stdClass\\) given\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Statistics/Repository/FamilyDatesRepository.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property object\\{id\\: string, year\\: int, fact\\: string, type\\: string\\}\\:\\:\\$year is not writable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Statistics/Repository/FamilyDatesRepository.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Return type of call to method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:map\\(\\) contains unresolvable type\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Statistics/Repository/FamilyDatesRepository.php', +]; +$ignoreErrors[] = [ 'message' => '#^Cannot access property \\$age on mixed\\.$#', 'count' => 9, 'path' => __DIR__ . '/app/Statistics/Repository/FamilyRepository.php', |
