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

api-platform / core / 3713134090

pending completion
3713134090

Pull #5254

github

GitHub
Merge b2ec54b3c into ac711530f
Pull Request #5254: [OpenApi] Add ApiResource::openapi and deprecate openapiContext

197 of 197 new or added lines in 5 files covered. (100.0%)

7493 of 12362 relevant lines covered (60.61%)

67.56 hits per line

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

60.0
/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\CompositeIdentifierParser;
17
use ApiPlatform\Api\UriVariablesConverterInterface;
18
use ApiPlatform\Exception\InvalidIdentifierException;
19
use ApiPlatform\Metadata\HttpOperation;
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 = [];
514✔
31

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

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

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

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

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

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

56
                continue;
×
57
            }
58

59
            $identifiers[$parameterName] = $parameters[$parameterName];
224✔
60
        }
61

62
        if ($this->uriVariablesConverter) {
514✔
63
            $context = ['operation' => $operation];
514✔
64
            $identifiers = $this->uriVariablesConverter->convert($identifiers, $operation->getClass() ?? $resourceClass, $context);
514✔
65
        }
66

67
        return $identifiers;
514✔
68
    }
69
}
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