Passed
Pull Request — master (#25)
by
unknown
02:23
created

ArrayQueue   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 12
c 2
b 0
f 0
dl 0
loc 44
ccs 18
cts 18
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A offer() 0 3 1
A poll() 0 8 2
A getIndexIterator() 0 3 1
A peek() 0 7 2
A stream() 0 3 1
A afterElementsSet() 0 2 1
A afterElementAdd() 0 2 1
1
<?php
2
/**
3
 * @author  Igor Pomiluyko [email protected]
4
 * @license MIT
5
 */
6
7
namespace WS\Utils\Collections;
8
9
use RuntimeException;
10
use WS\Utils\Collections\Iterator\Iterator;
11
use WS\Utils\Collections\Iterator\IteratorFactory;
12
13
class ArrayQueue extends AbstractCollection implements Queue, IndexIterable
14
{
15
    use RemoveTraverseTrait;
16
17 1
    public function offer($element): bool
18
    {
19 1
        return $this->add($element);
20
    }
21
22 4
    public function poll()
23
    {
24 4
        if ($this->isEmpty()) {
25 1
            throw new RuntimeException('Queue is empty');
26
        }
27
28 3
        $this->pointer--;
29 3
        return array_shift($this->elements);
30
    }
31
32 3
    public function peek()
33
    {
34 3
        if ($this->isEmpty()) {
35 1
            throw new RuntimeException('Queue is empty');
36
        }
37
38 2
        return $this->elements[0];
39
    }
40
41 1
    public function stream(): Stream
42
    {
43 1
        return new SerialStream($this);
44
    }
45
46 5
    public function getIndexIterator(): Iterator
47
    {
48 5
        return IteratorFactory::directSequence($this->size());
49
    }
50
51 6
    protected function afterElementAdd($element): void
52
    {
53 6
    }
54
55 20
    protected function afterElementsSet(): void
56
    {
57 20
    }
58
}
59