ActionRegistry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllActions() 0 3 1
A getAction() 0 7 2
A add() 0 9 2
1
<?php
2
namespace rtens\domin;
3
4
class ActionRegistry {
5
6
    /** @var array|Action[] indexed by ID */
7
    private $actions = [];
8
9
    /**
10
     * @return Action[] indexed by ID
11
     */
12
    public function getAllActions() {
13
        return $this->actions;
14
    }
15
16
    /**
17
     * @param string $id
18
     * @return Action
19
     * @throws \Exception
20
     */
21
    public function getAction($id) {
22
        if (!array_key_exists($id, $this->actions)) {
23
            throw new \Exception("Action [$id] is not registered.");
24
        }
25
26
        return $this->actions[$id];
27
    }
28
29
    /**
30
     * @param string $id
31
     * @param Action $action
32
     * @throws \Exception
33
     * @return Action
34
     */
35
    public function add($id, Action $action) {
36
        if (array_key_exists($id, $this->actions)) {
37
            throw new \Exception("Action [$id] is already registered.");
38
        }
39
40
        $this->actions[$id] = $action;
41
42
        return $action;
43
    }
44
}