Passed
Pull Request — master (#24)
by Igor
02:46
created

ImmutableList   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Test Coverage

Coverage 95.74%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 24
eloc 25
c 2
b 0
f 0
dl 0
loc 118
ccs 45
cts 47
cp 0.9574
rs 10

23 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A of() 0 3 2
A stream() 0 3 1
A fromCollection() 0 3 1
A contains() 0 3 1
A isEmpty() 0 3 1
A add() 0 3 1
A parallelStream() 0 3 1
A indexOf() 0 3 1
A size() 0 3 1
A merge() 0 3 1
A get() 0 3 1
A copy() 0 3 1
A clear() 0 3 1
A equals() 0 3 1
A remove() 0 3 1
A set() 0 3 1
A getIterator() 0 3 1
A addAll() 0 3 1
A lastIndexOf() 0 3 1
A createBlockingException() 0 3 1
A toArray() 0 3 1
A removeAt() 0 3 1
1
<?php
2
/**
3
 * @author Maxim Sokolovsky
4
 */
5
6
namespace WS\Utils\Collections;
7
8
use RuntimeException;
9
10
class ImmutableList implements ListSequence
11
{
12
13
    private $decoratedList;
14
15 9
    public function __construct(?array $elements = null)
16
    {
17 9
        $this->decoratedList = new ArrayList($elements);
18 9
    }
19
20 1
    public static function fromCollection(Collection $collection): self
21
    {
22 1
        return new static($collection->toArray());
23
    }
24
25 1
    public static function of(...$elements): self
26
    {
27 1
        return new static($elements ?: null);
28
    }
29
    
30 1
    public function stream(): Stream
31
    {
32 1
        return $this->decoratedList->stream();
33
    }
34
35
    public function parallelStream($workersPool = null): Stream
36
    {
37
        return $this->decoratedList->parallelStream($workersPool);
38
    }
39
40 1
    public function remove($element): bool
41
    {
42 1
        throw $this->createBlockingException();
43
    }
44
45 1
    public function get(int $index)
46
    {
47 1
        return $this->decoratedList->get($index);
48
    }
49
50 1
    public function set($element, int $index)
51
    {
52 1
        throw $this->createBlockingException();
53
    }
54
55 1
    public function indexOf($element): ?int
56
    {
57 1
        return $this->decoratedList->indexOf($element);
58
    }
59
60 1
    public function lastIndexOf($element): ?int
61
    {
62 1
        return $this->decoratedList->lastIndexOf($element);
63
    }
64
65 1
    public function removeAt(int $index)
66
    {
67 1
       throw $this->createBlockingException();
68
    }
69
70 7
    private function createBlockingException(): RuntimeException
71
    {
72 7
        return new RuntimeException('Is immutable list. Everything modifier call is prohibited');
73
    }
74
75 1
    public function add($element): bool
76
    {
77 1
        throw  $this->createBlockingException();
78
    }
79
80 1
    public function addAll(iterable $elements): bool
81
    {
82 1
        throw $this->createBlockingException();
83
    }
84
85 1
    public function merge(Collection $collection): bool
86
    {
87 1
        throw $this->createBlockingException();
88
    }
89
90 1
    public function clear(): void
91
    {
92 1
        throw $this->createBlockingException();
93
    }
94
95 1
    public function contains($element): bool
96
    {
97 1
        return $this->decoratedList->contains($element);
98
    }
99
100 1
    public function equals(Collection $collection): bool
101
    {
102 1
        return $this->decoratedList->equals($collection);
103
    }
104
105 2
    public function size(): int
106
    {
107 2
        return $this->decoratedList->size();
108
    }
109
110 1
    public function isEmpty(): bool
111
    {
112 1
        return $this->decoratedList->isEmpty();
113
    }
114
115 2
    public function toArray(): array
116
    {
117 2
        return $this->decoratedList->toArray();
118
    }
119
120 1
    public function copy(): Collection
121
    {
122 1
        return $this->decoratedList->copy();
123
    }
124
125 1
    public function getIterator()
126
    {
127 1
        return $this->decoratedList->getIterator();
128
    }
129
}
130