Passed
Pull Request — master (#1308)
by Timo
22:26
created

FacetCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 0
loc 57
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addFacet() 0 4 1
A getUsed() 0 8 1
A getAvailable() 0 8 1
A getByGroupName() 0 8 1
A getByPosition() 0 4 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 44
    public function addFacet(AbstractFacet $facet)
18
    {
19 44
        $this->data[$facet->getName()] = $facet;
20 44
    }
21
22
    /**
23
     * @return FacetCollection
24
     */
25 22
    public function getUsed()
26
    {
27 22
        return $this->getFilteredCopy(
28
            function(AbstractFacet $facet) {
29 20
                return $facet->getIsUsed();
30 22
            }
31
        );
32
    }
33
34
    /**
35
     * @return FacetCollection
36
     */
37 22
    public function getAvailable()
38
    {
39 22
        return $this->getFilteredCopy(
40
            function(AbstractFacet $facet) {
41 20
                return $facet->getIsAvailable();
42 22
            }
43
        );
44
    }
45
46
    /**
47
     * @param string $requiredGroup
48
     * @return AbstractCollection
49
     */
50 25
    public function getByGroupName($requiredGroup = 'all')
51
    {
52 25
        return $this->getFilteredCopy(
53 25
            function(AbstractFacet $facet) use ($requiredGroup) {
54 23
                return $facet->getGroupName() == $requiredGroup;
55 25
            }
56
        );
57
    }
58
59
    /**
60
     * @param int $position
61
     * @return AbstractFacet
62
     */
63 16
    public function getByPosition($position)
64
    {
65 16
        return parent::getByPosition($position);
66
    }
67
}
68