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 |
||
7 | View Code Duplication | class Panel extends Container |
|
|
|||
8 | { |
||
9 | public function setTitle($title){ |
||
12 | |||
13 | public function setHeader(Header $header){ |
||
16 | |||
17 | public function addTool(Tool $tool){ |
||
20 | |||
21 | public function addDockedItem($dockedItem){ |
||
24 | |||
25 | public function setDockedItems(array $dockedItems){ |
||
31 | |||
32 | |||
33 | /** |
||
34 | * True to make the panel collapsible and have an expand/collapse toggle Tool added into the header tool button area. |
||
35 | * @param bool $collapsible |
||
36 | * @return $this |
||
37 | */ |
||
38 | public function setCollapsible($collapsible){ |
||
41 | |||
42 | public function setButtons(array $buttons){ |
||
48 | |||
49 | public function getButtons(){ |
||
52 | |||
53 | public function addButton($button){ |
||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 | } |
||
62 |
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.