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 |
||
16 | abstract class HtmlViewItem extends HtmlSemDoubleElement { |
||
17 | use ContentPartTrait; |
||
18 | |||
19 | public function __construct($identifier,$baseClass,$content=NULL) { |
||
25 | |||
26 | public function setContent($value){ |
||
40 | |||
41 | View Code Duplication | private function createContent($content, $baseClass="content") { |
|
47 | |||
48 | private function addElementIn($key, $element) { |
||
58 | |||
59 | |||
60 | public function addHeader($header, $niveau=4, $type="page") { |
||
66 | |||
67 | public function addImage($image, $title="") { |
||
74 | |||
75 | public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL,$key="extra-content") { |
||
82 | |||
83 | public function addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) { |
||
90 | |||
91 | public function addExtraContent($content=array()) { |
||
94 | |||
95 | /*public function addContent($content=array(), $before=false) { |
||
96 | if (!$content instanceof HtmlViewContent) { |
||
97 | $content=$this->createContent($content); |
||
98 | } |
||
99 | $this->content["content"]->addElement($content); |
||
100 | return $content; |
||
101 | }*/ |
||
102 | |||
103 | /** |
||
104 | * @param array $elements |
||
105 | * @param boolean $asIcons |
||
106 | * @param string $part |
||
107 | * @param boolean $before |
||
108 | * @return HtmlButtonGroups |
||
109 | */ |
||
110 | public function addContentButtons($elements=array(), $asIcons=false,$part="extra",$before=false){ |
||
113 | |||
114 | |||
115 | |||
116 | public function addItemHeaderContent($header, $metas=array(), $description=NULL,$extra=NULL) { |
||
119 | |||
120 | public function addItemContent($content=array()) { |
||
124 | |||
125 | public function getItemContent() { |
||
128 | |||
129 | public function getItemExtraContent() { |
||
132 | |||
133 | public function getItemImage() { |
||
136 | |||
137 | public function getItemHeader() { |
||
140 | |||
141 | /** |
||
142 | * |
||
143 | * {@inheritDoc} |
||
144 | * |
||
145 | * @see HtmlSemDoubleElement::compile() |
||
146 | */ |
||
147 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
151 | |||
152 | public function asLink($href="",$target=NULL) { |
||
161 | } |
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.