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