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

api-platform / core / 13724522058

07 Mar 2025 04:04PM UTC coverage: 8.175% (-0.3%) from 8.518%
13724522058

Pull #7005

github

web-flow
Merge 322407532 into 1e0bc9dc8
Pull Request #7005: fix(validation): deprecate string message for ValidationException con…

4 of 6 new or added lines in 1 file covered. (66.67%)

159 existing lines in 24 files now uncovered.

12839 of 157045 relevant lines covered (8.18%)

13.55 hits per line

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

95.65
/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
    {
33
        if ($request) {
485✔
34
            return ($parameter instanceof HeaderParameterInterface ? $request->attributes->get('_api_header_parameters') : $request->attributes->get('_api_query_parameters')) ?? [];
483✔
35
        }
36

37
        return $context['args'] ?? [];
2✔
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
    {
47
        $accessors = null;
485✔
48
        $key = $parameter->getKey();
485✔
49
        if (null === $key) {
485✔
50
            throw new \RuntimeException('A Parameter should have a key.');
×
51
        }
52

53
        $parsedKey = explode('[:property]', $key);
485✔
54
        if (isset($parsedKey[0]) && isset($values[$parsedKey[0]])) {
485✔
55
            $key = $parsedKey[0];
290✔
56
        } elseif (str_contains($key, '[')) {
477✔
57
            preg_match_all('/[^\[\]]+/', $key, $matches);
269✔
58
            $key = array_shift($matches[0]);
269✔
59
            $accessors = $matches[0];
269✔
60
        }
61

62
        $value = $values[$key] ?? new ParameterNotFound();
485✔
63
        if (!$accessors) {
485✔
64
            return $value;
479✔
65
        }
66

67
        foreach ($accessors as $accessor) {
204✔
68
            if (\is_array($value) && isset($value[$accessor])) {
204✔
UNCOV
69
                $value = $value[$accessor];
31✔
70
            } else {
71
                $value = new ParameterNotFound();
203✔
72
                continue;
203✔
73
            }
74
        }
75

76
        return $value;
204✔
77
    }
78
}
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