Passed
Push — master ( 28c5ec...7a4f55 )
by Pol
04:19
created

Apply::modify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\phptree\Modifier;
6
7
use loophp\phptree\Node\NodeInterface;
8
9
/**
10
 * Class Apply.
11
 */
12
class Apply implements ModifierInterface
13
{
14
    /**
15
     * @var callable
16
     */
17
    private $apply;
18
19
    /**
20
     * Filter constructor.
21
     *
22
     * @param callable $apply
23
     */
24 2
    public function __construct(callable $apply)
25
    {
26 2
        $this->apply = $apply;
27 2
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 1
    public function modify(NodeInterface $tree): NodeInterface
33
    {
34
        /** @var \loophp\phptree\Node\MerkleNode $item */
35 1
        foreach ($tree->all() as $item) {
36 1
            ($this->apply)($item);
37
        }
38
39 1
        return $tree;
40
    }
41
}
42