| Total Complexity | 8 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class ParseException extends RuntimeException |
||
| 17 | { |
||
| 18 | /** @var int */ |
||
| 19 | protected $code = 422; |
||
| 20 | |||
| 21 | public function __construct(string $file = '', ?Throwable $previous = null) |
||
| 22 | { |
||
| 23 | parent::__construct($this->formatMessage($file, $previous), previous: $previous); |
||
| 24 | } |
||
| 25 | |||
| 26 | protected function formatMessage(string $file, ?Throwable $previous): string |
||
| 27 | { |
||
| 28 | return rtrim(sprintf('Invalid %s in file%s %s', $this->getTypeLabel($file), $this->getFileLabel($file), $this->getContext($previous))); |
||
| 29 | } |
||
| 30 | |||
| 31 | protected function getTypeLabel(string $file): string |
||
| 32 | { |
||
| 33 | return match (Arr::last(explode('.', $file))) { |
||
| 34 | 'md' => 'Markdown', |
||
| 35 | 'yaml', 'yml' => 'Yaml', |
||
| 36 | 'json' => 'Json', |
||
| 37 | default => 'data', |
||
| 38 | }; |
||
| 39 | } |
||
| 40 | |||
| 41 | protected function getFileLabel(string $file): string |
||
| 44 | } |
||
| 45 | |||
| 46 | protected function getContext(?Throwable $previous): string |
||
| 49 | } |
||
| 50 | } |
||
| 51 |