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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 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 = [];
1,015✔
31

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

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

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

46
            if (($uriVariableDefinition->getCompositeIdentifier() ?? true) && 1 < ($numIdentifiers = \count($uriVariableDefinition->getIdentifiers() ?? []))) {
395✔
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];
395✔
62
            $uriVariablesMap[$parameterName] = $uriVariableDefinition;
395✔
63
        }
64

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

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