Passed
Push — master ( 683c38...4d0316 )
by Timo
22:01
created

GroupCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 54
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getByName() 0 10 3
A getHasWithName() 0 10 3
A getGroupNames() 0 9 2
A add() 0 3 1
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Grouping;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2017 Timo Hund <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\System\Data\AbstractCollection;
29
30
/**
31
 * The Group contains the Group objects.
32
 *
33
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Grouping
34
 */
35
class GroupCollection extends AbstractCollection {
36
37
    /**
38
     * @param string $name
39
     * @return Group|null
40
     */
41 1
    public function getByName($name)
42
    {
43 1
        foreach ($this->data as $group) {
44
            /** @var $group Group */
45 1
            if ($group->getGroupName() === $name) {
46 1
                return $group;
47
            }
48
        }
49
50 1
        return null;
51
    }
52
53
    /**
54
     * @param string $name
55
     * @return boolean
56
     */
57 1
    public function getHasWithName($name): bool
58
    {
59 1
        foreach ($this->data as $group) {
60
            /** @var $group Group */
61 1
            if ($group->getGroupName() === $name) {
62 1
                return true;
63
            }
64
        }
65
66 1
        return false;
67
    }
68
69
    /**
70
     * @return array
71
     */
72 1
    public function getGroupNames(): array
73
    {
74 1
        $names = [];
75 1
        foreach ($this->data as $group) {
76
            /** @var $group Group */
77 1
            $names[] = $group->getGroupName();
78
        }
79
80 1
        return $names;
81
    }
82
83
    /**
84
     * @param Group $group
85
     */
86 1
    public function add(Group $group)
87
    {
88 1
        $this->data[] = $group;
89
    }
90
}