Each::flow()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
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\Collection;
15
16
use Graze\DataFlow\Flow\AbstractFlow;
17
use Graze\DataFlow\FlowInterface;
18
use Graze\DataNode\NodeCollectionInterface;
19
use Graze\DataNode\NodeInterface;
20
use InvalidArgumentException;
21
22
/**
23
 * Apply a flow to each element of a NodeCollection
24
 */
25 View Code Duplication
class Each extends AbstractFlow
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    /**
28
     * @var FlowInterface
29
     */
30
    private $flow;
31
32
    /**
33
     * Each constructor.
34
     *
35
     * @param FlowInterface $flow
36
     */
37 11
    public function __construct(FlowInterface $flow)
38
    {
39 11
        $this->flow = $flow;
40 11
    }
41
42
    /**
43
     * @param NodeInterface $node
44
     *
45
     * @return NodeCollectionInterface
46
     */
47 10
    public function flow(NodeInterface $node)
48
    {
49 10
        if (!($node instanceof NodeCollectionInterface)) {
50 1
            throw new InvalidArgumentException("The supplied $node is not a NodeCollectionInterface");
51
        }
52
53 9
        $map = new Map(function (NodeInterface $item) {
54 9
            return $this->flow->flow($item);
55 9
        });
56 9
        return $map->flow($node);
57
    }
58
}
59