Passed
Push — master ( 4ee1ca...f0c776 )
by Maxim
02:45 queued 10s
created

ArrayQueue::afterElementsSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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