Completed
Pull Request — master (#2)
by Samuel
04:21
created

MutationExceptionFormatter::createFromException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace App\Common\App\Formatter;
4
5
use App\Common\Domain\FormException;
6
use App\Common\Domain\MutationException;
7
use GraphQL\Error\ClientAware;
8
use GraphQL\Error\Error;
9
use GraphQL\Error\FormattedError;
10
use GraphQL\Language\SourceLocation;
11
use GraphQL\Utils;
12
use Symfony\Component\Form\FormInterface;
13
14
class MutationExceptionFormatter
15
{
16
    public static function createFromException(MutationException $exception): array
17
    {
18
        $payload = [];
19
20
        foreach ($exception->getConstraintViolations() as $constraintViolation) {
21
            $payload[] = [
22
                'message' => $constraintViolation->getMessage(),
23
                'field'   => $constraintViolation->getPropertyPath(),
24
            ];
25
        }
26
27
        return $payload;
28
    }
29
}
30