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 |
||
11 | trait HasDecoratorsTrait |
||
12 | { |
||
13 | protected $_decorators; |
||
14 | |||
15 | /** |
||
16 | * @param string $type |
||
17 | * @return mixed |
||
18 | */ |
||
19 | public function newDecorator($type = '') |
||
27 | |||
28 | /** |
||
29 | * @param Nip_Form_Decorator_Elements_Abstract $decorator |
||
30 | * @param string $position |
||
31 | * @param bool $name |
||
32 | * @return $this |
||
33 | */ |
||
34 | public function attachDecorator( |
||
45 | |||
46 | /** |
||
47 | * @param boolean $position |
||
48 | * @return mixed |
||
49 | */ |
||
50 | public function getDecoratorsByPosition($position) |
||
54 | |||
55 | /** |
||
56 | * @param $name |
||
57 | * @param bool $position |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function getDecorator($name, $position = false) |
||
74 | |||
75 | /** |
||
76 | * @param $name |
||
77 | * @param bool $position |
||
78 | * @return $this |
||
79 | */ |
||
80 | public function removeDecorator($name, $position = false) |
||
96 | } |
||
97 |
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.