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

api-platform / core / 19337721455

13 Nov 2025 04:02PM UTC coverage: 0.0% (-24.6%) from 24.631%
19337721455

push

github

soyuka
Merge 4.1

0 of 56854 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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
    /**
26
     * @var array<int, array{0: string, 1: Parameter}>
27
     */
28
    private array $parameters = [];
29

30
    /**
31
     * @param array<int|string, Parameter> $parameters
32
     */
33
    public function __construct(array $parameters = [])
34
    {
35
        foreach ($parameters as $parameterName => $parameter) {
×
36
            if ($parameter->getKey()) {
×
37
                $parameterName = $parameter->getKey();
×
38
            }
39

40
            $key = \sprintf('%s.%s', $parameter::class, $parameterName);
×
41

42
            $this->parameters[$key] = [$parameterName, $parameter];
×
43
        }
44

45
        $this->parameters = array_values($this->parameters);
×
46

47
        $this->sort();
×
48
    }
49

50
    /**
51
     * @return \ArrayIterator<string, Parameter>
52
     */
53
    public function getIterator(): \Traversable
54
    {
55
        return (function (): \Generator {
×
56
            foreach ($this->parameters as [$parameterName, $parameter]) {
×
57
                yield $parameterName => $parameter;
×
58
            }
59
        })();
×
60
    }
61

62
    public function add(string $key, Parameter $value): self
63
    {
64
        foreach ($this->parameters as $i => [$parameterName, $parameter]) {
×
65
            if ($parameterName === $key && $value::class === $parameter::class) {
×
66
                $this->parameters[$i] = [$key, $value];
×
67

68
                return $this;
×
69
            }
70
        }
71

72
        $this->parameters[] = [$key, $value];
×
73

74
        return $this;
×
75
    }
76

77
    /**
78
     * @template T of Parameter
79
     *
80
     * @param class-string<T> $parameterClass
81
     */
82
    public function remove(string $key, string $parameterClass = QueryParameter::class): self
83
    {
84
        foreach ($this->parameters as $i => [$parameterName, $parameter]) {
×
85
            if ($parameterName === $key && $parameterClass === $parameter::class) {
×
86
                unset($this->parameters[$i]);
×
87

88
                return $this;
×
89
            }
90
        }
91

92
        throw new RuntimeException(\sprintf('Could not remove parameter "%s".', $key));
×
93
    }
94

95
    /**
96
     * @template T of Parameter
97
     *
98
     * @param class-string<T> $parameterClass
99
     *
100
     * @return T|null
101
     */
102
    public function get(string $key, string $parameterClass = QueryParameter::class): ?Parameter
103
    {
104
        foreach ($this->parameters as [$parameterName, $parameter]) {
×
105
            if ($parameterName === $key && $parameterClass === $parameter::class) {
×
106
                return $parameter;
×
107
            }
108
        }
109

110
        return null;
×
111
    }
112

113
    /**
114
     * @template T of Parameter
115
     *
116
     * @param class-string<T> $parameterClass
117
     */
118
    public function has(string $key, string $parameterClass = QueryParameter::class): bool
119
    {
120
        foreach ($this->parameters as [$parameterName, $parameter]) {
×
121
            if ($parameterName === $key && $parameterClass === $parameter::class) {
×
122
                return true;
×
123
            }
124
        }
125

126
        return false;
×
127
    }
128

129
    public function count(): int
130
    {
131
        return \count($this->parameters);
×
132
    }
133

134
    public function sort(): self
135
    {
136
        usort($this->parameters, static fn (array $a, array $b): int => $b[1]->getPriority() - $a[1]->getPriority());
×
137

138
        return $this;
×
139
    }
140
}
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