Passed
Push — master ( 1b8200...cdf526 )
by Timo
21:46
created

Node::addChildNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Hierarchy;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
*/
16
17
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\AbstractOptionFacetItem;
18
19
/**
20
 * Value object that represent an option of a options facet.
21
 *
22
 * @author Frans Saris <[email protected]>
23
 * @author Timo Hund <[email protected]>
24
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionsFacet
25
 */
26
class Node extends AbstractOptionFacetItem
27
{
28
29
    /**
30
     * @var NodeCollection
31
     */
32
    protected $childNodes;
33
34
    /**
35
     * @var Node
36
     */
37
    protected $parentNode;
38
39
    /**
40
     * @var integer
41
     */
42
    protected $depth;
43
44
    /**
45
     * @var string
46
     */
47
    protected $key;
48
49
    /**
50
     * @param HierarchyFacet $facet
51
     * @param Node $parentNode
52
     * @param string $key
53
     * @param string $label
54
     * @param string $value
55
     * @param int $documentCount
56
     * @param bool $selected
57
     */
58 26
    public function __construct(HierarchyFacet $facet, $parentNode = null, $key = '', $label = '', $value = '', $documentCount = 0, $selected = false)
59
    {
60 26
        parent::__construct($facet, $label, $value, $documentCount, $selected);
61 26
        $this->value = $value;
62 26
        $this->childNodes = new NodeCollection();
63 26
        $this->parentNode = $parentNode;
64 26
        $this->key = $key;
65 26
    }
66
67
    /**
68
     * @return string
69
     */
70 1
    public function getKey()
71
    {
72 1
        return $this->key;
73
    }
74
75
    /**
76
     * @param Node $node
77
     */
78 24
    public function addChildNode(Node $node)
79
    {
80 24
        $this->childNodes->add($node);
81 24
    }
82
83
    /**
84
     * @return NodeCollection
85
     */
86 20
    public function getChildNodes()
87
    {
88 20
        return $this->childNodes;
89
    }
90
91
    /**
92
     * @return Node|null
93
     */
94 1
    public function getParentNode()
95
    {
96 1
        return $this->parentNode;
97
    }
98
99
    /**
100
     * @return bool
101
     */
102 1
    public function getHasParentNode()
103
    {
104 1
        return $this->parentNode !== null;
105
    }
106
107
    /**
108
     * @return bool
109
     */
110 3
    public function getHasChildNodeSelected()
111
    {
112
        /** @var Node $childNode */
113 3
        foreach ($this->childNodes as $childNode) {
114 2
            if ($childNode->getSelected()) {
115 1
                return true;
116
            }
117
        }
118 2
        return false;
119
    }
120
}
121