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

api-platform / core / 21002323270

14 Jan 2026 04:47PM UTC coverage: 28.875%. Remained the same
21002323270

Pull #7673

github

web-flow
Merge fc4377d20 into e1aaf65fa
Pull Request #7673: fix(validator): Fix ValidationException::violations schema

16825 of 58269 relevant lines covered (28.87%)

79.04 hits per line

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

91.67
/src/Symfony/EventListener/ValidateListener.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\EventListener;
15

16
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
17
use ApiPlatform\State\ProviderInterface;
18
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
19
use ApiPlatform\Validator\Exception\ValidationException;
20
use Symfony\Component\HttpKernel\Event\ViewEvent;
21

22
/**
23
 * Validates data.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class ValidateListener
28
{
29
    use OperationRequestInitiatorTrait;
30

31
    /**
32
     * @param ProviderInterface<object> $provider
33
     */
34
    public function __construct(private readonly ProviderInterface $provider, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
35
    {
36
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
309✔
37
    }
38

39
    /**
40
     * Validates data returned by the controller if applicable.
41
     *
42
     * @throws ValidationException
43
     */
44
    public function onKernelView(ViewEvent $event): void
45
    {
46
        $request = $event->getRequest();
309✔
47
        $operation = $this->initializeOperation($request);
309✔
48

49
        if (!$operation) {
309✔
50
            return;
×
51
        }
52

53
        if (null === $operation->canValidate()) {
309✔
54
            $operation = $operation->withValidate(!$request->isMethodSafe() && !$request->isMethod('DELETE'));
308✔
55
        }
56

57
        $this->provider->provide($operation, $request->attributes->get('_api_uri_variables') ?? [], [
309✔
58
            'request' => $request,
309✔
59
            'uri_variables' => $request->attributes->get('_api_uri_variables') ?? [],
309✔
60
            'resource_class' => $operation->getClass(),
309✔
61
        ]);
309✔
62
    }
63
}
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

© 2026 Coveralls, Inc