Apply   A
last analyzed

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 8
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A modify() 0 7 2
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace loophp\phptree\Modifier;
11
12
use loophp\phptree\Node\NodeInterface;
13
use loophp\phptree\Traverser\PostOrder;
14
use loophp\phptree\Traverser\TraverserInterface;
15
16
class Apply implements ModifierInterface
17
{
18
    /**
19
     * @var callable
20
     */
21
    private $apply;
22
23
    /**
24
     * @var TraverserInterface
25
     */
26
    private $traverser;
27
28
    /**
29
     * Apply constructor.
30
     */
31 2
    public function __construct(callable $apply, ?TraverserInterface $traverser = null)
32
    {
33 2
        $this->apply = $apply;
34 2
        $this->traverser = $traverser ?? new PostOrder();
35 2
    }
36
37 1
    public function modify(NodeInterface $tree): NodeInterface
38
    {
39 1
        foreach ($this->traverser->traverse($tree) as $item) {
40 1
            ($this->apply)($item);
41
        }
42
43 1
        return $tree;
44
    }
45
}
46