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

api-platform / core / 9663895513

25 Jun 2024 02:01PM UTC coverage: 62.122% (-0.5%) from 62.637%
9663895513

push

github

web-flow
feat(laravel): laravel component (#5882)

* feat(laravel): laravel component

* try to skip laravel

* feat(jsonapi): component

* feat(laravel): json api support (needs review)

* work on relations

* relations (needs toMany) + skolem + IRI to resource

* links handler

* ulid

* validation

* slug post

* remove deprecations

* move classes

* fix tests

* fix tests metadata

* phpstan

* missing class

* fix laravel tests

* fix stan

33 of 77 new or added lines in 20 files covered. (42.86%)

140 existing lines in 15 files now uncovered.

10862 of 17485 relevant lines covered (62.12%)

59.64 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
    {
31
        if (!\array_key_exists($name, $queryParameters)) {
×
32
            return [];
×
33
        }
34

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

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

41
        $errorList = [];
×
42

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

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

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

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

58
        return $errorList;
×
59
    }
60

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

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

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

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

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
    {
83
        return match ($collectionFormat) {
×
84
            'csv' => ',',
×
85
            'ssv' => ' ',
×
86
            'tsv' => '\t',
×
87
            'pipes' => '|',
×
88
            default => throw new \InvalidArgumentException(sprintf('Unknown collection format %s', $collectionFormat)),
×
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