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

api-platform / core / 7407219156

04 Jan 2024 08:32AM UTC coverage: 35.357% (-1.9%) from 37.257%
7407219156

push

github

soyuka
cs: various fixes

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

425 existing lines in 27 files now uncovered.

10237 of 28953 relevant lines covered (35.36%)

27.07 hits per line

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

0.0
/src/Api/QueryParameterValidator/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\Api\QueryParameterValidator\Validator;
15

16
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18

19
/**
20
 * @deprecated use \ApiPlatform\ParameterValidator\Validator\ArrayItems instead
21
 */
22
final class ArrayItems implements ValidatorInterface
23
{
24
    use CheckFilterDeprecationsTrait;
25

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

UNCOV
35
        $this->checkFilterDeprecations($filterDescription);
×
36

UNCOV
37
        $maxItems = $filterDescription['openapi']['maxItems'] ?? $filterDescription['swagger']['maxItems'] ?? null;
×
UNCOV
38
        $minItems = $filterDescription['openapi']['minItems'] ?? $filterDescription['swagger']['minItems'] ?? null;
×
UNCOV
39
        $uniqueItems = $filterDescription['openapi']['uniqueItems'] ?? $filterDescription['swagger']['uniqueItems'] ?? false;
×
40

UNCOV
41
        $errorList = [];
×
42

UNCOV
43
        $value = $this->getValue($name, $filterDescription, $queryParameters);
×
UNCOV
44
        $nbItems = \count($value);
×
45

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

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

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

UNCOV
58
        return $errorList;
×
59
    }
60

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

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

UNCOV
69
        if (\is_array($value)) {
×
UNCOV
70
            return $value;
×
71
        }
72

UNCOV
73
        $collectionFormat = $filterDescription['openapi']['collectionFormat'] ?? $filterDescription['swagger']['collectionFormat'] ?? 'csv';
×
74

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

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