Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ErrorLogFilterData
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
2 / 2
10
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
9
 getOffset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\ErrorLog\Data;
6
7use App\Support\Row;
8
9/**
10 * Data transfer object for error log filtering and pagination.
11 */
12final readonly class ErrorLogFilterData
13{
14    public int $page;
15
16    public int $limit;
17
18    public ?string $level;
19
20    public ?int $minLevelValue;
21
22    public ?int $userId;
23
24    public ?bool $resolved;
25
26    public ?string $startDate;
27
28    public ?string $endDate;
29
30    public ?string $search;
31
32    public string $sortBy;
33
34    public string $sortOrder;
35
36    /**
37     * @param array<mixed> $params Query parameters
38     */
39    public function __construct(array $params)
40    {
41        $this->page = max(1, Row::nullableInt($params, 'page') ?? 1);
42        $this->limit = max(1, min(100, Row::nullableInt($params, 'limit') ?? 25));
43
44        $level = Row::nullableString($params, 'level');
45        $this->level = $level === '' ? null : $level;
46
47        $this->minLevelValue = Row::nullableInt($params, 'minLevelValue');
48
49        $userId = Row::nullableString($params, 'userId');
50        $this->userId = ($userId === null || $userId === '') ? null : (int)$userId;
51
52        $resolved = $params['resolved'] ?? null;
53        $this->resolved = $resolved === null
54            ? null
55            : filter_var($resolved, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
56
57        $startDate = Row::nullableString($params, 'startDate');
58        $this->startDate = $startDate === '' ? null : $startDate;
59
60        $endDate = Row::nullableString($params, 'endDate');
61        $this->endDate = $endDate === '' ? null : $endDate;
62
63        $search = Row::nullableString($params, 'search');
64        $this->search = $search === '' ? null : $search;
65
66        $this->sortBy = Row::nullableString($params, 'sortBy') ?? 'createdAt';
67        $this->sortOrder = strtoupper(Row::nullableString($params, 'sortOrder') ?? 'DESC') === 'ASC' ? 'ASC' : 'DESC';
68    }
69
70    public function getOffset(): int
71    {
72        return ($this->page - 1) * $this->limit;
73    }
74}