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

api-platform / core / 17155082657

22 Aug 2025 12:19PM UTC coverage: 22.017% (-0.2%) from 22.209%
17155082657

Pull #7121

github

web-flow
Merge 57bd1a784 into 9e382e01b
Pull Request #7121: feat(doctrine): new search filters

44 of 99 new or added lines in 11 files covered. (44.44%)

125 existing lines in 11 files now uncovered.

11619 of 52774 relevant lines covered (22.02%)

12.54 hits per line

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

0.0
/src/Doctrine/Odm/Filter/PartialSearchFilter.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\Filter;
15

16
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
17
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
18
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
19
use ApiPlatform\Metadata\Operation;
20
use Doctrine\ODM\MongoDB\Aggregation\Builder;
21
use MongoDB\BSON\Regex;
22

23
/**
24
 * @author Vincent Amstoutz <vincent.amstoutz.dev@gmail.com>
25
 */
26
final class PartialSearchFilter implements FilterInterface, OpenApiParameterFilterInterface
27
{
28
    use BackwardCompatibleFilterDescriptionTrait;
29
    use OpenApiFilterTrait;
30

31
    public function apply(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
32
    {
NEW
33
        $parameter = $context['parameter'];
×
NEW
34
        $values = (array) $parameter->getValue();
×
35

NEW
36
        $property = $parameter->getProperty();
×
37

NEW
38
        if (1 === \count($values)) {
×
NEW
39
            $escapedValue = preg_quote((string) $values[0], '/');
×
NEW
40
            $aggregationBuilder
×
NEW
41
                ->match()
×
NEW
42
                ->field($property)
×
NEW
43
                ->equals(new Regex($escapedValue, 'i'));
×
44

NEW
45
            return;
×
46
        }
47

NEW
48
        $match = $aggregationBuilder->match();
×
NEW
49
        foreach ($values as $value) {
×
NEW
50
            $escapedValue = preg_quote((string) $value, '/');
×
51

NEW
52
            $match->addOr(
×
NEW
53
                $match->expr()
×
NEW
54
                    ->field($property)
×
NEW
55
                    ->equals(new Regex($escapedValue, 'i'))
×
NEW
56
            );
×
57
        }
58
    }
59
}
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