| Total Complexity | 8 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 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 | 9 | public function __construct($data = null) |
|
| 25 | { |
||
| 26 | 9 | $this->data = $data; |
|
| 27 | 9 | } |
|
| 28 | |||
| 29 | 3 | public function getStringData(): ?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->getDataType(), 'string'); |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | return $this->data; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return array<mixed, mixed>|null |
||
| 44 | */ |
||
| 45 | 4 | public function getArrayData(): ?array |
|
| 46 | { |
||
| 47 | 4 | if ($this->data === null) { |
|
| 48 | 1 | return null; |
|
| 49 | } |
||
| 50 | |||
| 51 | 3 | if (!\is_array($this->data)) { |
|
| 52 | 1 | throw new InvalidFormatException($this->getDataType(), 'array'); |
|
| 53 | } |
||
| 54 | |||
| 55 | 2 | return $this->data; |
|
| 56 | } |
||
| 57 | |||
| 58 | 5 | public function getDataType(): string |
|
| 61 | } |
||
| 62 | } |
||
| 63 |