Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
88.89% |
8 / 9 |
|
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ExceptionNormalizer | |
88.89% |
8 / 9 |
|
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
|
66.67% |
2 / 3 |
3.33 | |
0.00% |
0 / 1 |
| normalizeErrors | n/a |
0 / 0 |
n/a |
0 / 0 |
n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||||
| getStatus | n/a |
0 / 0 |
n/a |
0 / 0 |
n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||||
| getErrorCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| normalize | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Shared\Infrastructure\Normalizer; |
| 4 | |
| 5 | use App\Shared\Domain\Exception\ValidationException; |
| 6 | use Symfony\Component\Clock\ClockAwareTrait; |
| 7 | use Symfony\Component\HttpFoundation\Response; |
| 8 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
| 9 | |
| 10 | /** |
| 11 | * @author Wilhelm Zwertvaegher |
| 12 | */ |
| 13 | abstract class ExceptionNormalizer implements NormalizerInterface |
| 14 | { |
| 15 | use ClockAwareTrait; |
| 16 | |
| 17 | /** |
| 18 | * @param \Throwable $throwable |
| 19 | * @return array<string, array<string, string[]|int[]>> |
| 20 | */ |
| 21 | abstract protected function normalizeErrors(\Throwable $throwable): array; |
| 22 | |
| 23 | abstract protected function getStatus(\Throwable $throwable): int; |
| 24 | |
| 25 | protected function getErrorCode(\Throwable $throwable): string |
| 26 | { |
| 27 | return 'internal-error'; |
| 28 | } |
| 29 | |
| 30 | protected function getMessage(\Throwable $throwable): string |
| 31 | { |
| 32 | return $throwable->getMessage(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @throws \InvalidArgumentException |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * @param mixed $data |
| 41 | * @param string|null $format |
| 42 | * @param array<string, mixed> $context |
| 43 | * @return array<string, mixed> |
| 44 | */ |
| 45 | final public function normalize(mixed $data, ?string $format = null, array $context = []): array |
| 46 | { |
| 47 | return [ |
| 48 | 'timestamp' => $this->now()->format(\DateTimeInterface::RFC3339_EXTENDED), |
| 49 | 'status' => $this->getStatus($data), |
| 50 | 'error' => $this->getErrorCode($data), |
| 51 | 'message' => $this->getMessage($data), |
| 52 | 'errors' => $this->normalizeErrors($data), |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 25 | protected function getErrorCode(\Throwable $throwable): string |
| 26 | { |
| 27 | return 'internal-error'; |
| 28 | } |
| 30 | protected function getMessage(\Throwable $throwable): string |
| 31 | { |
| 32 | return $throwable->getMessage(); |
| 33 | } |
| 45 | final public function normalize(mixed $data, ?string $format = null, array $context = []): array |
| 46 | { |
| 47 | return [ |
| 48 | 'timestamp' => $this->now()->format(\DateTimeInterface::RFC3339_EXTENDED), |
| 49 | 'status' => $this->getStatus($data), |
| 50 | 'error' => $this->getErrorCode($data), |
| 51 | 'message' => $this->getMessage($data), |
| 52 | 'errors' => $this->normalizeErrors($data), |
| 53 | ]; |
| 54 | } |
| 3 | namespace App\Shared\Infrastructure\Normalizer; |
| 4 | |
| 5 | use App\Shared\Domain\Exception\ValidationException; |
| 6 | use Symfony\Component\Clock\ClockAwareTrait; |
| 7 | use Symfony\Component\HttpFoundation\Response; |
| 8 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
| 9 | |
| 10 | /** |
| 11 | * @author Wilhelm Zwertvaegher |
| 12 | */ |
| 13 | abstract class ExceptionNormalizer implements NormalizerInterface |
| 14 | { |
| 15 | use ClockAwareTrait; |
| 16 | |
| 17 | /** |
| 18 | * @param \Throwable $throwable |
| 19 | * @return array<string, array<string, string[]|int[]>> |
| 20 | */ |
| 21 | abstract protected function normalizeErrors(\Throwable $throwable): array; |
| 22 | |
| 23 | abstract protected function getStatus(\Throwable $throwable): int; |
| 24 | |
| 25 | protected function getErrorCode(\Throwable $throwable): string |
| 26 | { |
| 27 | return 'internal-error'; |
| 28 | } |
| 29 | |
| 30 | protected function getMessage(\Throwable $throwable): string |
| 31 | { |
| 32 | return $throwable->getMessage(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @throws \InvalidArgumentException |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * @param mixed $data |
| 41 | * @param string|null $format |
| 42 | * @param array<string, mixed> $context |
| 43 | * @return array<string, mixed> |
| 44 | */ |
| 45 | final public function normalize(mixed $data, ?string $format = null, array $context = []): array |
| 46 | { |
| 47 | return [ |
| 48 | 'timestamp' => $this->now()->format(\DateTimeInterface::RFC3339_EXTENDED), |
| 49 | 'status' => $this->getStatus($data), |
| 50 | 'error' => $this->getErrorCode($data), |
| 51 | 'message' => $this->getMessage($data), |
| 52 | 'errors' => $this->normalizeErrors($data), |
| 53 | ]; |
| 54 | } |
| 55 |