• 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/Validator/ArrayItems.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\Validator;
15

16
/**
17
 * @deprecated use \ApiPlatform\Metadata\Parameter::$constraints instead
18
 */
19
final class ArrayItems implements ValidatorInterface
20
{
21
    use CheckFilterDeprecationsTrait;
22

23
    public function __construct()
24
    {
NEW
25
        trigger_deprecation('api-platform/core', '3.4', 'The class "%s" is deprecated, use "\ApiPlatform\Metadata\Parameter::$constraints" instead.', __CLASS__);
×
26
    }
27

28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function validate(string $name, array $filterDescription, array $queryParameters): array
32
    {
33
        if (!\array_key_exists($name, $queryParameters)) {
×
34
            return [];
×
35
        }
36

37
        $this->checkFilterDeprecations($filterDescription);
×
38

39
        $maxItems = $filterDescription['openapi']['maxItems'] ?? $filterDescription['swagger']['maxItems'] ?? null;
×
40
        $minItems = $filterDescription['openapi']['minItems'] ?? $filterDescription['swagger']['minItems'] ?? null;
×
41
        $uniqueItems = $filterDescription['openapi']['uniqueItems'] ?? $filterDescription['swagger']['uniqueItems'] ?? false;
×
42

43
        $errorList = [];
×
44

45
        $value = $this->getValue($name, $filterDescription, $queryParameters);
×
46
        $nbItems = \count($value);
×
47

48
        if (null !== $maxItems && $nbItems > $maxItems) {
×
49
            $errorList[] = \sprintf('Query parameter "%s" must contain less than %d values', $name, $maxItems);
×
50
        }
51

52
        if (null !== $minItems && $nbItems < $minItems) {
×
53
            $errorList[] = \sprintf('Query parameter "%s" must contain more than %d values', $name, $minItems);
×
54
        }
55

56
        if (true === $uniqueItems && $nbItems > \count(array_unique($value))) {
×
57
            $errorList[] = \sprintf('Query parameter "%s" must contain unique values', $name);
×
58
        }
59

60
        return $errorList;
×
61
    }
62

63
    private function getValue(string $name, array $filterDescription, array $queryParameters): array
64
    {
65
        $value = $queryParameters[$name] ?? null;
×
66

67
        if (empty($value) && '0' !== $value) {
×
68
            return [];
×
69
        }
70

71
        if (\is_array($value)) {
×
72
            return $value;
×
73
        }
74

75
        $collectionFormat = $filterDescription['openapi']['collectionFormat'] ?? $filterDescription['swagger']['collectionFormat'] ?? 'csv';
×
76

77
        return explode(self::getSeparator($collectionFormat), (string) $value) ?: []; // @phpstan-ignore-line
×
78
    }
79

80
    /**
81
     * @return non-empty-string
82
     */
83
    private static function getSeparator(string $collectionFormat): string
84
    {
85
        return match ($collectionFormat) {
×
86
            'csv' => ',',
×
87
            'ssv' => ' ',
×
88
            'tsv' => '\t',
×
89
            'pipes' => '|',
×
90
            default => throw new \InvalidArgumentException(\sprintf('Unknown collection format %s', $collectionFormat)),
×
91
        };
×
92
    }
93
}
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