Completed
Push — master ( d98c10...e4052f )
by Nikolas
04:37
created

ActionList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 36
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hasGroups() 0 3 1
A getAllActions() 0 3 1
A getGroups() 0 3 1
A getActionsOf() 0 6 1
1
<?php
2
namespace rtens\domin\delivery\web\home;
3
4
5
use rtens\domin\delivery\web\ActionGroups;
6
7
class ActionList {
8
9
    /** @var array|ActionListItem[] */
10
    private $actions;
11
12
    /** @var ActionGroups */
13
    private $groups;
14
15
    /**
16
     * @param ActionGroups $groups
17
     * @param ActionListItem[] $actions
18
     */
19
    public function __construct(ActionGroups $groups, array $actions) {
20
        $this->actions = $actions;
21
        $this->groups = $groups;
22
    }
23
24
    public function hasGroups() {
25
        return count($this->groups->getGroups()) != 0;
26
    }
27
28
    public function getAllActions() {
29
        return $this->actions;
30
    }
31
32
    public function getGroups() {
33
        return $this->groups->getGroups();
34
    }
35
36
    public function getActionsOf($group) {
37
        $actions = array_keys($this->groups->getActionsOf($group));
38
        return array_filter($this->actions, function (ActionListItem $action) use ($actions) {
39
            return in_array($action->getId(), $actions);
40
        });
41
    }
42
}