Passed
Push — multi_binding ( 75a5e8 )
by Akihito
02:09
created

Map::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 2
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\MultiBinding;
6
7
use ArrayAccess;
8
use Generator;
9
use Iterator;
10
use IteratorAggregate;
11
use LogicException;
12
use Ray\Di\InjectorInterface;
13
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...
14
15
use function array_key_exists;
16
use function assert;
17
use function is_object;
18
19
final class Map implements IteratorAggregate, ArrayAccess
20
{
21
    /** @var array<string, Lazy> $lazies */
22
    private $lazies;
23
24
    /** @var InjectorInterface */
25
    private $injector;
26
27
    /** @param array<string, Lazy> $lazies */
28
    public function __construct(array $lazies, InjectorInterface $injector)
29
    {
30
        $this->lazies = $lazies;
31
        $this->injector = $injector;
32
    }
33
34
    /** @param string $offset */
35
    #[ReturnTypeWillChange]
36
    public function offsetExists($offset): bool
37
    {
38
        return array_key_exists($offset, $this->lazies);
39
    }
40
41
    /**
42
     * @param string $offset
43
     *
44
     * @return mixed
45
     */
46
    #[ReturnTypeWillChange]
47
    public function offsetGet($offset)
48
    {
49
        $lazy = $this->lazies[$offset];
50
51
        /** @var Lazy $lazy */
52
        return $lazy($this->injector);
53
    }
54
55
    /**
56
     * @param string $offset
57
     * @param mixed  $value
58
     *
59
     * @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...
60
     */
61
    #[ReturnTypeWillChange]
62
    public function offsetSet($offset, $value)
63
    {
64
        throw new LogicException();
65
    }
66
67
    /**
68
     * @param string $offset
69
     *
70
     * @return never
71
     */
72
    #[ReturnTypeWillChange]
73
    public function offsetUnset($offset)
74
    {
75
        throw new LogicException();
76
    }
77
78
    /** @return Generator<int, object> */
79
    public function getIterator(): Iterator
80
    {
81
        foreach ($this->lazies as $lazy) {
82
            $object = ($lazy)($this->injector);
83
            assert(is_object($object));
84
85
            yield $object;
86
        }
87
    }
88
}
89