Completed
Push — master ( ca7ebd...ffd42a )
by Nikolas
03:40
created

ActionGroups::getActionsOf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
namespace rtens\domin\delivery\web;
3
4
use rtens\domin\Action;
5
use rtens\domin\ActionRegistry;
6
7
class ActionGroups {
8
9
    /** @var ActionRegistry */
10
    private $actions;
11
12
    /** @var array[] */
13
    private $groups = [];
14
15
    /**
16
     * @param ActionRegistry $actions
17
     */
18
    public function __construct(ActionRegistry $actions) {
19
        $this->actions = $actions;
20
    }
21
22
    /**
23
     * @param string $actionId
24
     * @param string $groupName
25
     */
26
    public function put($actionId, $groupName) {
27
        $this->groups[$groupName][] = $actionId;
28
    }
29
30
    /**
31
     * @return string[]
32
     */
33
    public function getGroups() {
34
        return array_keys($this->groups);
35
    }
36
37
    /**
38
     * @param string $group
39
     * @return Action[] indexed by ID
40
     * @throws \Exception
41
     */
42
    public function getActionsOf($group) {
43
        $actions = [];
44
        foreach ($this->groups[$group] as $id) {
45
            $actions[$id] = $this->actions->getAction($id);
46
        }
47
        return $actions;
48
    }
49
}