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

api-platform / core / 13814792797

12 Mar 2025 03:09PM UTC coverage: 5.889% (-1.4%) from 7.289%
13814792797

Pull #7012

github

web-flow
Merge 199d44919 into 284937039
Pull Request #7012: doc: comment typo in ApiResource.php

10048 of 170615 relevant lines covered (5.89%)

5.17 hits per line

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

75.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\PropertyAwareFilterInterface;
17
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
18
use ApiPlatform\Doctrine\Orm\PropertyHelperTrait as OrmPropertyHelperTrait;
19
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
20
use ApiPlatform\Metadata\Operation;
21
use Doctrine\ORM\QueryBuilder;
22
use Doctrine\Persistence\ManagerRegistry;
23
use Psr\Log\LoggerInterface;
24
use Psr\Log\NullLogger;
25
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
26

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

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

38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
42
    {
43
        foreach ($context['filters'] as $property => $value) {
18✔
44
            $this->filterProperty($this->denormalizePropertyName($property), $value, $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
12✔
45
        }
46
    }
47

48
    /**
49
     * Passes a property through the filter.
50
     *
51
     * @param class-string         $resourceClass
52
     * @param array<string, mixed> $context
53
     */
54
    abstract protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void;
55

56
    protected function getManagerRegistry(): ManagerRegistry
57
    {
58
        return $this->managerRegistry;
33✔
59
    }
60

61
    protected function getProperties(): ?array
62
    {
63
        return $this->properties;
33✔
64
    }
65

66
    protected function getLogger(): LoggerInterface
67
    {
68
        return $this->logger;
×
69
    }
70

71
    /**
72
     * @param string[] $properties
73
     */
74
    public function setProperties(array $properties): void
75
    {
76
        $this->properties = $properties;
9✔
77
    }
78

79
    /**
80
     * Determines whether the given property is enabled.
81
     */
82
    protected function isPropertyEnabled(string $property, string $resourceClass): bool
83
    {
84
        if (null === $this->properties) {
12✔
85
            // to ensure sanity, nested properties must still be explicitly enabled
86
            return !$this->isPropertyNested($property, $resourceClass);
×
87
        }
88

89
        return \array_key_exists($property, $this->properties);
12✔
90
    }
91

92
    protected function denormalizePropertyName(string|int $property): string
93
    {
94
        if (!$this->nameConverter instanceof NameConverterInterface) {
12✔
95
            return (string) $property;
×
96
        }
97

98
        return implode('.', array_map($this->nameConverter->denormalize(...), explode('.', (string) $property)));
12✔
99
    }
100

101
    protected function normalizePropertyName(string $property): string
102
    {
103
        if (!$this->nameConverter instanceof NameConverterInterface) {
33✔
104
            return $property;
×
105
        }
106

107
        return implode('.', array_map($this->nameConverter->normalize(...), explode('.', $property)));
33✔
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