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

api-platform / core / 20306196173

17 Dec 2025 02:27PM UTC coverage: 25.294% (-0.002%) from 25.296%
20306196173

push

github

web-flow
feat: enable to skip autoconfiguration with new `SkipAutoconfigure` attribute (#7467)

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

7803 existing lines in 234 files now uncovered.

14672 of 58006 relevant lines covered (25.29%)

29.35 hits per line

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

83.33
/src/Metadata/Operations.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
/**
17
 * An Operation dictionnary.
18
 *
19
 * @template-covariant T of Operation
20
 */
21
final class Operations implements \IteratorAggregate, \Countable
22
{
23
    /**
24
     * @var list<array{0: string, 1: T}>
25
     */
26
    private array $operations = [];
27

28
    /**
29
     * @param list<T>|array<string, T> $operations
30
     */
31
    public function __construct(array $operations = [])
32
    {
UNCOV
33
        foreach ($operations as $operationName => $operation) {
234✔
34
            // When we use an int-indexed array in the constructor, compute priorities
UNCOV
35
            if (\is_int($operationName) && null === $operation->getPriority()) {
224✔
UNCOV
36
                $operation = $operation->withPriority($operationName);
86✔
UNCOV
37
                $operationName = (string) $operationName;
86✔
38
            }
39

UNCOV
40
            if ($operation->getName()) {
224✔
UNCOV
41
                $operationName = $operation->getName();
142✔
42
            }
43

UNCOV
44
            $this->operations[] = [$operationName, $operation];
224✔
45
        }
46

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

50
    /**
51
     * @return \Iterator<string, T>
52
     */
53
    public function getIterator(): \Traversable
54
    {
UNCOV
55
        return (function (): \Generator {
924✔
UNCOV
56
            foreach ($this->operations as [$operationName, $operation]) {
924✔
UNCOV
57
                yield $operationName => $operation;
920✔
58
            }
UNCOV
59
        })();
924✔
60
    }
61

62
    public function add(string $key, Operation $value): self
63
    {
UNCOV
64
        foreach ($this->operations as $i => [$operationName, $operation]) {
136✔
UNCOV
65
            if ($operationName === $key) {
136✔
UNCOV
66
                $this->operations[$i] = [$key, $value];
130✔
67

UNCOV
68
                return $this;
130✔
69
            }
70
        }
71

UNCOV
72
        $this->operations[] = [$key, $value];
136✔
73

UNCOV
74
        return $this;
136✔
75
    }
76

77
    public function remove(string $key): self
78
    {
UNCOV
79
        foreach ($this->operations as $i => [$operationName, $operation]) {
2✔
UNCOV
80
            if ($operationName === $key) {
2✔
UNCOV
81
                unset($this->operations[$i]);
2✔
82

UNCOV
83
                return $this;
2✔
84
            }
85
        }
86

87
        throw new \RuntimeException(\sprintf('Could not remove operation "%s".', $key));
×
88
    }
89

90
    public function has(string $key): bool
91
    {
92
        foreach ($this->operations as $i => [$operationName, $operation]) {
×
93
            if ($operationName === $key) {
×
94
                return true;
×
95
            }
96
        }
97

98
        return false;
×
99
    }
100

101
    public function count(): int
102
    {
UNCOV
103
        return \count($this->operations);
60✔
104
    }
105

106
    public function sort(): self
107
    {
UNCOV
108
        usort($this->operations, fn ($a, $b): int => $a[1]->getPriority() - $b[1]->getPriority());
234✔
109

UNCOV
110
        return $this;
234✔
111
    }
112
}
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