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

OperationList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 62
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 1
A append() 0 6 1
A prepend() 0 6 1
A count() 0 4 1
A getIterator() 0 4 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