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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

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

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

95.65
/src/State/UriVariablesResolverTrait.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\State;
15

16
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
17
use ApiPlatform\Metadata\HttpOperation;
18
use ApiPlatform\Metadata\UriVariablesConverterInterface;
19
use ApiPlatform\Metadata\Util\CompositeIdentifierParser;
20

21
trait UriVariablesResolverTrait
22
{
23
    private ?UriVariablesConverterInterface $uriVariablesConverter = null;
24

25
    /**
26
     * Resolves an operation's UriVariables to their identifiers values.
27
     */
28
    private function getOperationUriVariables(?HttpOperation $operation = null, array $parameters = [], ?string $resourceClass = null): array
29
    {
UNCOV
30
        $identifiers = [];
2,087✔
31

UNCOV
32
        if (!$operation) {
2,087✔
33
            return $identifiers;
×
34
        }
35

UNCOV
36
        $uriVariablesMap = [];
2,087✔
UNCOV
37
        foreach ($operation->getUriVariables() ?? [] as $parameterName => $uriVariableDefinition) {
2,087✔
UNCOV
38
            if (!isset($parameters[$parameterName])) {
806✔
UNCOV
39
                if (!isset($parameters['id'])) {
6✔
UNCOV
40
                    throw new InvalidIdentifierException(\sprintf('Parameter "%s" not found, check the identifiers configuration.', $parameterName));
2✔
41
                }
42

43
                $parameterName = 'id';
4✔
44
            }
45

UNCOV
46
            if (($uriVariableDefinition->getCompositeIdentifier() ?? true) && 1 < ($numIdentifiers = \count($uriVariableDefinition->getIdentifiers() ?? []))) {
804✔
47
                $currentIdentifiers = CompositeIdentifierParser::parse($parameters[$parameterName]);
9✔
48

49
                if (($foundNumIdentifiers = \count($currentIdentifiers)) !== $numIdentifiers) {
9✔
50
                    throw new InvalidIdentifierException(\sprintf('We expected "%s" identifiers and got "%s".', $numIdentifiers, $foundNumIdentifiers));
1✔
51
                }
52

53
                foreach ($currentIdentifiers as $key => $value) {
8✔
54
                    $identifiers[$key] = $value;
8✔
55
                    $uriVariablesMap[$key] = $uriVariableDefinition;
8✔
56
                }
57

58
                continue;
8✔
59
            }
60

UNCOV
61
            $identifiers[$parameterName] = $parameters[$parameterName];
795✔
UNCOV
62
            $uriVariablesMap[$parameterName] = $uriVariableDefinition;
795✔
63
        }
64

UNCOV
65
        if ($this->uriVariablesConverter) {
2,084✔
UNCOV
66
            $context = ['operation' => $operation, 'uri_variables_map' => $uriVariablesMap];
2,076✔
UNCOV
67
            $identifiers = $this->uriVariablesConverter->convert($identifiers, $operation->getClass() ?? $resourceClass, $context);
2,076✔
68
        }
69

UNCOV
70
        return $identifiers;
2,081✔
71
    }
72
}
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