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

api-platform / core / 14008635868

22 Mar 2025 12:39PM UTC coverage: 8.52% (+0.005%) from 8.515%
14008635868

Pull #7042

github

web-flow
Merge fdd88ef56 into 47a6dffbb
Pull Request #7042: Purge parent collections in inheritance cases

4 of 9 new or added lines in 1 file covered. (44.44%)

540 existing lines in 57 files now uncovered.

13394 of 157210 relevant lines covered (8.52%)

22.93 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
    {
30
        $identifiers = [];
1,747✔
31

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

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

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

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

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

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

UNCOV
58
                continue;
8✔
59
            }
60

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

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

70
        return $identifiers;
1,743✔
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