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

ErrorNormalizer::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
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