Completed
Pull Request — master (#90)
by Arnaud
03:09 queued 01:17
created

Registry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 25.4 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 16
loc 63
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 7 7 2
A get() 9 9 2
A has() 0 4 1
A all() 0 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
class Registry
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 View Code Duplication
    public function add($id, ActionInterface $action)
0 ignored issues
show
Duplication introduced by
This method 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...
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 View Code Duplication
    public function get($id)
0 ignored issues
show
Duplication introduced by
This method 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...
41
    {
42 1
        if (!array_key_exists($id, $this->actions)) {
43 1
            dump($this->actions);
44
            throw new Exception('No Action with the service id "'.$id.'" has been found');
45
        }
46
        
47
        return $this->actions[$id];
48
    }
49
    
50
    /**
51
     * Return true if an Action with the name $id has been registered.
52
     *
53
     * @param string $id
54
     * @return bool
55
     */
56
    public function has($id)
57
    {
58
        return array_key_exists($id, $this->actions);
59
    }
60
    
61
    /**
62
     * Return all the registered Actions.
63
     *
64
     * @return ActionInterface[]
65
     */
66
    public function all()
67
    {
68
        return $this->actions;
69
    }
70
}
71