Passed
Pull Request — main (#3261)
by Sebastian
48:30 queued 07:03
created

Node::getHasParentNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
*/
15
16
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Hierarchy;
17
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\AbstractOptionFacetItem;
19
20
/**
21
 * Value object that represent an option of a options facet.
22
 *
23
 * @author Frans Saris <[email protected]>
24
 * @author Timo Hund <[email protected]>
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 int
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 13
    public function __construct(HierarchyFacet $facet, $parentNode = null, $key = '', $label = '', $value = '', $documentCount = 0, $selected = false)
59
    {
60 13
        parent::__construct($facet, $label, $value, $documentCount, $selected);
61 13
        $this->value = $value;
62 13
        $this->childNodes = new NodeCollection();
63 13
        $this->parentNode = $parentNode;
64 13
        $this->key = $key;
65
    }
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 11
    public function addChildNode(Node $node)
79
    {
80 11
        $this->childNodes->add($node);
81
    }
82
83
    /**
84
     * @return NodeCollection
85
     */
86 8
    public function getChildNodes()
87
    {
88 8
        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