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 |
||
24 | class EntityClosure extends Entity implements EntityInterface |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Holds group info... |
||
29 | */ |
||
30 | public $group = null; |
||
31 | |||
32 | // protected $group = null; |
||
|
|||
33 | // protected $group = array( |
||
34 | // // 'title' => 'some group title...', |
||
35 | // // 'description' => 'some group description..', |
||
36 | // // 'bb' => 'ss' |
||
37 | // ); |
||
38 | |||
39 | private $reflection; |
||
40 | |||
41 | /** |
||
42 | * Sets and returns the reflection of a function. |
||
43 | * |
||
44 | * @param string $name The REST name of function. |
||
45 | * @return \ReflectionFunction|false |
||
46 | */ |
||
47 | public function reflectedFunc($name) |
||
48 | { |
||
49 | if (isset($this->reflection[$name])) { |
||
50 | return $this->reflection[$name]; |
||
51 | } elseif ( isset($this->actions[$name]['action']) |
||
52 | && $this->actions[$name]['action'] instanceof \Closure |
||
53 | ) { |
||
54 | $this->reflection[$name] = new \ReflectionFunction($this->actions[$name]['action']); |
||
55 | |||
56 | return $this->reflection[$name]; |
||
57 | } |
||
58 | |||
59 | return false; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function append(array $def) |
||
66 | { |
||
67 | parent::_append($def); |
||
68 | // if (!isset($def['method'])) { |
||
69 | // throw new \RuntimeException('Closure not defining a method, somehting must be wrong!?'); |
||
70 | // } |
||
71 | $this->actions[$def['method']] = $def; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | * @codeCoverageIgnore |
||
77 | */ |
||
78 | public function setActions(array $asso = null) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function underlineCall(Router $route) |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function parseDocs() |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function getMethod(Router $route) |
||
139 | |||
140 | private function getAction($method) |
||
144 | |||
145 | /* --- CLOSURE only --- */ |
||
146 | |||
147 | /** |
||
148 | * Adds a redirect. |
||
149 | * |
||
150 | * @param string $location A name |
||
151 | * @param array $resource The resource definition array |
||
152 | * @return void |
||
153 | */ |
||
154 | public function redirect($location) |
||
160 | |||
161 | /** |
||
162 | * Group a resource entity. |
||
163 | * |
||
164 | * @param string $name The group name |
||
165 | * @return void |
||
166 | */ |
||
167 | public function group($title) |
||
180 | |||
181 | } |
||
182 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.