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

api-platform / core / 18974957045

31 Oct 2025 02:04PM UTC coverage: 24.541% (-0.06%) from 24.603%
18974957045

push

github

web-flow
Merge 4.1 (#7499)

Co-authored-by: Nicolas LAURENT <aegypius@users.noreply.github.com>
Co-authored-by: Javier Sampedro <jsampedro77@gmail.com>
fix(laravel): serializer attributes on Eloquent methods (#7416)
fixes #7289
fixes #7338
fix(validator): custom message was not translated (#7424)
fixes #7336
fix(serializer): resilient denormalizeRelation capability (#7474)
fix(doctrine): properly set properties according to interface (#7487)
fix(graphql): stateOptions to get filter class (#7485)

11 of 232 new or added lines in 20 files covered. (4.74%)

28 existing lines in 6 files now uncovered.

14064 of 57309 relevant lines covered (24.54%)

26.35 hits per line

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

93.94
/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) {
389✔
36
            if ($parameter->getKey()) {
34✔
37
                $parameterName = $parameter->getKey();
2✔
38
            }
39

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

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

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

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

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

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

68
                return $this;
42✔
69
            }
70
        }
71

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

74
        return $this;
246✔
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]) {
2✔
85
            if ($parameterName === $key && $parameterClass === $parameter::class) {
2✔
86
                unset($this->parameters[$i]);
2✔
87

88
                return $this;
2✔
89
            }
90
        }
91

UNCOV
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]) {
20✔
105
            if ($parameterName === $key && $parameterClass === $parameter::class) {
20✔
106
                return $parameter;
20✔
107
            }
108
        }
109

UNCOV
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]) {
4✔
121
            if ($parameterName === $key && $parameterClass === $parameter::class) {
4✔
122
                return true;
2✔
123
            }
124
        }
125

126
        return false;
4✔
127
    }
128

129
    public function count(): int
130
    {
131
        return \count($this->parameters);
336✔
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());
389✔
137

138
        return $this;
389✔
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