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

api-platform / core / 17327553156

29 Aug 2025 03:13PM UTC coverage: 22.588% (-0.03%) from 22.622%
17327553156

push

github

web-flow
fix(laravel): serialization issue with camelCase relation (#7356)

fixes #7344

0 of 76 new or added lines in 9 files covered. (0.0%)

11415 existing lines in 372 files now uncovered.

11181 of 49499 relevant lines covered (22.59%)

23.68 hits per line

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

93.62
/src/Symfony/Validator/State/ParameterValidatorProvider.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\State;
15

16
use ApiPlatform\Metadata\HttpOperation;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\Metadata\Parameter;
19
use ApiPlatform\Metadata\Parameters;
20
use ApiPlatform\State\ParameterNotFound;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\Util\ParameterParserTrait;
23
use ApiPlatform\Validator\Exception\ValidationException;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\Validator\ConstraintViolation;
26
use Symfony\Component\Validator\ConstraintViolationInterface;
27
use Symfony\Component\Validator\ConstraintViolationList;
28
use Symfony\Component\Validator\Validator\ValidatorInterface;
29

30
/**
31
 * Validates parameters using the Symfony validator.
32
 *
33
 * @experimental
34
 */
35
final class ParameterValidatorProvider implements ProviderInterface
36
{
37
    use ParameterParserTrait;
38

39
    public function __construct(
40
        private readonly ValidatorInterface $validator,
41
        private readonly ProviderInterface $decorated,
42
    ) {
UNCOV
43
    }
571✔
44

45
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
46
    {
UNCOV
47
        if (!($request = $context['request'] ?? null) instanceof Request) {
544✔
48
            return $this->decorated->provide($operation, $uriVariables, $context);
×
49
        }
50

UNCOV
51
        $operation = $request->attributes->get('_api_operation') ?? $operation;
544✔
UNCOV
52
        if (!($operation->getQueryParameterValidationEnabled() ?? true)) {
544✔
UNCOV
53
            return $this->decorated->provide($operation, $uriVariables, $context);
2✔
54
        }
55

UNCOV
56
        $constraintViolationList = new ConstraintViolationList();
542✔
UNCOV
57
        $parameters = $operation->getParameters() ?? new Parameters();
542✔
58

UNCOV
59
        if ($operation instanceof HttpOperation) {
542✔
UNCOV
60
            foreach ($operation->getUriVariables() ?? [] as $key => $uriVariable) {
542✔
UNCOV
61
                if ($uriVariable->getValue() instanceof ParameterNotFound) {
206✔
UNCOV
62
                    $uriVariable->setValue($uriVariables[$key] ?? new ParameterNotFound());
206✔
63
                }
64

UNCOV
65
                $parameters->add($key, $uriVariable->withKey($key));
206✔
66
            }
67
        }
68

UNCOV
69
        foreach ($parameters as $parameter) {
542✔
UNCOV
70
            if (!$constraints = $parameter->getConstraints()) {
476✔
UNCOV
71
                continue;
448✔
72
            }
73

UNCOV
74
            $value = $parameter->getValue();
186✔
75

UNCOV
76
            if ($value instanceof ParameterNotFound) {
186✔
UNCOV
77
                $value = null;
88✔
78
            }
79

UNCOV
80
            $violations = $this->validator->validate($value, $constraints);
186✔
81

UNCOV
82
            foreach ($violations as $violation) {
186✔
UNCOV
83
                $constraintViolationList->add(new ConstraintViolation(
64✔
UNCOV
84
                    $violation->getMessage(),
64✔
UNCOV
85
                    $violation->getMessageTemplate(),
64✔
UNCOV
86
                    $violation->getParameters(),
64✔
UNCOV
87
                    $violation->getRoot(),
64✔
UNCOV
88
                    $this->getProperty($parameter, $violation),
64✔
UNCOV
89
                    $violation->getInvalidValue(),
64✔
UNCOV
90
                    $violation->getPlural(),
64✔
UNCOV
91
                    $violation->getCode(),
64✔
UNCOV
92
                    $violation->getConstraint(),
64✔
UNCOV
93
                    $violation->getCause()
64✔
UNCOV
94
                ));
64✔
95
            }
96
        }
97

UNCOV
98
        if (0 !== \count($constraintViolationList)) {
542✔
UNCOV
99
            throw new ValidationException($constraintViolationList);
64✔
100
        }
101

UNCOV
102
        return $this->decorated->provide($operation, $uriVariables, $context);
542✔
103
    }
104

105
    // There's a `property` inside Parameter but it's used for hydra:search only as here we want the parameter name instead
106
    private function getProperty(Parameter $parameter, ConstraintViolationInterface $violation): string
107
    {
UNCOV
108
        $key = $parameter->getKey();
64✔
109

UNCOV
110
        if (str_contains($key, '[:property]')) {
64✔
UNCOV
111
            return str_replace('[:property]', $violation->getPropertyPath(), $key);
6✔
112
        }
113

UNCOV
114
        if (str_contains($key, ':property')) {
60✔
115
            return str_replace(':property', $violation->getPropertyPath(), $key);
×
116
        }
117

UNCOV
118
        $openApi = $parameter->getOpenApi();
60✔
UNCOV
119
        if (false === $openApi) {
60✔
120
            $openApi = null;
×
121
        }
122

UNCOV
123
        if ('deepObject' === $openApi?->getStyle() && $p = $violation->getPropertyPath()) {
60✔
UNCOV
124
            return $key.$p;
2✔
125
        }
126

UNCOV
127
        return $key;
60✔
128
    }
129
}
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