Total Complexity | 10 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 90.48% |
Changes | 0 |
1 | <?php |
||
9 | final class VisitsParams |
||
10 | { |
||
11 | /** @var null|DateRange */ |
||
12 | private $dateRange; |
||
13 | /** @var int */ |
||
14 | private $page = 1; |
||
15 | /** @var null|int */ |
||
16 | private $itemsPerPage; |
||
17 | |||
18 | 7 | public function __construct(?DateRange $dateRange = null, int $page = 1, ?int $itemsPerPage = null) |
|
19 | { |
||
20 | 7 | $this->dateRange = $dateRange ?? new DateRange(); |
|
21 | 7 | $this->page = $page; |
|
22 | 7 | $this->itemsPerPage = $itemsPerPage; |
|
23 | } |
||
24 | |||
25 | 3 | public static function fromRawData(array $query): self |
|
26 | { |
||
27 | 3 | $startDate = self::getDateQueryParam($query, 'startDate'); |
|
28 | 3 | $endDate = self::getDateQueryParam($query, 'endDate'); |
|
29 | |||
30 | 3 | return new self( |
|
31 | 3 | new DateRange($startDate, $endDate), |
|
32 | 3 | (int) ($query['page'] ?? 1), |
|
33 | 3 | isset($query['itemsPerPage']) ? (int) $query['itemsPerPage'] : null |
|
34 | ); |
||
35 | } |
||
36 | |||
37 | 3 | private static function getDateQueryParam(array $query, string $key): ?Chronos |
|
38 | { |
||
39 | 3 | return ! isset($query[$key]) || empty($query[$key]) ? null : Chronos::parse($query[$key]); |
|
40 | } |
||
41 | |||
42 | 1 | public function getDateRange(): DateRange |
|
45 | } |
||
46 | |||
47 | 1 | public function getPage(): int |
|
48 | { |
||
49 | 1 | return $this->page; |
|
50 | } |
||
51 | |||
52 | public function getItemsPerPage(): ?int |
||
53 | { |
||
54 | return $this->itemsPerPage; |
||
55 | } |
||
56 | |||
57 | 1 | public function hasItemsPerPage(): bool |
|
60 | } |
||
61 | } |
||
62 |