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

MutationExceptionFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createFromException() 0 13 2
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