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

api-platform / core / 13944674159

19 Mar 2025 10:47AM UTC coverage: 7.275% (-0.01%) from 7.289%
13944674159

push

github

soyuka
Merge 3.4

6 of 23 new or added lines in 4 files covered. (26.09%)

2380 existing lines in 154 files now uncovered.

12415 of 170643 relevant lines covered (7.28%)

12.04 hits per line

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

65.22
/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
    {
30
        $identifiers = [];
957✔
31

32
        if (!$operation) {
957✔
33
            return $identifiers;
×
34
        }
35

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

UNCOV
43
                $parameterName = 'id';
2✔
44
            }
45

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

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

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

58
                continue;
×
59
            }
60

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

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

70
        return $identifiers;
954✔
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

© 2025 Coveralls, Inc