Imports   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 59.09%

Importance

Changes 0
Metric Value
wmc 9
eloc 12
dl 0
loc 72
rs 10
c 0
b 0
f 0
ccs 13
cts 22
cp 0.5909

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A __construct() 0 7 3
A offsetGet() 0 5 1
A offsetExists() 0 3 1
A offsetUnset() 0 3 1
A offsetSet() 0 3 1
A isKnown() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Parser;
6
7
use ArrayAccess;
8
use IteratorAggregate;
9
use function assert;
10
use function in_array;
11
use function is_string;
12
use function strtolower;
13
14
final class Imports implements ArrayAccess, IteratorAggregate
15
{
16
    /** @var string[] array<string, string> alias => FCQN */
17
    private $map = [];
18
19
    /**
20
     * @param string[] $map iterable<string, string>
21
     */
22 45
    public function __construct(iterable $map)
23
    {
24 45
        foreach ($map as $alias => $name) {
25 30
            assert(is_string($alias) && is_string($name));
26 30
            assert(! isset($this[strtolower($alias)]));
27
28 30
            $this->map[strtolower($alias)] = $name;
29
        }
30 45
    }
31
32
    /**
33
     * @return string[] alias => FCQN
34
     */
35
    public function getIterator() : iterable
36
    {
37
        yield from $this->map;
0 ignored issues
show
Bug Best Practice introduced by
The expression YieldFromNode returns the type Generator which is incompatible with the documented return type string[].
Loading history...
38
    }
39
40
    /**
41
     * @param string $offset
42
     *
43
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
44
     */
45 9
    public function offsetGet($offset) : string
46
    {
47 9
        assert(isset($this[strtolower($offset)]));
48
49 9
        return $this->map[strtolower($offset)];
50
    }
51
52
    /**
53
     * @param string $offset
54
     * @param mixed  $value
55
     *
56
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
57
     */
58
    public function offsetSet($offset, $value) : void
59
    {
60
        assert(false, 'immutable');
61
    }
62
63
    /**
64
     * @param string $offset
65
     *
66
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
67
     */
68 39
    public function offsetExists($offset) : bool
69
    {
70 39
        return isset($this->map[strtolower($offset)]);
71
    }
72
73
    /**
74
     * @param string $offset
75
     *
76
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
77
     */
78
    public function offsetUnset($offset) : void
79
    {
80
        assert(false, 'immutable');
81
    }
82
83 2
    public function isKnown(string $name) : bool
84
    {
85 2
        return in_array($name, $this->map, true);
86
    }
87
}
88