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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

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

30.0
/src/Doctrine/Odm/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\Odm\Extension;
15

16
use ApiPlatform\Doctrine\Common\Filter\ManagerRegistryAwareInterface;
17
use ApiPlatform\Doctrine\Common\ParameterValueExtractorTrait;
18
use ApiPlatform\Doctrine\Odm\Filter\AbstractFilter;
19
use ApiPlatform\Doctrine\Odm\Filter\FilterInterface;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\State\ParameterNotFound;
22
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
23
use Doctrine\ODM\MongoDB\Aggregation\Builder;
24
use Psr\Container\ContainerInterface;
25

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

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

41
    /**
42
     * @param array<string, mixed> $context
43
     */
44
    private function applyFilter(Builder $aggregationBuilder, ?string $resourceClass = null, ?Operation $operation = null, array &$context = []): void
45
    {
UNCOV
46
        foreach ($operation->getParameters() ?? [] as $parameter) {
469✔
UNCOV
47
            if (null === ($v = $parameter->getValue()) || $v instanceof ParameterNotFound) {
220✔
UNCOV
48
                continue;
219✔
49
            }
50

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

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

62
            if (!$filter instanceof FilterInterface) {
×
63
                continue;
×
64
            }
65

66
            if ($this->managerRegistry && $filter instanceof ManagerRegistryAwareInterface && !$filter->hasManagerRegistry()) {
×
67
                $filter->setManagerRegistry($this->managerRegistry);
×
68
            }
69

70
            if ($filter instanceof AbstractFilter && !$filter->getProperties()) {
×
71
                $propertyKey = $parameter->getProperty() ?? $parameter->getKey();
×
72

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

82
                $filter->setProperties($properties ?? []);
×
83
            }
84

85
            $filterContext = ['filters' => $values, 'parameter' => $parameter];
×
86
            $filter->apply($aggregationBuilder, $resourceClass, $operation, $filterContext);
×
87
            // update by reference
88
            if (isset($filterContext['mongodb_odm_sort_fields'])) {
×
89
                $context['mongodb_odm_sort_fields'] = $filterContext['mongodb_odm_sort_fields'];
×
90
            }
91
        }
92
    }
93

94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function applyToCollection(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
98
    {
UNCOV
99
        $this->applyFilter($aggregationBuilder, $resourceClass, $operation, $context);
274✔
100
    }
101

102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function applyToItem(Builder $aggregationBuilder, string $resourceClass, array $identifiers, ?Operation $operation = null, array &$context = []): void
106
    {
UNCOV
107
        $this->applyFilter($aggregationBuilder, $resourceClass, $operation, $context);
217✔
108
    }
109
}
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