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

api-platform / core / 8100440090

29 Feb 2024 05:54PM UTC coverage: 57.09% (+0.2%) from 56.922%
8100440090

Pull #6138

github

web-flow
chore(deps): bump codecov/codecov-action from 3 to 4

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #6138: chore(deps): bump codecov/codecov-action from 3 to 4

9538 of 16707 relevant lines covered (57.09%)

30.81 hits per line

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

100.0
/src/Symfony/Validator/EventListener/ValidationExceptionListener.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\Symfony\Validator\EventListener;
15

16
use ApiPlatform\Exception\FilterValidationException;
17
use ApiPlatform\Symfony\EventListener\ExceptionListener;
18
use ApiPlatform\Symfony\Validator\Exception\ConstraintViolationListAwareExceptionInterface as SymfonyConstraintViolationListAwareExceptionInterface;
19
use ApiPlatform\Util\ErrorFormatGuesser;
20
use ApiPlatform\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
21
use ApiPlatform\Validator\Exception\ValidationException;
22
use Symfony\Component\HttpFoundation\Response;
23
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
24
use Symfony\Component\Serializer\SerializerInterface;
25

26
/**
27
 * Handles validation errors.
28
 * TODO: remove this class.
29
 *
30
 * @deprecated
31
 *
32
 * @author Kévin Dunglas <dunglas@gmail.com>
33
 */
34
final class ValidationExceptionListener
35
{
36
    public function __construct(private readonly SerializerInterface $serializer, private readonly array $errorFormats, private readonly array $exceptionToStatus = [], private readonly ?ExceptionListener $exceptionListener = null)
37
    {
38
    }
43✔
39

40
    /**
41
     * Returns a list of violations normalized in the Hydra format.
42
     */
43
    public function onKernelException(ExceptionEvent $event): void
44
    {
45
        // API Platform 3.2 handles every exception through the exception listener so we just skip this one
46
        if ($this->exceptionListener) {
17✔
47
            return;
2✔
48
        }
49

50
        trigger_deprecation('api-platform', '3.2', sprintf('The class "%s" is deprecated and will be removed in 4.x.', __CLASS__));
15✔
51

52
        $exception = $event->getThrowable();
15✔
53
        $hasConstraintViolationList = ($exception instanceof ConstraintViolationListAwareExceptionInterface || $exception instanceof SymfonyConstraintViolationListAwareExceptionInterface);
15✔
54
        if (!$hasConstraintViolationList && !$exception instanceof FilterValidationException) {
15✔
55
            return;
3✔
56
        }
57

58
        $exceptionClass = $exception::class;
12✔
59
        $statusCode = Response::HTTP_UNPROCESSABLE_ENTITY;
12✔
60

61
        foreach ($this->exceptionToStatus as $class => $status) {
12✔
62
            if (is_a($exceptionClass, $class, true)) {
3✔
63
                $statusCode = $status;
3✔
64

65
                break;
3✔
66
            }
67
        }
68

69
        $format = ErrorFormatGuesser::guessErrorFormat($event->getRequest(), $this->errorFormats);
12✔
70

71
        $context = [];
12✔
72
        if ($exception instanceof ValidationException && ($errorTitle = $exception->getErrorTitle())) {
12✔
73
            $context['title'] = $errorTitle;
3✔
74
        }
75

76
        $event->setResponse(new Response(
12✔
77
            $this->serializer->serialize($hasConstraintViolationList ? $exception->getConstraintViolationList() : $exception, $format['key'], $context),
12✔
78
            $statusCode,
12✔
79
            [
12✔
80
                'Content-Type' => sprintf('%s; charset=utf-8', $format['value'][0]),
12✔
81
                'X-Content-Type-Options' => 'nosniff',
12✔
82
                'X-Frame-Options' => 'deny',
12✔
83
            ]
12✔
84
        ));
12✔
85
    }
86
}
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