| Total Complexity | 8 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | final class ScalarValues |
||
| 9 | { |
||
| 10 | /** @var array<string, scalar> */ |
||
| 11 | private $data; |
||
| 12 | |||
| 13 | /** @param array<string, scalar> $data */ |
||
| 14 | 139 | public function __construct(array $data) |
|
| 15 | { |
||
| 16 | 139 | $this->data = $data; |
|
| 17 | } |
||
| 18 | |||
| 19 | /** @return scalar|null */ |
||
| 20 | 139 | public function get(string $key) |
|
| 21 | { |
||
| 22 | 139 | return $this->data[$key] ?? null; |
|
| 23 | } |
||
| 24 | |||
| 25 | 139 | public function string(string $key): string |
|
| 26 | { |
||
| 27 | 139 | return (string) $this->get($key); |
|
| 28 | } |
||
| 29 | |||
| 30 | 112 | public function timestamp(string $key): int |
|
| 31 | { |
||
| 32 | 112 | $value = $this->string($key); |
|
| 33 | 112 | if ('' === $value) { |
|
| 34 | 95 | return 0; |
|
| 35 | } |
||
| 36 | 112 | return strtotime($value) ?: 0; |
|
| 37 | } |
||
| 38 | |||
| 39 | 24 | public function bool(string $key): bool |
|
| 40 | { |
||
| 41 | 24 | return (bool) $this->get($key); |
|
| 42 | } |
||
| 43 | |||
| 44 | 12 | public function int(string $key): int |
|
| 47 | } |
||
| 48 | } |
||
| 49 |