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 |
||
10 | class JsUtils extends \Ajax\JsUtils implements InjectionAwareInterface{ |
||
11 | protected $_di; |
||
12 | public function setDi(DiInterface $di) { |
||
16 | |||
17 | public function getDi() { |
||
20 | |||
21 | public function getUrl($url){ |
||
24 | |||
25 | View Code Duplication | public function addViewElement($identifier,$content,$view){ |
|
33 | |||
34 | public function createScriptVariable($view,$view_var, $output){ |
||
37 | |||
38 | View Code Duplication | public function forward($initialController,$controller,$action){ |
|
48 | |||
49 | public function renderContent($view, $controller, $action, $params=NULL) { |
||
55 | |||
56 | View Code Duplication | public function fromDispatcher($dispatcher){ |
|
69 | } |
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.