Total Complexity | 8 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | final class Payload |
||
17 | { |
||
18 | /** @var array<mixed, mixed>|string */ |
||
19 | private $data; |
||
20 | |||
21 | /** |
||
22 | * @param array<mixed, mixed>|string $data |
||
23 | */ |
||
24 | 7 | public function __construct($data = null) |
|
25 | { |
||
26 | 7 | $this->data = $data; |
|
27 | 7 | } |
|
28 | |||
29 | 3 | public function dataInStringFormat(): ?string |
|
30 | { |
||
31 | 3 | if ($this->data === null) { |
|
32 | 1 | return null; |
|
33 | } |
||
34 | |||
35 | 2 | if (!\is_string($this->data)) { |
|
36 | 1 | throw new InvalidFormatException($this->dataType(), 'string'); |
|
37 | } |
||
38 | |||
39 | 1 | return $this->data; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @return array<mixed, mixed>|null |
||
44 | */ |
||
45 | 4 | public function dataInArrayFormat(): ?array |
|
56 | } |
||
57 | |||
58 | 5 | public function dataType(): string |
|
61 | } |
||
62 | } |
||
63 |