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 |
||
3 | class Ajde_Template_Parser extends Ajde_Object_Standard |
||
4 | { |
||
5 | /** |
||
6 | * @var Ajde_Template |
||
7 | */ |
||
8 | protected $_template = null; |
||
9 | |||
10 | /** |
||
11 | * @var Ajde_Template_Parser_Phtml_Helper |
||
12 | */ |
||
13 | protected $_helper = null; |
||
14 | |||
15 | /** |
||
16 | * @param Ajde_Template $template |
||
17 | */ |
||
18 | public function __construct(Ajde_Template $template) |
||
22 | |||
23 | public function __isset($name) |
||
29 | |||
30 | public function __get($name) |
||
39 | |||
40 | View Code Duplication | public function __fallback($method, $arguments) |
|
49 | |||
50 | /** |
||
51 | * @return Ajde_Template_Parser_Phtml_Helper |
||
52 | */ |
||
53 | public function getHelper() |
||
61 | |||
62 | /** |
||
63 | * @return Ajde_Template |
||
64 | */ |
||
65 | public function getTemplate() |
||
69 | |||
70 | public function parse() |
||
74 | |||
75 | protected function _getContents() |
||
84 | } |
||
85 |
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.