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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

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

11040 existing lines in 370 files now uncovered.

0 of 48303 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\HeaderParameterInterface;
17
use ApiPlatform\Metadata\Parameter;
18
use ApiPlatform\State\ParameterNotFound;
19
use Symfony\Component\HttpFoundation\Request;
20

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

UNCOV
37
        return $context['args'] ?? [];
×
38
    }
39

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

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

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

UNCOV
66
        $value = $values[$key] ?? new ParameterNotFound();
×
UNCOV
67
        if (!$accessors) {
×
UNCOV
68
            return $value;
×
69
        }
70

UNCOV
71
        foreach ($accessors as $accessor) {
×
UNCOV
72
            if (\is_array($value) && isset($value[$accessor])) {
×
73
                $value = $value[$accessor];
×
74
            } else {
UNCOV
75
                $value = new ParameterNotFound();
×
UNCOV
76
                continue;
×
77
            }
78
        }
79

UNCOV
80
        return $value;
×
81
    }
82
}
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