Completed
Pull Request — master (#90)
by Arnaud
07:39 queued 05:31
created

Registry::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LAG\AdminBundle\Action\Registry;
4
5
use Exception;
6
use LAG\AdminBundle\Action\ActionInterface;
7
8
/**
9
 * Store the Action in a typed collection
10
 */
11 View Code Duplication
class Registry
1 ignored issue
show
Duplication introduced by
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.
54
     *
55 1
     * @param string $id
56
     * @return bool
57 1
     */
58
    public function has($id)
59
    {
60
        return array_key_exists($id, $this->actions);
61
    }
62
    
63
    /**
64
     * Return all the registered Actions.
65 1
     *
66
     * @return ActionInterface[]
67 1
     */
68
    public function all()
69
    {
70
        return $this->actions;
71
    }
72
}
73