Completed
Pull Request — master (#90)
by Arnaud
16:16
created

Registry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 62
loc 62
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 7 7 2
A get() 8 8 2
A has() 4 4 1
A all() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LAG\AdminBundle\Action\Registry;
4
5
use Exception;
6
use LAG\AdminBundle\Action\ActionInterface;
7
8 View Code Duplication
class Registry
0 ignored issues
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...
9
{
10
    /**
11
     * Actions registry.
12
     *
13
     * @var ActionInterface[]
14
     */
15
    protected $actions = [];
16
    
17
    /**
18
     * Add an Action to the registry.
19
     *
20
     * @param $id
21
     * @param ActionInterface $action
22
     *
23
     * @throws Exception
24
     */
25 1
    public function add($id, ActionInterface $action)
26
    {
27 1
        if (array_key_exists($id, $this->actions)) {
28 1
            throw new Exception('An Action with the name "'.$id.'" has already been registered');
29
        }
30 1
        $this->actions[$id] = $action;
31 1
    }
32
    
33
    /**
34
     * Return an Action from the registry.
35
     *
36
     * @param string $id
37
     * @return ActionInterface
38
     * @throws Exception
39
     */
40 1
    public function get($id)
41
    {
42 1
        if (!array_key_exists($id, $this->actions)) {
43 1
            throw new Exception('No Action with the service id "'.$id.'" has been found');
44
        }
45
        
46 1
        return $this->actions[$id];
47
    }
48
    
49
    /**
50
     * Return true if an Action with the name $id has been registered.
51
     *
52
     * @param string $id
53
     * @return bool
54
     */
55 1
    public function has($id)
56
    {
57 1
        return array_key_exists($id, $this->actions);
58
    }
59
    
60
    /**
61
     * Return all the registered Actions.
62
     *
63
     * @return ActionInterface[]
64
     */
65 1
    public function all()
66
    {
67 1
        return $this->actions;
68
    }
69
}
70