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

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

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

95.0
/src/Api/QueryParameterValidator/QueryParameterValidator.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\Api\QueryParameterValidator;
15

16
use ApiPlatform\Api\FilterLocatorTrait;
17
use ApiPlatform\Api\QueryParameterValidator\Validator\ArrayItems;
18
use ApiPlatform\Api\QueryParameterValidator\Validator\Bounds;
19
use ApiPlatform\Api\QueryParameterValidator\Validator\Enum;
20
use ApiPlatform\Api\QueryParameterValidator\Validator\Length;
21
use ApiPlatform\Api\QueryParameterValidator\Validator\MultipleOf;
22
use ApiPlatform\Api\QueryParameterValidator\Validator\Pattern;
23
use ApiPlatform\Api\QueryParameterValidator\Validator\Required;
24
use ApiPlatform\Exception\FilterValidationException;
25
use Psr\Container\ContainerInterface;
26

27
/**
28
 * Validates query parameters depending on filter description.
29
 *
30
 * @author Julien Deniau <julien.deniau@gmail.com>
31
 */
32
class QueryParameterValidator
33
{
34
    use FilterLocatorTrait;
35

36
    private array $validators;
37

38
    public function __construct(ContainerInterface $filterLocator)
39
    {
40
        $this->setFilterLocator($filterLocator);
2,496✔
41

42
        $this->validators = [
2,496✔
43
            new ArrayItems(),
2,496✔
44
            new Bounds(),
2,496✔
45
            new Enum(),
2,496✔
46
            new Length(),
2,496✔
47
            new MultipleOf(),
2,496✔
48
            new Pattern(),
2,496✔
49
            new Required(),
2,496✔
50
        ];
2,496✔
51
    }
52

53
    public function validateFilters(string $resourceClass, array $resourceFilters, array $queryParameters): void
54
    {
55
        $errorList = [];
831✔
56

57
        foreach ($resourceFilters as $filterId) {
831✔
58
            if (!$filter = $this->getFilter($filterId)) {
540✔
UNCOV
59
                continue;
×
60
            }
61

62
            foreach ($filter->getDescription($resourceClass) as $name => $data) {
540✔
63
                foreach ($this->validators as $validator) {
537✔
64
                    if ($errors = $validator->validate($name, $data, $queryParameters)) {
537✔
65
                        $errorList[] = $errors;
57✔
66
                    }
67
                }
68
            }
69
        }
70

71
        if ($errorList) {
831✔
72
            throw new FilterValidationException(array_merge(...$errorList));
57✔
73
        }
74
    }
75
}
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