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

api-platform / core / 10739011304

06 Sep 2024 01:11PM UTC coverage: 7.159% (-0.5%) from 7.645%
10739011304

push

github

web-flow
 feat(laravel): eloquent filters (search, date, equals, or) (#6593)

* feat(laravel): Eloquent filters search date or

* feat(laravel): eloquent filters order range equals afterdate

* fix(laravel): order afterDate filters

* temp

* test(laravel): filter with eloquent

---------

Co-authored-by: Nathan <nathan@les-tilleuls.coop>

0 of 144 new or added lines in 16 files covered. (0.0%)

4792 existing lines in 155 files now uncovered.

11736 of 163930 relevant lines covered (7.16%)

22.8 hits per line

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

100.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
    {
UNCOV
35
        $this->logger = $logger ?? new NullLogger();
682✔
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) {
177✔
44
            $this->filterProperty($this->denormalizePropertyName($property), $value, $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
150✔
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
    {
UNCOV
58
        return $this->managerRegistry;
565✔
59
    }
60

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

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

71
    /**
72
     * @param string[] $properties
73
     */
74
    public function setProperties(array $properties): void
75
    {
76
        $this->properties = $properties;
144✔
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) {
137✔
85
            // to ensure sanity, nested properties must still be explicitly enabled
86
            return !$this->isPropertyNested($property, $resourceClass);
3✔
87
        }
88

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

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

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

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

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

© 2026 Coveralls, Inc