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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

70.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
final class Operations implements \IteratorAggregate, \Countable
20
{
21
    private array $operations = [];
22

23
    /**
24
     * @param array<string|int, Operation> $operations
25
     */
26
    public function __construct(array $operations = [])
27
    {
UNCOV
28
        foreach ($operations as $operationName => $operation) {
128✔
29
            // When we use an int-indexed array in the constructor, compute priorities
UNCOV
30
            if (\is_int($operationName) && null === $operation->getPriority()) {
123✔
UNCOV
31
                $operation = $operation->withPriority($operationName);
50✔
UNCOV
32
                $operationName = (string) $operationName;
50✔
33
            }
34

UNCOV
35
            if ($operation->getName()) {
123✔
UNCOV
36
                $operationName = $operation->getName();
78✔
37
            }
38

UNCOV
39
            $this->operations[] = [$operationName, $operation];
123✔
40
        }
41

UNCOV
42
        $this->sort();
128✔
43
    }
44

45
    public function getIterator(): \Traversable
46
    {
UNCOV
47
        return (function (): \Generator {
1,017✔
UNCOV
48
            foreach ($this->operations as [$operationName, $operation]) {
1,017✔
UNCOV
49
                yield $operationName => $operation;
1,015✔
50
            }
UNCOV
51
        })();
1,017✔
52
    }
53

54
    public function add(string $key, Operation $value): self
55
    {
UNCOV
56
        foreach ($this->operations as $i => [$operationName, $operation]) {
68✔
UNCOV
57
            if ($operationName === $key) {
68✔
UNCOV
58
                $this->operations[$i] = [$key, $value];
65✔
59

UNCOV
60
                return $this;
65✔
61
            }
62
        }
63

UNCOV
64
        $this->operations[] = [$key, $value];
68✔
65

UNCOV
66
        return $this;
68✔
67
    }
68

69
    public function remove(string $key): self
70
    {
71
        foreach ($this->operations as $i => [$operationName, $operation]) {
×
72
            if ($operationName === $key) {
×
73
                unset($this->operations[$i]);
×
74

75
                return $this;
×
76
            }
77
        }
78

79
        throw new \RuntimeException(\sprintf('Could not remove operation "%s".', $key));
×
80
    }
81

82
    public function has(string $key): bool
83
    {
84
        foreach ($this->operations as $i => [$operationName, $operation]) {
×
85
            if ($operationName === $key) {
×
86
                return true;
×
87
            }
88
        }
89

90
        return false;
×
91
    }
92

93
    public function count(): int
94
    {
UNCOV
95
        return \count($this->operations);
25✔
96
    }
97

98
    public function sort(): self
99
    {
UNCOV
100
        usort($this->operations, fn ($a, $b): int|float => $a[1]->getPriority() - $b[1]->getPriority());
128✔
101

UNCOV
102
        return $this;
128✔
103
    }
104
}
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