Failed Conditions
Push — release-11.5.x ( 71e6eb...3bfdb1 )
by Markus
27:37
created

GroupCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getByName() 0 9 3
A getHasWithName() 0 10 3
A getGroupNames() 0 8 2
A add() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Grouping;
17
18
use ApacheSolrForTypo3\Solr\System\Data\AbstractCollection;
19
20
/**
21
 * The Group contains the Group objects.
22
 */
23
class GroupCollection extends AbstractCollection
24
{
25
    /**
26
     * @param string $name
27
     * @return Group|null
28
     */
29
    public function getByName(string $name): ?Group
30
    {
31
        foreach ($this->data as $group) {
32
            /* @var Group $group */
33
            if ($group->getGroupName() === $name) {
34
                return $group;
35
            }
36
        }
37
        return null;
38
    }
39
40
    /**
41
     * @param string $name
42
     * @return bool
43
     */
44
    public function getHasWithName(string $name): bool
45
    {
46
        foreach ($this->data as $group) {
47
            /* @var Group $group */
48
            if ($group->getGroupName() === $name) {
49
                return true;
50
            }
51
        }
52
53
        return false;
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getGroupNames(): array
60
    {
61
        $names = [];
62
        foreach ($this->data as $group) {
63
            /* @var Group $group */
64
            $names[] = $group->getGroupName();
65
        }
66
        return $names;
67
    }
68
69
    /**
70
     * @param Group $group
71
     */
72
    public function add(Group $group)
73
    {
74
        $this->data[] = $group;
75
    }
76
}
77