| Total Complexity | 8 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class InvalidElementKeyException extends RuntimeException implements ExceptionInterface, PathAwareInterface |
||
| 16 | { |
||
| 17 | |||
| 18 | private $key; |
||
| 19 | |||
| 20 | private $path; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param mixed $key |
||
| 24 | * @param PathInterface $path |
||
| 25 | * @param Throwable|null $previous |
||
| 26 | */ |
||
| 27 | public function __construct($key, PathInterface $path, Throwable $previous = null) |
||
| 28 | { |
||
| 29 | $this->key = $key; |
||
| 30 | $this->path = $path; |
||
| 31 | parent::__construct($this->buildMessage(), 0, $previous); |
||
| 32 | } |
||
| 33 | |||
| 34 | private function buildMessage(): string |
||
| 35 | { |
||
| 36 | return "Invalid element key in decoded JSON: {$this->buildKey()} at {$this->buildPath()}"; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function getKey() |
||
| 40 | { |
||
| 41 | return $this->key; |
||
| 42 | } |
||
| 43 | |||
| 44 | public function getPath(): PathInterface |
||
| 47 | } |
||
| 48 | |||
| 49 | private function buildKey(): string |
||
| 50 | { |
||
| 51 | if (is_string($this->key)) { |
||
| 52 | return $this->key; |
||
| 53 | } |
||
| 54 | |||
| 55 | if (is_int($this->key)) { |
||
| 56 | return (string) $this->key; |
||
| 57 | } |
||
| 58 | |||
| 59 | $type = gettype($this->key); |
||
| 60 | |||
| 61 | return "<{$type}>"; |
||
| 62 | } |
||
| 63 | |||
| 64 | private function buildPath(): string |
||
| 67 | } |
||
| 68 | } |
||
| 69 |