Passed
Branch master (5f6eff)
by Rafael
04:03
created

GroupCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A getByName() 0 10 3
A getHasWithName() 0 10 3
A getGroupNames() 0 9 2
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
class GroupCollection extends AbstractCollection {
34
35
    /**
36
     * @param string $name
37
     * @return Group|null
38
     */
39
    public function getByName($name)
40
    {
41
        foreach ($this->data as $group) {
42
            /** @var $group Group */
43
            if ($group->getGroupName() === $name) {
44
                return $group;
45
            }
46
        }
47
48
        return null;
49
    }
50
51
    /**
52
     * @param string $name
53
     * @return boolean
54
     */
55
    public function getHasWithName($name): bool
56
    {
57
        foreach ($this->data as $group) {
58
            /** @var $group Group */
59
            if ($group->getGroupName() === $name) {
60
                return true;
61
            }
62
        }
63
64
        return false;
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    public function getGroupNames(): array
71
    {
72
        $names = [];
73
        foreach ($this->data as $group) {
74
            /** @var $group Group */
75
            $names[] = $group->getGroupName();
76
        }
77
78
        return $names;
79
    }
80
81
    /**
82
     * @param Group $group
83
     */
84
    public function add(Group $group)
85
    {
86
        $this->data[] = $group;
87
    }
88
}
89