FlowCollection::getAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of graze/data-flow
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-flow/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-flow
12
 */
13
14
namespace Graze\DataFlow\Flow;
15
16
use ArrayIterator;
17
use Graze\DataFlow\FlowInterface;
18
use IteratorAggregate;
19
use Serializable;
20
21
class FlowCollection implements IteratorAggregate, Serializable
22
{
23
    /**
24
     * @var FlowInterface[]
25
     */
26
    protected $items = [];
27
28
    /**
29
     * FlowCollection constructor.
30
     *
31
     * @param FlowInterface ...$flows
32
     */
0 ignored issues
show
Documentation introduced by
Should the type for parameter $flows not be FlowInterface[]?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
33 59
    public function __construct(...$flows)
34
    {
35 59
        $this->addFlows($flows);
36 59
    }
37
38
    /**
39
     * @param FlowInterface[] $items
40
     *
41
     * @return $this
42
     */
43 59
    public function addFlows(array $items)
44
    {
45 59
        foreach ($items as $item) {
46 14
            $this->add($item);
47 59
        }
48
49 59
        return $this;
50
    }
51
52
    /**
53
     * @return FlowInterface[]
54
     */
55 3
    public function getAll()
56
    {
57 3
        return $this->items;
58
    }
59
60
    /**
61
     * @param FlowInterface $flow
62
     *
63
     * @return static
64
     */
65 55
    public function add(FlowInterface $flow)
66
    {
67 55
        $this->items[] = $flow;
68
69 55
        return $this;
70
    }
71
72
    /**
73
     * @param FlowInterface $flow
74
     *
75
     * @return static
76
     */
77 1
    public function remove(FlowInterface $flow)
78
    {
79 1
        $index = array_search($flow, $this->items, true);
80 1
        if ($index !== false) {
81 1
            unset($this->items[$index]);
82 1
            $this->items = array_values($this->items);
83 1
        }
84
85 1
        return $this;
86
    }
87
88
    /**
89
     * @param FlowInterface $flow
90
     *
91
     * @return bool
92
     */
93 1
    public function contains(FlowInterface $flow)
94
    {
95 1
        return in_array($flow, $this->items, true);
96
    }
97
98
    /**
99
     * @return int
100
     */
101 3
    public function count()
102
    {
103 3
        return count($this->items);
104
    }
105
106
    /**
107
     * @return ArrayIterator
108
     */
109 1
    public function getIterator()
110
    {
111 1
        return new ArrayIterator($this->items);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117 1
    public function serialize()
118
    {
119 1
        return serialize($this->items);
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 1
    public function unserialize($data)
126
    {
127 1
        $this->items = unserialize($data);
128 1
    }
129
}
130