Completed
Push — master ( a56eed...8e6738 )
by Aurimas
02:24
created

DataModifierGroups::addGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Thruster\Component\DataModifier;
4
5
use Thruster\Component\DataModifier\Exception\DataModifierGroupNotFoundException;
6
7
/**
8
 * Class DataModifierGroups
9
 *
10
 * @package Thruster\Component\DataModifier
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class DataModifierGroups
14
{
15
    /**
16
     * @var DataModifierGroup[]
17
     */
18
    protected $dataModifierGroups;
19
20 3
    public function __construct()
21
    {
22 3
        $this->dataModifierGroups = [];
23 3
    }
24
25
    /**
26
     * @param string            $groupName
27
     * @param DataModifierGroup $group
28
     *
29
     * @return $this
30
     */
31 1
    public function addGroup(string $groupName, DataModifierGroup $group) : self
32
    {
33 1
        $this->dataModifierGroups[$groupName] = $group;
34
35 1
        return $this;
36
    }
37
38
    /**
39
     * @param string $groupName
40
     *
41
     * @return bool
42
     */
43 3
    public function hasGroup(string $groupName) : bool
44
    {
45 3
        return array_key_exists($groupName, $this->dataModifierGroups);
46
    }
47
48
    /**
49
     * @param string $groupName
50
     *
51
     * @return DataModifierGroup
52
     * @throws DataModifierGroupNotFoundException
53
     */
54 2
    public function getGroup(string $groupName) : DataModifierGroup
55
    {
56 2
        if (false === $this->hasGroup($groupName)) {
57 1
            throw new DataModifierGroupNotFoundException($groupName);
58
        }
59
60 1
        return $this->dataModifierGroups[$groupName];
61
    }
62
63
    /**
64
     * @param string $groupName
65
     *
66
     * @return $this
67
     */
68 1
    public function removeGroup(string $groupName) : self
69
    {
70 1
        unset($this->dataModifierGroups[$groupName]);
71
72 1
        return $this;
73
    }
74
75
    /**
76
     * @return DataModifierGroup[]
77
     */
78 1
    public function getGroups() : array
79
    {
80 1
        return $this->dataModifierGroups;
81
    }
82
83
    /**
84
     * @param DataModifierGroup[] $dataModifierGroups
85
     *
86
     * @return $this
87
     */
88 1
    public function setGroups($dataModifierGroups) : self
89
    {
90 1
        $this->dataModifierGroups = $dataModifierGroups;
91
92 1
        return $this;
93
    }
94
}
95