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

Apply   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 28
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A modify() 0 8 2
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