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

api-platform / core / 9838430407

08 Jul 2024 11:06AM UTC coverage: 64.738% (-0.1%) from 64.857%
9838430407

push

github

web-flow
feat: deprecate query parameter validator (#6454)

51 of 60 new or added lines in 8 files covered. (85.0%)

34 existing lines in 10 files now uncovered.

11480 of 17733 relevant lines covered (64.74%)

68.99 hits per line

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

50.0
/src/ParameterValidator/ParameterValidator.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\ParameterValidator;
15

16
use ApiPlatform\ParameterValidator\Exception\ValidationException;
17
use ApiPlatform\ParameterValidator\Validator\ArrayItems;
18
use ApiPlatform\ParameterValidator\Validator\Bounds;
19
use ApiPlatform\ParameterValidator\Validator\Enum;
20
use ApiPlatform\ParameterValidator\Validator\Length;
21
use ApiPlatform\ParameterValidator\Validator\MultipleOf;
22
use ApiPlatform\ParameterValidator\Validator\Pattern;
23
use ApiPlatform\ParameterValidator\Validator\Required;
24
use Psr\Container\ContainerInterface;
25

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

35
    private array $validators;
36

37
    public function __construct(ContainerInterface $filterLocator)
38
    {
39
        $this->setFilterLocator($filterLocator);
428✔
40

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

52
    public function validateFilters(string $resourceClass, array $resourceFilters, array $queryParameters): void
53
    {
UNCOV
54
        $errorList = [];
×
55

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

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

UNCOV
70
        if ($errorList) {
×
71
            throw new ValidationException(array_merge(...$errorList));
×
72
        }
73
    }
74
}
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