From d2ee80ebe78b69ae77734959ba7b81e3fbcfc4f0 Mon Sep 17 00:00:00 2001 From: Marco0300 Date: Tue, 1 Sep 2026 22:50:39 +0200 Subject: [PATCH] fix: harden report class loading and query parameters --- app/Domain/Reporting/ClientHistoryReport.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Domain/Reporting/ClientHistoryReport.php b/app/Domain/Reporting/ClientHistoryReport.php index 6014fa2..d809d9f 100644 --- a/app/Domain/Reporting/ClientHistoryReport.php +++ b/app/Domain/Reporting/ClientHistoryReport.php @@ -1,31 +1,36 @@ > $rows @return list> */ public function build(array $rows, string $audience = 'client'): array { ReportAudience::validate($audience); - $filters = $this->filters ?? new ReportFilters(); $mapper = $this->mapper ?? new ReportDataMapper(); $selected = []; + $filters = $this->filters ?? new ReportFilters(); + $mapper = $this->mapper ?? new ReportDataMapper(); + $selected = []; foreach ($rows as $row) if ($filters->matches($row)) $selected[] = $row; - usort($selected, static fn(array $a,array $b): int => strcmp((string)($a['changed_at'] ?? ''), (string)($b['changed_at'] ?? '')) ?: ((int)($a['id'] ?? $a['jobcard_id'] ?? 0) <=> (int)($b['id'] ?? $b['jobcard_id'] ?? 0)) ?: strcmp((string)($a['reference_no'] ?? ''), (string)($b['reference_no'] ?? ''))); + usort($selected, static fn(array $a, array $b): int => strcmp((string)($a['changed_at'] ?? ''), (string)($b['changed_at'] ?? '')) ?: ((int)($a['id'] ?? $a['jobcard_id'] ?? 0) <=> (int)($b['id'] ?? $b['jobcard_id'] ?? 0)) ?: strcmp((string)($a['reference_no'] ?? ''), (string)($b['reference_no'] ?? ''))); $result = []; foreach ($selected as $row) $result[] = $audience === ReportAudience::INTERNAL ? $mapper->internalHistory($row) : $mapper->clientHistory($row); return $result; } + public function query(array $rows, string $audience = 'client'): array { return $this->build($rows, $audience); } } }