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

api-platform / core / 13200284839

07 Feb 2025 12:56PM UTC coverage: 0.0% (-8.2%) from 8.164%
13200284839

Pull #6952

github

web-flow
Merge 519fbf8cc into 62377f880
Pull Request #6952: fix: errors retrieval and documentation

0 of 206 new or added lines in 17 files covered. (0.0%)

10757 existing lines in 366 files now uncovered.

0 of 47781 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
    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) {
×
UNCOV
33
            if ($parameter->getKey()) {
×
UNCOV
34
                $parameterName = $parameter->getKey();
×
35
            }
36

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

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

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

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

UNCOV
61
                return $this;
×
62
            }
63
        }
64

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

UNCOV
67
        return $this;
×
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]) {
×
UNCOV
76
            if ($parameterName === $key && $parameterClass === $parameter::class) {
×
UNCOV
77
                unset($this->parameters[$i]);
×
78

UNCOV
79
                return $this;
×
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]) {
×
UNCOV
92
            if ($parameterName === $key && $parameterClass === $parameter::class) {
×
UNCOV
93
                return $parameter;
×
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]) {
×
UNCOV
106
            if ($parameterName === $key && $parameterClass === $parameter::class) {
×
UNCOV
107
                return true;
×
108
            }
109
        }
110

UNCOV
111
        return false;
×
112
    }
113

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

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

UNCOV
123
        return $this;
×
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

© 2025 Coveralls, Inc