• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 14035635597

24 Mar 2025 12:46PM UTC coverage: 8.513% (-7.6%) from 16.086%
14035635597

push

github

web-flow
fix(laravel): defer "filters" dependent services (#7045)

0 of 109 new or added lines in 1 file covered. (0.0%)

3078 existing lines in 187 files now uncovered.

13386 of 157241 relevant lines covered (8.51%)

22.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\GraphQl\Serializer\Exception;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
18
use GraphQL\Error\Error;
19
use GraphQL\Error\FormattedError;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
22

23
/**
24
 * Normalize validation exceptions.
25
 *
26
 * @author Mahmood Bazdar <mahmood@bazdar.me>
27
 * @author Alan Poulain <contact@alanpoulain.eu>
28
 */
29
final class ValidationExceptionNormalizer implements NormalizerInterface
30
{
31
    public function __construct(private readonly array $exceptionToStatus = [])
32
    {
33
    }
2,008✔
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function normalize(mixed $object, ?string $format = null, array $context = []): array
39
    {
UNCOV
40
        $validationException = $object->getPrevious();
2✔
UNCOV
41
        if (!$validationException instanceof ConstraintViolationListAwareExceptionInterface) {
2✔
42
            throw new RuntimeException(\sprintf('Object is not a "%s".', ConstraintViolationListAwareExceptionInterface::class));
×
43
        }
44

UNCOV
45
        $error = FormattedError::createFromException($object);
2✔
UNCOV
46
        $error['message'] = $validationException->getMessage();
2✔
47

UNCOV
48
        $exceptionClass = $validationException::class;
2✔
UNCOV
49
        $statusCode = Response::HTTP_UNPROCESSABLE_ENTITY;
2✔
50

UNCOV
51
        foreach ($this->exceptionToStatus as $class => $status) {
2✔
UNCOV
52
            if (is_a($exceptionClass, $class, true)) {
2✔
53
                $statusCode = $status;
×
54

55
                break;
×
56
            }
57
        }
UNCOV
58
        $error['extensions']['status'] = $statusCode;
2✔
59
        // graphql-php < 15
UNCOV
60
        if (\defined(Error::class.'::CATEGORY_INTERNAL')) {
2✔
61
            $error['extensions']['category'] = 'user';
×
62
        }
UNCOV
63
        $error['extensions']['violations'] = [];
2✔
64

UNCOV
65
        foreach ($validationException->getConstraintViolationList() as $violation) {
2✔
UNCOV
66
            $error['extensions']['violations'][] = [
2✔
UNCOV
67
                'path' => $violation->getPropertyPath(),
2✔
UNCOV
68
                'message' => $violation->getMessage(),
2✔
UNCOV
69
            ];
2✔
70
        }
71

UNCOV
72
        return $error;
2✔
73
    }
74

75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
79
    {
UNCOV
80
        return $data instanceof Error && ($data->getPrevious() instanceof ConstraintViolationListAwareExceptionInterface);
35✔
81
    }
82

83
    public function getSupportedTypes($format): array
84
    {
85
        return [
1,884✔
86
            Error::class => false,
1,884✔
87
        ];
1,884✔
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc