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

api-platform / core / 18223414080

03 Oct 2025 01:18PM UTC coverage: 0.0% (-22.0%) from 21.956%
18223414080

Pull #7397

github

web-flow
Merge 69d085182 into 0b8237918
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

0 of 18 new or added lines in 2 files covered. (0.0%)

12304 existing lines in 405 files now uncovered.

0 of 53965 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/State/Util/ParameterParserTrait.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\Util;
15

16
use ApiPlatform\Metadata\HeaderParameter;
17
use ApiPlatform\Metadata\HeaderParameterInterface;
18
use ApiPlatform\Metadata\Parameter;
19
use ApiPlatform\State\ParameterNotFound;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\TypeInfo\Type\CollectionType;
22
use Symfony\Component\TypeInfo\Type\UnionType;
23

24
/**
25
 * @internal
26
 */
27
trait ParameterParserTrait
28
{
29
    /**
30
     * @param array<string, mixed> $context
31
     *
32
     * @return array<string, mixed>
33
     */
34
    private function getParameterValues(Parameter $parameter, ?Request $request, array $context): array
35
    {
UNCOV
36
        if ($request) {
×
UNCOV
37
            return ($parameter instanceof HeaderParameterInterface ? $request->attributes->get('_api_header_parameters') : $request->attributes->get('_api_query_parameters')) ?? [];
×
38
        }
39

UNCOV
40
        return $context['args'] ?? [];
×
41
    }
42

43
    /**
44
     * @param array<string, mixed> $values
45
     */
46
    private function extractParameterValues(Parameter $parameter, array $values): mixed
47
    {
UNCOV
48
        $accessors = null;
×
UNCOV
49
        $key = $parameter->getKey();
×
UNCOV
50
        if (null === $key) {
×
51
            throw new \RuntimeException('A Parameter should have a key.');
×
52
        }
53

UNCOV
54
        if ($parameter instanceof HeaderParameterInterface) {
×
UNCOV
55
            $key = strtolower($key);
×
56
        }
57

UNCOV
58
        $parsedKey = explode('[:property]', $key);
×
UNCOV
59
        if (isset($parsedKey[0]) && isset($values[$parsedKey[0]])) {
×
UNCOV
60
            $key = $parsedKey[0];
×
UNCOV
61
        } elseif (str_contains($key, '[')) {
×
UNCOV
62
            preg_match_all('/[^\[\]]+/', $key, $matches);
×
UNCOV
63
            $key = array_shift($matches[0]);
×
UNCOV
64
            $accessors = $matches[0];
×
65
        }
66

UNCOV
67
        $value = $values[$key] ?? new ParameterNotFound();
×
UNCOV
68
        foreach ($accessors ?? [] as $accessor) {
×
UNCOV
69
            if (\is_array($value) && isset($value[$accessor])) {
×
70
                $value = $value[$accessor];
×
71
            } else {
UNCOV
72
                $value = new ParameterNotFound();
×
73
            }
74
        }
75

UNCOV
76
        if ($value instanceof ParameterNotFound) {
×
UNCOV
77
            return $value;
×
78
        }
79

UNCOV
80
        $isCollectionType = fn ($t) => $t instanceof CollectionType;
×
UNCOV
81
        $isCollection = $parameter->getNativeType()?->isSatisfiedBy($isCollectionType) ?? false;
×
82

83
        // type-info 7.2
UNCOV
84
        if (!$isCollection && $parameter->getNativeType() instanceof UnionType) {
×
85
            foreach ($parameter->getNativeType()->getTypes() as $t) {
×
86
                if ($isCollection = $t->isSatisfiedBy($isCollectionType)) {
×
87
                    break;
×
88
                }
89
            }
90
        }
91

UNCOV
92
        if ($isCollection && true === $parameter->getCastToArray() && !\is_array($value)) {
×
UNCOV
93
            $value = [$value];
×
94
        }
95

UNCOV
96
        if (!$isCollection && $parameter instanceof HeaderParameter && \is_array($value) && array_is_list($value) && 1 === \count($value)) {
×
UNCOV
97
            $value = $value[0];
×
98
        }
99

UNCOV
100
        if (true === $parameter->getCastToNativeType() && ($castFn = $parameter->getCastFn())) {
×
UNCOV
101
            if (\is_array($value)) {
×
102
                $value = array_map(fn ($v) => $castFn($v, $parameter), $value);
×
103
            } else {
UNCOV
104
                $value = $castFn($value, $parameter);
×
105
            }
106
        }
107

UNCOV
108
        return $value;
×
109
    }
110
}
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