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

api-platform / core / 3713134090

pending completion
3713134090

Pull #5254

github

GitHub
Merge b2ec54b3c into ac711530f
Pull Request #5254: [OpenApi] Add ApiResource::openapi and deprecate openapiContext

197 of 197 new or added lines in 5 files covered. (100.0%)

7493 of 12362 relevant lines covered (60.61%)

67.56 hits per line

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

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

16
use ApiPlatform\Doctrine\Common\Filter\NumericFilterTrait;
17
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
18
use ApiPlatform\Metadata\Operation;
19
use Doctrine\DBAL\Types\Types;
20
use Doctrine\ORM\Query\Expr\Join;
21
use Doctrine\ORM\QueryBuilder;
22

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

38
    /**
39
     * Type of numeric in Doctrine.
40
     *
41
     * @see http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/types.html
42
     */
43
    public const DOCTRINE_NUMERIC_TYPES = [
44
        Types::BIGINT => true,
45
        Types::DECIMAL => true,
46
        Types::FLOAT => true,
47
        Types::INTEGER => true,
48
        Types::SMALLINT => true,
49
    ];
50

51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void
55
    {
56
        if (
×
57
            !$this->isPropertyEnabled($property, $resourceClass) ||
×
58
            !$this->isPropertyMapped($property, $resourceClass) ||
×
59
            !$this->isNumericField($property, $resourceClass)
×
60
        ) {
61
            return;
×
62
        }
63

64
        $values = $this->normalizeValues($value, $property);
×
65
        if (null === $values) {
×
66
            return;
×
67
        }
68

69
        $alias = $queryBuilder->getRootAliases()[0];
×
70
        $field = $property;
×
71

72
        if ($this->isPropertyNested($property, $resourceClass)) {
×
73
            [$alias, $field] = $this->addJoinsForNestedProperty($property, $alias, $queryBuilder, $queryNameGenerator, $resourceClass, Join::INNER_JOIN);
×
74
        }
75

76
        $valueParameter = $queryNameGenerator->generateParameterName($field);
×
77

78
        if (1 === \count($values)) {
×
79
            $queryBuilder
80
                ->andWhere(sprintf('%s.%s = :%s', $alias, $field, $valueParameter))
×
81
                ->setParameter($valueParameter, $values[0], (string) $this->getDoctrineFieldType($property, $resourceClass));
×
82
        } else {
×
83
            $queryBuilder
84
                ->andWhere(sprintf('%s.%s IN (:%s)', $alias, $field, $valueParameter))
×
85
                ->setParameter($valueParameter, $values);
×
86
        }
87
    }
88

89
    /**
90
     * {@inheritdoc}
91
     */
92
    protected function getType(string $doctrineType = null): string
93
    {
94
        if (null === $doctrineType || Types::DECIMAL === $doctrineType) {
×
95
            return 'string';
×
96
        }
97

98
        if (Types::FLOAT === $doctrineType) {
×
99
            return 'float';
×
100
        }
101

102
        return 'int';
×
103
    }
104
}
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