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

api-platform / core / 20903291093

11 Jan 2026 10:58PM UTC coverage: 20.146% (-8.7%) from 28.875%
20903291093

Pull #7667

github

VincentLanglet
Try
Pull Request #7667: POC NameConverterAwareInterface

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

14884 existing lines in 487 files now uncovered.

11580 of 57481 relevant lines covered (20.15%)

27.5 hits per line

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

25.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);
×
31

UNCOV
32
        return new IriTemplate(
×
UNCOV
33
            variableRepresentation: 'BasicRepresentation',
×
UNCOV
34
            mapping: $mapping,
×
UNCOV
35
            template: \sprintf('%s{?%s}', $path, implode(',', $keys)),
×
UNCOV
36
        );
×
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 = [];
119✔
UNCOV
47
        $keys = [];
119✔
48

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

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

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

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

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

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

UNCOV
82
                    $variableName = $variable;
×
83

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

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

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

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

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

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