Passed
Push — task/2976_TYPO3.11_compatibili... ( d7dfd0...4be1cc )
by Rafael
03:40
created

HierarchyFacet::addChildNode()   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 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\AbstractFacet;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetItemCollection;
19
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
20
21
/**
22
 * Value object that represent a options facet.
23
 *
24
 * @author Frans Saris <[email protected]>
25
 * @author Timo Hund <[email protected]>
26
 */
27
class HierarchyFacet extends AbstractFacet
28
{
29
    const TYPE_HIERARCHY = 'hierarchy';
30
31
    /**
32
     * String
33
     * @var string
34
     */
35
    protected static $type = self::TYPE_HIERARCHY;
36
37
    /**
38
     * @var NodeCollection
39
     */
40
    protected $childNodes;
41
42
    /**
43
     * @var NodeCollection
44
     */
45
    protected $allNodes;
46
47
    /**
48
     * @var array
49
     */
50
    protected $nodesByKey = [];
51
52
    /**
53
     * OptionsFacet constructor
54
     *
55
     * @param SearchResultSet $resultSet
56
     * @param string $name
57
     * @param string $field
58
     * @param string $label
59
     * @param array $configuration Facet configuration passed from typoscript
60
     */
61 9
    public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = [])
62
    {
63 9
        parent::__construct($resultSet, $name, $field, $label, $configuration);
64 9
        $this->childNodes = new NodeCollection();
65 9
        $this->allNodes = new NodeCollection();
66 9
    }
67
68
    /**
69
     * @param Node $node
70
     */
71 9
    public function addChildNode(Node $node)
72
    {
73 9
        $this->childNodes->add($node);
74 9
    }
75
76
    /**
77
     * @return NodeCollection
78
     */
79 8
    public function getChildNodes()
80
    {
81 8
        return $this->childNodes;
82
    }
83
84
    /**
85
     * Creates a new node on the right position with the right parent node.
86
     *
87
     * @param string  $parentKey
88
     * @param string $key
89
     * @param string $label
90
     * @param string $value
91
     * @param integer $count
92
     * @param boolean $selected
93
     */
94 9
    public function createNode($parentKey, $key, $label, $value, $count, $selected)
95
    {
96
        /** @var $parentNode Node|null */
97 9
        $parentNode = isset($this->nodesByKey[$parentKey]) ? $this->nodesByKey[$parentKey] : null;
98
        /** @var Node $node */
99 9
        $node = $this->objectManager->get(Node::class, $this, $parentNode, $key, $label, $value, $count, $selected);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

99
        $node = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(Node::class, $this, $parentNode, $key, $label, $value, $count, $selected);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
100 9
        $this->nodesByKey[$key] = $node;
101
102 9
        if ($parentNode === null) {
103 9
            $this->addChildNode($node);
104
        } else {
105 9
            $parentNode->addChildNode($node);
106
        }
107
108 9
        $this->allNodes->add($node);
109 9
    }
110
111
    /**
112
     * Get facet partial name used for rendering the facet
113
     *
114
     * @return string
115
     */
116 3
    public function getPartialName()
117
    {
118 3
        return !empty($this->configuration['partialName']) ? $this->configuration['partialName'] : 'Hierarchy';
119
    }
120
121
    /**
122
     * The implementation of this method should return a "flatten" collection of all items.
123
     *
124
     * @return AbstractFacetItemCollection
125
     */
126 3
    public function getAllFacetItems()
127
    {
128 3
        return $this->allNodes;
129
    }
130
}
131