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

api-platform / core / 10943429050

19 Sep 2024 02:48PM UTC coverage: 7.647% (-0.03%) from 7.675%
10943429050

push

github

web-flow
feat: api-platform/json-hal component (#6621)

* feat: add hal support for laravel

* feat: quick review

* fix: typo & cs-fixer

* fix: typo in composer.json

* fix: cs-fixer & phpstan

* fix: forgot about hal item normalizer, therefore there's no more createbook nor updatebook test as Hal is a readonly format

0 of 94 new or added lines in 2 files covered. (0.0%)

9082 existing lines in 291 files now uncovered.

12629 of 165144 relevant lines covered (7.65%)

22.89 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) {
34✔
29
            // When we use an int-indexed array in the constructor, compute priorities
UNCOV
30
            if (\is_int($operationName) && null === $operation->getPriority()) {
34✔
UNCOV
31
                $operation = $operation->withPriority($operationName);
31✔
UNCOV
32
                $operationName = (string) $operationName;
31✔
33
            }
34

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

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

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

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

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

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

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

UNCOV
66
        return $this;
34✔
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);
39✔
96
    }
97

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

UNCOV
102
        return $this;
34✔
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