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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 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
    {
UNCOV
30
        $identifiers = [];
823✔
31

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

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

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

UNCOV
46
            if (($uriVariableDefinition->getCompositeIdentifier() ?? true) && 1 < ($numIdentifiers = \count($uriVariableDefinition->getIdentifiers() ?? []))) {
330✔
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

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

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

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