Passed
Pull Request — release-11.2.x (#3154)
by Markus
16:09
created

Node   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 19
dl 0
loc 93
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getParentNode() 0 3 1
A getChildNodes() 0 3 1
A getKey() 0 3 1
A addChildNode() 0 3 1
A __construct() 0 7 1
A getHasChildNodeSelected() 0 9 3
A getHasParentNode() 0 3 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
 */
25
class Node extends AbstractOptionFacetItem
26
{
27
28
    /**
29
     * @var NodeCollection
30
     */
31
    protected $childNodes;
32
33
    /**
34
     * @var Node
35
     */
36
    protected $parentNode;
37
38
    /**
39
     * @var integer
40
     */
41
    protected $depth;
42
43
    /**
44
     * @var string
45
     */
46
    protected $key;
47
48
    /**
49
     * @param HierarchyFacet $facet
50
     * @param Node $parentNode
51
     * @param string $key
52
     * @param string $label
53
     * @param string $value
54
     * @param int $documentCount
55
     * @param bool $selected
56
     */
57 10
    public function __construct(HierarchyFacet $facet, $parentNode = null, $key = '', $label = '', $value = '', $documentCount = 0, $selected = false)
58
    {
59 10
        parent::__construct($facet, $label, $value, $documentCount, $selected);
60 10
        $this->value = $value;
61 10
        $this->childNodes = new NodeCollection();
62 10
        $this->parentNode = $parentNode;
63 10
        $this->key = $key;
64 10
    }
65
66
    /**
67
     * @return string
68
     */
69 1
    public function getKey()
70
    {
71 1
        return $this->key;
72
    }
73
74
    /**
75
     * @param Node $node
76
     */
77 8
    public function addChildNode(Node $node)
78
    {
79 8
        $this->childNodes->add($node);
80 8
    }
81
82
    /**
83
     * @return NodeCollection
84
     */
85 5
    public function getChildNodes()
86
    {
87 5
        return $this->childNodes;
88
    }
89
90
    /**
91
     * @return Node|null
92
     */
93 1
    public function getParentNode()
94
    {
95 1
        return $this->parentNode;
96
    }
97
98
    /**
99
     * @return bool
100
     */
101 1
    public function getHasParentNode()
102
    {
103 1
        return $this->parentNode !== null;
104
    }
105
106
    /**
107
     * @return bool
108
     */
109 3
    public function getHasChildNodeSelected()
110
    {
111
        /** @var Node $childNode */
112 3
        foreach ($this->childNodes as $childNode) {
113 2
            if ($childNode->getSelected()) {
114 1
                return true;
115
            }
116
        }
117 2
        return false;
118
    }
119
}
120