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

api-platform / core / 10729306835

05 Sep 2024 10:46PM UTC coverage: 7.655% (-0.01%) from 7.665%
10729306835

push

github

web-flow
Merge pull request #6586 from soyuka/merge-342

Merge 3.4

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

8760 existing lines in 277 files now uncovered.

12505 of 163357 relevant lines covered (7.66%)

22.84 hits per line

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

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

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;
723✔
UNCOV
48
        $key = $parameter->getKey();
723✔
UNCOV
49
        $parsedKey = explode('[:property]', $key);
723✔
UNCOV
50
        if (isset($parsedKey[0]) && isset($values[$parsedKey[0]])) {
723✔
UNCOV
51
            $key = $parsedKey[0];
176✔
UNCOV
52
        } elseif (str_contains($key, '[')) {
723✔
UNCOV
53
            preg_match_all('/[^\[\]]+/', $key, $matches);
685✔
UNCOV
54
            $key = array_shift($matches[0]);
685✔
UNCOV
55
            $accessors = $matches[0];
685✔
56
        }
57

UNCOV
58
        $value = $values[$key] ?? new ParameterNotFound();
723✔
UNCOV
59
        if (!$accessors) {
723✔
UNCOV
60
            return $value;
705✔
61
        }
62

UNCOV
63
        foreach ($accessors as $accessor) {
486✔
UNCOV
64
            if (\is_array($value) && isset($value[$accessor])) {
486✔
UNCOV
65
                $value = $value[$accessor];
93✔
66
            } else {
UNCOV
67
                $value = new ParameterNotFound();
483✔
UNCOV
68
                continue;
483✔
69
            }
70
        }
71

UNCOV
72
        return $value;
486✔
73
    }
74
}
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