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

api-platform / core / 16531587208

25 Jul 2025 09:05PM UTC coverage: 0.0% (-22.1%) from 22.07%
16531587208

Pull #7225

github

web-flow
Merge 23f449a58 into 02a764950
Pull Request #7225: feat: json streamer

0 of 294 new or added lines in 31 files covered. (0.0%)

11514 existing lines in 375 files now uncovered.

0 of 51976 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/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) {
×
34
            // When we use an int-indexed array in the constructor, compute priorities
UNCOV
35
            if (\is_int($operationName) && null === $operation->getPriority()) {
×
UNCOV
36
                $operation = $operation->withPriority($operationName);
×
UNCOV
37
                $operationName = (string) $operationName;
×
38
            }
39

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

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

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

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

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

UNCOV
68
                return $this;
×
69
            }
70
        }
71

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

UNCOV
74
        return $this;
×
75
    }
76

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

83
                return $this;
×
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);
×
104
    }
105

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

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

© 2025 Coveralls, Inc