Passed
Push — master ( 4877e0...70b946 )
by Timo
18:59
created

FacetCollection::addFacet()   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
3
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets;
4
5
use ApacheSolrForTypo3\Solr\System\Data\AbstractCollection;
6
7
/**
8
 * Class FacetCollection
9
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets
10
 */
11
class FacetCollection extends AbstractCollection
12
{
13
14
    /**
15
     * @param AbstractFacet $facet
16
     */
17 48
    public function addFacet(AbstractFacet $facet)
18
    {
19 48
        $this->data[$facet->getName()] = $facet;
20 48
    }
21
22
    /**
23
     * @return FacetCollection
24
     */
25 24
    public function getUsed()
26
    {
27 24
        return $this->getFilteredCopy(
28
            function(AbstractFacet $facet) {
29 22
                return $facet->getIsUsed() && $facet->getIncludeInUsedFacets();
30 24
            }
31
        );
32
    }
33
34
    /**
35
     * @return FacetCollection
36
     */
37 25
    public function getAvailable()
38
    {
39 25
        return $this->getFilteredCopy(
40
            function(AbstractFacet $facet) {
41 23
                return $facet->getIsAvailable() && $facet->getIncludeInAvailableFacets() && $facet->getAllRequirementsMet();
42 25
            }
43
        );
44
    }
45
46
    /**
47
     * @param string $requiredGroup
48
     * @return AbstractCollection
49
     */
50 26
    public function getByGroupName($requiredGroup = 'all')
51
    {
52 26
        return $this->getFilteredCopy(
53 26
            function(AbstractFacet $facet) use ($requiredGroup) {
54 24
                return $facet->getGroupName() == $requiredGroup;
55 26
            }
56
        );
57
    }
58
59
    /**
60
     * @param string $requiredName
61
     * @return AbstractCollection
62
     */
63 16
    public function getByName($requiredName) {
64
        return $this->getFilteredCopy(
65 16
            function(AbstractFacet $facet) use ($requiredName) {
66
                return $facet->getName() == $requiredName;
67
            }
68
        );
69
    }
70
71
    /**
72
     * @param int $position
73
     * @return AbstractFacet
74
     */
75
    public function getByPosition($position)
76
    {
77
        return parent::getByPosition($position);
78
    }
79
}
80