Completed
Push — master ( e610ee...c79300 )
by Arne
04:09
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 addOperation() 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
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