Passed
Push — master ( ce7fff...9920f1 )
by Alan
04:04
created

ErrorNormalizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A normalize() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\GraphQl\Serializer\Exception;
15
16
use GraphQL\Error\Error;
17
use GraphQL\Error\FormattedError;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
20
/**
21
 * Normalize GraphQL error (fallback).
22
 *
23
 * @experimental
24
 *
25
 * @author Alan Poulain <[email protected]>
26
 */
27
final class ErrorNormalizer implements NormalizerInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function normalize($object, $format = null, array $context = []): array
33
    {
34
        return FormattedError::createFromException($object);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function supportsNormalization($data, $format = null): bool
41
    {
42
        return $data instanceof Error;
43
    }
44
}
45