This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate
the same code in three or more different places, we strongly encourage you to
look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
12
{
13
/**
14
* Actions registry.
15
*
16
* @var ActionInterface[]
17
*/
18
protected $actions = [];
19
20
/**
21
* Add an Action to the registry.
22
*
23
* @param $id
24
* @param ActionInterface $action
25
1
*
26
* @throws Exception
27
1
*/
28
1
public function add($id, ActionInterface $action)
29
{
30
1
if (array_key_exists($id, $this->actions)) {
31
1
throw new Exception('An Action with the name "'.$id.'" has already been registered');
32
}
33
$this->actions[$id] = $action;
34
}
35
36
/**
37
* Return an Action from the registry.
38
*
39
* @param string $id
40
1
* @return ActionInterface
41
* @throws Exception
42
1
*/
43
1
public function get($id)
44
{
45
if (!array_key_exists($id, $this->actions)) {
46
1
throw new Exception('No Action with the service id "'.$id.'" has been found');
47
}
48
49
return $this->actions[$id];
50
}
51
52
/**
53
* Return true if an Action with the name $id has been registered.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.