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

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

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

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

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

93.33
/src/Symfony/Validator/Validator.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;
15

16
use ApiPlatform\Symfony\Validator\Exception\ValidationException;
17
use ApiPlatform\Validator\ValidatorInterface;
18
use Psr\Container\ContainerInterface;
19
use Symfony\Component\Validator\Constraints\GroupSequence;
20
use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidatorInterface;
21

22
/**
23
 * Validates an item using the Symfony validator component.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 *
27
 * @final
28
 */
29
class Validator implements ValidatorInterface
30
{
31
    public function __construct(private readonly SymfonyValidatorInterface $validator, private readonly ?ContainerInterface $container = null)
32
    {
33
    }
2,478✔
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function validate(object $data, array $context = []): void
39
    {
40
        if (null !== $validationGroups = $context['groups'] ?? null) {
783✔
41
            if (
42
                $this->container
6✔
43
                && \is_string($validationGroups)
6✔
44
                && $this->container->has($validationGroups)
6✔
45
                && ($service = $this->container->get($validationGroups))
6✔
46
                && \is_callable($service)
6✔
47
            ) {
48
                $validationGroups = $service($data);
3✔
49
            } elseif (\is_callable($validationGroups)) {
3✔
UNCOV
50
                $validationGroups = $validationGroups($data);
×
51
            }
52

53
            if (!$validationGroups instanceof GroupSequence) {
6✔
54
                $validationGroups = (array) $validationGroups;
3✔
55
            }
56
        }
57

58
        $violations = $this->validator->validate($data, null, $validationGroups);
783✔
59
        if (0 !== \count($violations)) {
783✔
60
            throw new ValidationException($violations);
42✔
61
        }
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