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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

93.1
/src/Doctrine/Orm/Extension/ParameterExtension.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\Doctrine\Orm\Extension;
15

16
use ApiPlatform\Doctrine\Common\Filter\ManagerRegistryAwareInterface;
17
use ApiPlatform\Doctrine\Common\ParameterValueExtractorTrait;
18
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
19
use ApiPlatform\Doctrine\Orm\Filter\FilterInterface;
20
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\State\ParameterNotFound;
23
use Doctrine\ORM\QueryBuilder;
24
use Doctrine\Persistence\ManagerRegistry;
25
use Psr\Container\ContainerInterface;
26

27
/**
28
 * Reads operation parameters and execute its filter.
29
 *
30
 * @author Antoine Bluchet <soyuka@gmail.com>
31
 */
32
final class ParameterExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
33
{
34
    use ParameterValueExtractorTrait;
35

36
    public function __construct(
37
        private readonly ContainerInterface $filterLocator,
38
        private readonly ?ManagerRegistry $managerRegistry = null,
39
    ) {
UNCOV
40
    }
116✔
41

42
    /**
43
     * @param array<string, mixed> $context
44
     */
45
    private function applyFilter(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
46
    {
UNCOV
47
        foreach ($operation?->getParameters() ?? [] as $parameter) {
116✔
UNCOV
48
            if (null === ($v = $parameter->getValue()) || $v instanceof ParameterNotFound) {
90✔
UNCOV
49
                continue;
87✔
50
            }
51

UNCOV
52
            $values = $this->extractParameterValue($parameter, $v);
90✔
UNCOV
53
            if (null === ($filterId = $parameter->getFilter())) {
90✔
UNCOV
54
                continue;
2✔
55
            }
56

UNCOV
57
            $filter = match (true) {
88✔
UNCOV
58
                $filterId instanceof FilterInterface => $filterId,
88✔
UNCOV
59
                \is_string($filterId) && $this->filterLocator->has($filterId) => $this->filterLocator->get($filterId),
5✔
60
                default => null,
×
UNCOV
61
            };
88✔
62

UNCOV
63
            if (!$filter instanceof FilterInterface) {
88✔
64
                continue;
×
65
            }
66

UNCOV
67
            if ($this->managerRegistry && $filter instanceof ManagerRegistryAwareInterface && !$filter->hasManagerRegistry()) {
88✔
UNCOV
68
                $filter->setManagerRegistry($this->managerRegistry);
82✔
69
            }
70

UNCOV
71
            if ($filter instanceof AbstractFilter && !$filter->getProperties()) {
88✔
UNCOV
72
                $propertyKey = $parameter->getProperty() ?? $parameter->getKey();
76✔
73

UNCOV
74
                if (str_contains($propertyKey, ':property')) {
76✔
UNCOV
75
                    $extraProperties = $parameter->getExtraProperties()['_properties'] ?? [];
4✔
UNCOV
76
                    foreach (array_keys($extraProperties) as $property) {
4✔
UNCOV
77
                        $properties[$property] = $parameter->getFilterContext();
4✔
78
                    }
79
                } else {
UNCOV
80
                    $properties = [$propertyKey => $parameter->getFilterContext()];
72✔
81
                }
82

UNCOV
83
                $filter->setProperties($properties ?? []);
76✔
84
            }
85

UNCOV
86
            $filter->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operation,
88✔
UNCOV
87
                ['filters' => $values, 'parameter' => $parameter] + $context
88✔
UNCOV
88
            );
88✔
89
        }
90
    }
91

92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
96
    {
UNCOV
97
        $this->applyFilter($queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
104✔
98
    }
99

100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, ?Operation $operation = null, array $context = []): void
104
    {
UNCOV
105
        $this->applyFilter($queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
19✔
106
    }
107
}
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