-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDataRepositoryResponse.php
More file actions
44 lines (36 loc) · 940 Bytes
/
DataRepositoryResponse.php
File metadata and controls
44 lines (36 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace G4\DataRepository;
use G4\DataRepository\Exception\MissingResponseAllDataException;
use G4\DataRepository\Exception\MissingResponseOneDataException;
class DataRepositoryResponse
{
public function __construct(private readonly array $data, private $count, private $total)
{
}
public function count(): int
{
return $this->count;
}
public function getAll(): array
{
if (!$this->hasData() && $this->getTotal() === 0) {
throw new MissingResponseAllDataException();
}
return $this->data;
}
public function getOne(): mixed
{
if (!$this->hasData()) {
throw new MissingResponseOneDataException();
}
return current($this->data);
}
public function getTotal(): int
{
return $this->total;
}
public function hasData(): bool
{
return count($this->data) !== 0;
}
}