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

api-platform / core / 12691826531

09 Jan 2025 02:22PM UTC coverage: 61.963% (-0.2%) from 62.121%
12691826531

push

github

web-flow
 chore: add missing deprecation notices to ParameterValidator  (#6655)

Co-authored-by: soyuka <soyuka@users.noreply.github.com>

2 of 11 new or added lines in 11 files covered. (18.18%)

25 existing lines in 4 files now uncovered.

11475 of 18519 relevant lines covered (61.96%)

68.04 hits per line

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

0.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
 * @deprecated use \ApiPlatform\Metadata\Parameter::$constraints instead
30
 *
31
 * @author Julien Deniau <julien.deniau@gmail.com>
32
 */
33
class ParameterValidator
34
{
35
    use FilterLocatorTrait;
36

37
    private array $validators;
38

39
    public function __construct(ContainerInterface $filterLocator)
40
    {
NEW
41
        trigger_deprecation('api-platform/core', '3.4', 'The class "%s" is deprecated, use "\ApiPlatform\Metadata\Parameter::$constraints" instead.', __CLASS__);
×
42

UNCOV
43
        $this->setFilterLocator($filterLocator);
×
44

UNCOV
45
        $this->validators = [
×
UNCOV
46
            new ArrayItems(),
×
UNCOV
47
            new Bounds(),
×
UNCOV
48
            new Enum(),
×
UNCOV
49
            new Length(),
×
UNCOV
50
            new MultipleOf(),
×
UNCOV
51
            new Pattern(),
×
UNCOV
52
            new Required(),
×
UNCOV
53
        ];
×
54
    }
55

56
    public function validateFilters(string $resourceClass, array $resourceFilters, array $queryParameters): void
57
    {
58
        $errorList = [];
×
59

60
        foreach ($resourceFilters as $filterId) {
×
61
            if (!$filter = $this->getFilter($filterId)) {
×
62
                continue;
×
63
            }
64

65
            foreach ($filter->getDescription($resourceClass) as $name => $data) {
×
66
                foreach ($this->validators as $validator) {
×
67
                    if ($errors = $validator->validate($name, $data, $queryParameters)) {
×
68
                        $errorList[] = $errors;
×
69
                    }
70
                }
71
            }
72
        }
73

74
        if ($errorList) {
×
75
            throw new ValidationException(array_merge(...$errorList));
×
76
        }
77
    }
78
}
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