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

ArrayStack::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 1
Bugs 0 Features 1
Metric Value
eloc 0
c 1
b 0
f 1
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 ArrayStack extends AbstractCollection implements Stack, IndexIterable
14
{
15
16
    use RemoveTraverseTrait;
17
18
    /**
19
     * Adds element to the top of stack
20
     *
21
     * @param $element
22
     *
23
     * @return bool
24
     */
25 1
    public function push($element): bool
26
    {
27 1
        return $this->add($element);
28
    }
29
30
    /**
31
     * Gets element from the top of stack
32
     *
33
     * @return mixed
34
     */
35 2
    public function pop()
36
    {
37 2
        if ($this->isEmpty()) {
38 1
            throw new RuntimeException('Stack is empty');
39
        }
40
41 1
        return array_pop($this->elements);
42
    }
43
44
    /**
45
     * Retrieves, but does not remove
46
     *
47
     * @return mixed
48
     */
49 3
    public function peek()
50
    {
51 3
        if ($this->isEmpty()) {
52 1
            throw new RuntimeException('Stack is empty');
53
        }
54
55 2
        return $this->elements[count($this->elements) - 1];
56
    }
57
58 1
    public function stream(): Stream
59
    {
60 1
        return new SerialStream($this);
61
    }
62
63 11
    public function toArray(): array
64
    {
65 11
        return array_reverse($this->elements);
66
    }
67
68 5
    public function getIndexIterator(): Iterator
69
    {
70 5
        return IteratorFactory::reverseSequence($this->size());
71
    }
72
73 5
    protected function afterElementAdd($element): void
74
    {
75 5
    }
76
77 22
    protected function afterElementsSet(): void
78
    {
79 22
    }
80
}
81