Completed
Push — master ( 0b908e...886262 )
by Kevin
02:30
created

TokenContainer::removeChild()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Groundskeeper\Tokens;
4
5
use Groundskeeper\Configuration;
6
use Psr\Log\LoggerInterface;
7
8
class TokenContainer implements Cleanable, ContainsChildren
9
{
10
    /** @var array[Token] */
11
    private $children;
12
13
    /** @var Configuration */
14
    private $configuration;
15
16
    /**
17
     * Constructor
18
     */
19 21
    public function __construct(Configuration $configuration)
20
    {
21 21
        $this->children = array();
22 21
        $this->configuration = $configuration;
23 21
    }
24
25
    /**
26
     * Required by ContainsChildren interface.
27
     */
28 21
    public function getChildren()
29
    {
30 21
        return $this->children;
31
    }
32
33
    /**
34
     * Required by ContainsChildren interface.
35
     */
36
    public function hasChild(Token $token)
37
    {
38
        return array_search($token, $this->children) !== false;
39
    }
40
41
    /**
42
     * Required by ContainsChildren interface.
43
     */
44 21
    public function addChild(Token $token)
45
    {
46 21
        $this->children[] = $token;
47
48 21
        return $this;
49
    }
50
51
    /**
52
     * Required by ContainsChildren interface.
53
     */
54 View Code Duplication
    public function removeChild(Token $token)
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        $key = array_search($token, $this->children);
57
        if ($key !== false) {
58
            unset($this->children[$key]);
59
60
            return true;
61
        }
62
63
        return false;
64
    }
65
66
    /**
67
     * Required by Cleanable interface.
68
     */
69 15
    public function clean(LoggerInterface $logger = null)
70
    {
71 15
        if ($this->configuration->get('clean-strategy') == Configuration::CLEAN_STRATEGY_NONE) {
72
            return;
73
        }
74
75 15
        foreach ($this->children as $child) {
76 15
            if ($child instanceof Cleanable) {
77 7
                $child->clean($logger);
78 7
            }
79 15
        }
80 15
    }
81
}
82