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

api-platform / core / 4894398962

pending completion
4894398962

push

github

soyuka
chore: v3.1.11 changelog

10790 of 18096 relevant lines covered (59.63%)

10.06 hits per line

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

0.0
/src/Doctrine/Odm/Filter/NumericFilter.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\NumericFilterTrait;
17
use ApiPlatform\Metadata\Operation;
18
use Doctrine\ODM\MongoDB\Aggregation\Builder;
19
use Doctrine\ODM\MongoDB\Types\Type as MongoDbType;
20

21
/**
22
 * Filters the collection by numeric values.
23
 *
24
 * Filters collection by equality of numeric properties.
25
 *
26
 * For each property passed, if the resource does not have such property or if
27
 * the value is not numeric, the property is ignored.
28
 *
29
 * @author Amrouche Hamza <hamza.simperfit@gmail.com>
30
 * @author Teoh Han Hui <teohhanhui@gmail.com>
31
 * @author Alan Poulain <contact@alanpoulain.eu>
32
 */
33
final class NumericFilter extends AbstractFilter
34
{
35
    use NumericFilterTrait;
36

37
    /**
38
     * Type of numeric in Doctrine.
39
     */
40
    public const DOCTRINE_NUMERIC_TYPES = [
41
        MongoDbType::INT => true,
42
        MongoDbType::INTEGER => true,
43
        MongoDbType::FLOAT => true,
44
    ];
45

46
    /**
47
     * {@inheritdoc}
48
     */
49
    protected function filterProperty(string $property, $value, Builder $aggregationBuilder, string $resourceClass, Operation $operation = null, array &$context = []): void
50
    {
51
        if (
52
            !$this->isPropertyEnabled($property, $resourceClass)
×
53
            || !$this->isPropertyMapped($property, $resourceClass)
×
54
            || !$this->isNumericField($property, $resourceClass)
×
55
        ) {
56
            return;
×
57
        }
58

59
        $values = $this->normalizeValues($value, $property);
×
60
        if (null === $values) {
×
61
            return;
×
62
        }
63

64
        $matchField = $property;
×
65

66
        if ($this->isPropertyNested($property, $resourceClass)) {
×
67
            [$matchField] = $this->addLookupsForNestedProperty($property, $aggregationBuilder, $resourceClass);
×
68
        }
69

70
        if (1 === \count($values)) {
×
71
            $aggregationBuilder->match()->field($matchField)->equals($values[0]);
×
72
        } else {
73
            $aggregationBuilder->match()->field($matchField)->in($values);
×
74
        }
75
    }
76

77
    /**
78
     * {@inheritdoc}
79
     */
80
    protected function getType(string $doctrineType = null): string
81
    {
82
        if (null === $doctrineType) {
×
83
            return 'string';
×
84
        }
85

86
        if (MongoDbType::FLOAT === $doctrineType) {
×
87
            return 'float';
×
88
        }
89

90
        return 'int';
×
91
    }
92
}
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