Passed
Pull Request — 2.x (#263)
by Akihito
01:29
created

Map::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\MultiBinding;
6
7
use ArrayAccess;
8
use Countable;
9
use Generator;
10
use Iterator;
11
use IteratorAggregate;
12
use LogicException;
13
use Ray\Di\InjectorInterface;
14
use ReturnTypeWillChange;
0 ignored issues
show
Bug introduced by
The type ReturnTypeWillChange was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
use function array_key_exists;
17
use function count;
18
19
final class Map implements IteratorAggregate, ArrayAccess, Countable
20
{
21
    /** @var array<string, Lazy> $lazies */
22
    private $lazies;
23
24
    /** @var InjectorInterface */
25
    private $injector;
26
27
    /**
28
     * @param array<string, Lazy> $lazies
29
     */
30
    public function __construct(array $lazies, InjectorInterface $injector)
31
    {
32
        $this->lazies = $lazies;
33
        $this->injector = $injector;
34
    }
35
36
    /**
37
     * @param string $offset
38
     *
39
     * @codeCoverageIgnore
40
     */
41
    #[ReturnTypeWillChange]
42
    public function offsetExists($offset): bool
43
    {
44
        return array_key_exists($offset, $this->lazies);
45
    }
46
47
    /**
48
     * @param string $offset
49
     *
50
     * @return mixed
51
     *
52
     * @codeCoverageIgnore
53
     */
54
    #[ReturnTypeWillChange]
55
    public function offsetGet($offset)
56
    {
57
        $lazy = $this->lazies[$offset];
58
59
        return $lazy($this->injector);
60
    }
61
62
    /**
63
     * @param string $offset
64
     * @param mixed  $value
65
     *
66
     * @return never
0 ignored issues
show
Bug introduced by
The type Ray\Di\MultiBinding\never was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
     *
68
     * @codeCoverageIgnore
69
     */
70
    #[ReturnTypeWillChange]
71
    public function offsetSet($offset, $value)
72
    {
73
        unset($offset, $value);
74
75
        throw new LogicException();
76
    }
77
78
    /**
79
     * @param string $offset
80
     *
81
     * @return never
82
     *
83
     * @codeCoverageIgnore
84
     */
85
    #[ReturnTypeWillChange]
86
    public function offsetUnset($offset)
87
    {
88
        unset($offset);
89
90
        throw new LogicException();
91
    }
92
93
    /** @return Generator<int, object> */
94
    public function getIterator(): Iterator
95
    {
96
        foreach ($this->lazies as $lazy) {
97
            $object = ($lazy)($this->injector);
98
99
            yield $object;
100
        }
101
    }
102
103
    public function count(): int
104
    {
105
        return count($this->lazies);
106
    }
107
}
108