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

api-platform / core / 13471447230

22 Feb 2025 09:00AM UTC coverage: 8.516%. Remained the same
13471447230

push

github

web-flow
feat: add checkMode parameter to control json schema validation (#6974)

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

10870 existing lines in 366 files now uncovered.

13370 of 156994 relevant lines covered (8.52%)

22.87 hits per line

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

93.55
/src/Metadata/Parameters.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\Metadata;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17

18
/**
19
 * A parameter dictionnary.
20
 *
21
 * @implements \IteratorAggregate<string, Parameter>
22
 */
23
final class Parameters implements \IteratorAggregate, \Countable
24
{
25
    private array $parameters = [];
26

27
    /**
28
     * @param array<int|string, Parameter> $parameters
29
     */
30
    public function __construct(array $parameters = [])
31
    {
UNCOV
32
        foreach ($parameters as $parameterName => $parameter) {
141✔
UNCOV
33
            if ($parameter->getKey()) {
29✔
UNCOV
34
                $parameterName = $parameter->getKey();
4✔
35
            }
36

UNCOV
37
            $this->parameters[] = [$parameterName, $parameter];
29✔
38
        }
39

UNCOV
40
        $this->sort();
141✔
41
    }
42

43
    /**
44
     * @return \ArrayIterator<string, Parameter>
45
     */
46
    public function getIterator(): \Traversable
47
    {
UNCOV
48
        return (function (): \Generator {
1,141✔
UNCOV
49
            foreach ($this->parameters as [$parameterName, $parameter]) {
1,141✔
UNCOV
50
                yield $parameterName => $parameter;
1,062✔
51
            }
UNCOV
52
        })();
1,141✔
53
    }
54

55
    public function add(string $key, Parameter $value): self
56
    {
UNCOV
57
        foreach ($this->parameters as $i => [$parameterName, $parameter]) {
747✔
UNCOV
58
            if ($parameterName === $key && $value::class === $parameter::class) {
747✔
UNCOV
59
                $this->parameters[$i] = [$key, $value];
741✔
60

UNCOV
61
                return $this;
741✔
62
            }
63
        }
64

UNCOV
65
        $this->parameters[] = [$key, $value];
29✔
66

UNCOV
67
        return $this;
29✔
68
    }
69

70
    /**
71
     * @param class-string $parameterClass
72
     */
73
    public function remove(string $key, string $parameterClass = QueryParameter::class): self
74
    {
UNCOV
75
        foreach ($this->parameters as $i => [$parameterName, $parameter]) {
4✔
UNCOV
76
            if ($parameterName === $key && $parameterClass === $parameter::class) {
4✔
UNCOV
77
                unset($this->parameters[$i]);
4✔
78

UNCOV
79
                return $this;
4✔
80
            }
81
        }
82

83
        throw new RuntimeException(\sprintf('Could not remove parameter "%s".', $key));
×
84
    }
85

86
    /**
87
     * @param class-string $parameterClass
88
     */
89
    public function get(string $key, string $parameterClass = QueryParameter::class): ?Parameter
90
    {
UNCOV
91
        foreach ($this->parameters as [$parameterName, $parameter]) {
2✔
UNCOV
92
            if ($parameterName === $key && $parameterClass === $parameter::class) {
2✔
UNCOV
93
                return $parameter;
2✔
94
            }
95
        }
96

97
        return null;
×
98
    }
99

100
    /**
101
     * @param class-string $parameterClass
102
     */
103
    public function has(string $key, string $parameterClass = QueryParameter::class): bool
104
    {
UNCOV
105
        foreach ($this->parameters as [$parameterName, $parameter]) {
6✔
UNCOV
106
            if ($parameterName === $key && $parameterClass === $parameter::class) {
6✔
UNCOV
107
                return true;
4✔
108
            }
109
        }
110

UNCOV
111
        return false;
6✔
112
    }
113

114
    public function count(): int
115
    {
UNCOV
116
        return \count($this->parameters);
302✔
117
    }
118

119
    public function sort(): self
120
    {
UNCOV
121
        usort($this->parameters, fn ($a, $b): int|float => $b[1]->getPriority() - $a[1]->getPriority());
141✔
122

UNCOV
123
        return $this;
141✔
124
    }
125
}
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