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 |
||
17 | class PageController implements \Anax\DI\IInjectionAware |
||
18 | { |
||
19 | use \Anax\DI\TInjectable; |
||
20 | |||
21 | /** |
||
22 | * Properties |
||
23 | */ |
||
24 | private $content = null; |
||
25 | private $urlPrefix = CHP_TC_URLPREFIX; |
||
26 | |||
27 | /** |
||
28 | * Initialize the controller |
||
29 | * |
||
30 | * @Return Void |
||
31 | */ |
||
32 | View Code Duplication | public function initialize(){ |
|
39 | |||
40 | /** |
||
41 | * Index content - Redirect to startpage |
||
42 | * |
||
43 | * @Return Void |
||
44 | */ |
||
45 | public function indexAction(){ |
||
49 | |||
50 | /** |
||
51 | * Visit page made by database content |
||
52 | * |
||
53 | * @Param String $url Select url to content |
||
54 | * @Return Void |
||
55 | */ |
||
56 | public function pageAction($url = null){ |
||
79 | |||
80 | /** |
||
81 | * Prepare page to show in view |
||
82 | * |
||
83 | * @Param Object $page Page information |
||
84 | * @Return Object $result Prepared page information |
||
85 | */ |
||
86 | 1 | public function preparePage($page = null){ |
|
109 | } |
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.