Completed
Push — master ( e610ee...c79300 )
by Arne
04:09
created

OperationList::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Storeman;
4
5
use Storeman\Operation\OperationInterface;
6
7
class OperationList implements \Countable, \IteratorAggregate
8
{
9
    /**
10
     * @var OperationInterface[]
11
     */
12
    protected $operations = [];
13
14
    /**
15
     * Adds an operation to the end of the list.
16
     *
17
     * @param OperationInterface $operation
18
     * @return OperationList
19
     */
20
    public function addOperation(OperationInterface $operation): OperationList
21
    {
22
        $this->operations[] = $operation;
23
24
        return $this;
25
    }
26
27
    /**
28
     * Appends another operation list to the end of this list.
29
     *
30
     * @param OperationList $other
31
     * @return OperationList
32
     */
33
    public function append(OperationList $other): OperationList
34
    {
35
        $this->operations = array_merge($this->operations, $other->operations);
36
37
        return $this;
38
    }
39
40
    /**
41
     * Prepends another operation list to the start of this list.
42
     *
43
     * @param OperationList $other
44
     * @return OperationList
45
     */
46
    public function prepend(OperationList $other): OperationList
47
    {
48
        $this->operations = array_merge($other->operations, $this->operations);
49
50
        return $this;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function count()
57
    {
58
        return count($this->operations);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getIterator(): \Iterator
65
    {
66
        return new \ArrayIterator($this->operations);
67
    }
68
}
69