ValidationFormatter::getExceptionClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\ExceptionFormatter\Formatter;
6
7
use Fp\Collections\ArrayList;
8
use FRZB\Component\DependencyInjection\Attribute\AsService;
9
use FRZB\Component\DependencyInjection\Attribute\AsTagged;
10
use FRZB\Component\RequestMapper\Data\ErrorContract;
11
use FRZB\Component\RequestMapper\Data\ErrorInterface as Error;
12
use FRZB\Component\RequestMapper\Data\FormattedError;
13
use FRZB\Component\RequestMapper\Exception\ValidationException;
14
use Symfony\Component\HttpFoundation\Response;
15
16
#[AsService, AsTagged(FormatterInterface::class)]
17
class ValidationFormatter implements FormatterInterface
18 1
{
19
    public function __invoke(ValidationException $e): ErrorContract
20 1
    {
21 1
        return new FormattedError(
22
            $e->getMessage(),
23 1
            Response::HTTP_UNPROCESSABLE_ENTITY,
24 1
            self::formatErrors(...$e->errors),
25
            $e->getTrace(),
26
        );
27
    }
28 1
29
    public static function getExceptionClass(): string
30 1
    {
31
        return ValidationException::class;
32
    }
33 1
34
    public static function getPriority(): int
35 1
    {
36
        return 1;
37
    }
38 1
39
    private static function formatErrors(Error ...$errors): array
40 1
    {
41 1
        return ArrayList::collect($errors)
42 1
            ->map(static fn (Error $error) => [$error->getField() => $error->getMessage()])
43
            ->reduce(array_merge(...))
0 ignored issues
show
Bug introduced by
The type FRZB\Component\RequestMa...r\Formatter\array_merge was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
            ->getOrElse([])
45
        ;
46
    }
47
}
48