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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

0 of 4 new or added lines in 1 file covered. (0.0%)

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

100.0
/src/Hydra/State/Util/SearchHelperTrait.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\Hydra\State\Util;
15

16
use ApiPlatform\Hydra\IriTemplate;
17
use ApiPlatform\Hydra\IriTemplateMapping;
18
use ApiPlatform\Metadata\FilterInterface;
19
use ApiPlatform\Metadata\Operation;
20
use ApiPlatform\Metadata\Parameters;
21
use ApiPlatform\Metadata\QueryParameterInterface;
22

23
trait SearchHelperTrait
24
{
25
    /**
26
     * @param FilterInterface[] $filters
27
     */
28
    private function getSearch(string $path, ?Operation $operation = null, ?string $resourceClass = null, ?array $filters = [], ?Parameters $parameters = null, ?callable $getFilter = null): IriTemplate
29
    {
UNCOV
30
        ['mapping' => $mapping, 'keys' => $keys] = $this->getSearchMappingAndKeys($operation, $resourceClass, $filters, $parameters, $getFilter);
2✔
31

UNCOV
32
        return new IriTemplate(
2✔
UNCOV
33
            variableRepresentation: 'BasicRepresentation',
2✔
UNCOV
34
            mapping: $mapping,
2✔
UNCOV
35
            template: \sprintf('%s{?%s}', $path, implode(',', $keys)),
2✔
UNCOV
36
        );
2✔
37
    }
38

39
    /**
40
     * @param FilterInterface[] $filters
41
     *
42
     * @return array{mapping: list<IriTemplateMapping>, keys: list<string>}
43
     */
44
    private function getSearchMappingAndKeys(?Operation $operation = null, ?string $resourceClass = null, ?array $filters = [], ?Parameters $parameters = null, ?callable $getFilter = null): array
45
    {
UNCOV
46
        $mapping = [];
518✔
UNCOV
47
        $keys = [];
518✔
48

UNCOV
49
        if ($filters) {
518✔
UNCOV
50
            foreach ($filters as $filter) {
236✔
UNCOV
51
                foreach ($filter->getDescription($resourceClass) as $variable => $data) {
236✔
UNCOV
52
                    $keys[] = $variable;
235✔
UNCOV
53
                    $mapping[] = new IriTemplateMapping(variable: $variable, property: $data['property'] ?? null, required: $data['required'] ?? false);
235✔
54
                }
55
            }
56
        }
57

UNCOV
58
        foreach ($parameters ?? $operation?->getParameters() ?? [] as $key => $parameter) {
518✔
UNCOV
59
            if (!$parameter instanceof QueryParameterInterface || false === $parameter->getHydra()) {
481✔
UNCOV
60
                continue;
207✔
61
            }
62

63
            // get possible mapping via the parameter's Filter
UNCOV
64
            if ($getFilter && ($filterId = $parameter->getFilter()) && \is_string($filterId) && ($filter = $getFilter($filterId))) {
282✔
UNCOV
65
                $filterDescription = $filter->getDescription($resourceClass);
16✔
66

UNCOV
67
                foreach ($filterDescription as $variable => $description) {
16✔
68
                    // This is a practice induced by PHP and is not necessary when implementing URI
UNCOV
69
                    if (str_ends_with((string) $variable, '[]')) {
16✔
UNCOV
70
                        continue;
10✔
71
                    }
72

UNCOV
73
                    if (!($descriptionProperty = $description['property'] ?? null)) {
16✔
UNCOV
74
                        continue;
2✔
75
                    }
76

77
                    // Ensure the filter description matches the property defined in the QueryParameter
UNCOV
78
                    if (($prop = $parameter->getProperty()) && $descriptionProperty !== $prop) {
14✔
UNCOV
79
                        continue;
10✔
80
                    }
81

UNCOV
82
                    $variableName = $variable;
14✔
83

UNCOV
84
                    if ($prop && str_starts_with($variable, $prop)) {
14✔
UNCOV
85
                        $variableName = substr_replace($variable, $key, 0, \strlen($prop));
14✔
86
                    }
87

UNCOV
88
                    $keys[] = $variableName;
14✔
UNCOV
89
                    $mapping[] = new IriTemplateMapping(
14✔
UNCOV
90
                        variable: $variableName,
14✔
UNCOV
91
                        property: $descriptionProperty,
14✔
UNCOV
92
                        required: $parameter->getRequired() ?? $description['required'] ?? false
14✔
UNCOV
93
                    );
14✔
94
                }
95

UNCOV
96
                if ($filterDescription) {
16✔
UNCOV
97
                    continue;
16✔
98
                }
99
            }
100

UNCOV
101
            if (!($property = $parameter->getProperty())) {
278✔
UNCOV
102
                continue;
66✔
103
            }
104

UNCOV
105
            $m = new IriTemplateMapping(variable: $key, property: $property);
256✔
UNCOV
106
            $keys[] = $key;
256✔
UNCOV
107
            if (null !== ($required = $parameter->getRequired())) {
256✔
UNCOV
108
                $m->required = $required;
4✔
109
            }
UNCOV
110
            $mapping[] = $m;
256✔
111
        }
112

UNCOV
113
        return ['mapping' => $mapping, 'keys' => $keys];
518✔
114
    }
115
}
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

© 2026 Coveralls, Inc