• 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

91.3
/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\Api\UriVariablesConverterInterface as LegacyUriVariablesConverterInterface;
17
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\UriVariablesConverterInterface;
20
use ApiPlatform\Metadata\Util\CompositeIdentifierParser;
21

22
trait UriVariablesResolverTrait
23
{
24
    private null|LegacyUriVariablesConverterInterface|UriVariablesConverterInterface $uriVariablesConverter = null;
25

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

33
        if (!$operation) {
2,157✔
34
            return $identifiers;
×
35
        }
36

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

44
                $parameterName = 'id';
6✔
45
            }
46

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

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

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

59
                continue;
24✔
60
            }
61

62
            $identifiers[$parameterName] = $parameters[$parameterName];
906✔
63
            $uriVariablesMap[$parameterName] = $uriVariableDefinition;
906✔
64
        }
65

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

71
        return $identifiers;
2,151✔
72
    }
73
}
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