• 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

95.0
/src/Doctrine/Orm/Filter/AbstractFilter.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\Filter;
15

16
use ApiPlatform\Doctrine\Common\Filter\ManagerRegistryAwareInterface;
17
use ApiPlatform\Doctrine\Common\Filter\PropertyAwareFilterInterface;
18
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
19
use ApiPlatform\Doctrine\Orm\PropertyHelperTrait as OrmPropertyHelperTrait;
20
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
21
use ApiPlatform\Metadata\Exception\RuntimeException;
22
use ApiPlatform\Metadata\Operation;
23
use Doctrine\ORM\QueryBuilder;
24
use Doctrine\Persistence\ManagerRegistry;
25
use Psr\Log\LoggerInterface;
26
use Psr\Log\NullLogger;
27
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
28

29
abstract class AbstractFilter implements FilterInterface, PropertyAwareFilterInterface, ManagerRegistryAwareInterface
30
{
31
    use OrmPropertyHelperTrait;
32
    use PropertyHelperTrait;
33
    protected LoggerInterface $logger;
34

35
    public function __construct(
36
        protected ?ManagerRegistry $managerRegistry = null,
37
        ?LoggerInterface $logger = null,
38
        protected ?array $properties = null,
39
        protected ?NameConverterInterface $nameConverter = null,
40
    ) {
41
        $this->logger = $logger ?? new NullLogger();
196✔
42
    }
43

44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
48
    {
49
        foreach ($context['filters'] as $property => $value) {
144✔
50
            $this->filterProperty($this->denormalizePropertyName($property), $value, $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
140✔
51
        }
52
    }
53

54
    /**
55
     * Passes a property through the filter.
56
     *
57
     * @param class-string         $resourceClass
58
     * @param array<string, mixed> $context
59
     */
60
    abstract protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void;
61

62
    public function hasManagerRegistry(): bool
63
    {
64
        return $this->managerRegistry instanceof ManagerRegistry;
331✔
65
    }
66

67
    public function getManagerRegistry(): ManagerRegistry
68
    {
69
        if (!$this->hasManagerRegistry()) {
307✔
70
            throw new RuntimeException('ManagerRegistry must be initialized before accessing it.');
12✔
71
        }
72

73
        return $this->managerRegistry;
307✔
74
    }
75

76
    public function setManagerRegistry(ManagerRegistry $managerRegistry): void
77
    {
78
        $this->managerRegistry = $managerRegistry;
164✔
79
    }
80

81
    public function getProperties(): ?array
82
    {
83
        return $this->properties;
331✔
84
    }
85

86
    /**
87
     * @param array<string, mixed> $properties
88
     */
89
    public function setProperties(array $properties): void
90
    {
91
        $this->properties = $properties;
158✔
92
    }
93

94
    protected function getLogger(): LoggerInterface
95
    {
96
        return $this->logger;
20✔
97
    }
98

99
    /**
100
     * Determines whether the given property is enabled.
101
     */
102
    protected function isPropertyEnabled(string $property, string $resourceClass): bool
103
    {
104
        if (null === $this->properties) {
148✔
105
            // to ensure sanity, nested properties must still be explicitly enabled
106
            return !$this->isPropertyNested($property, $resourceClass);
×
107
        }
108

109
        return \array_key_exists($property, $this->properties);
148✔
110
    }
111

112
    protected function denormalizePropertyName(string|int $property): string
113
    {
114
        if (!$this->nameConverter instanceof NameConverterInterface) {
172✔
115
            return (string) $property;
164✔
116
        }
117

118
        return implode('.', array_map($this->nameConverter->denormalize(...), explode('.', (string) $property)));
8✔
119
    }
120

121
    protected function normalizePropertyName(string $property): string
122
    {
123
        if (!$this->nameConverter instanceof NameConverterInterface) {
167✔
UNCOV
124
            return $property;
145✔
125
        }
126

127
        return implode('.', array_map($this->nameConverter->normalize(...), explode('.', $property)));
22✔
128
    }
129
}
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