Completed
Push — master ( 44a00f...9727c6 )
by Arne
02:20
created

OperationList::addOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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