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 |
||
10 | class HtmlProgress extends HtmlSemDoubleElement { |
||
11 | private $_params=array (); |
||
12 | |||
13 | public function __construct($identifier, $value=NULL, $label=NULL) { |
||
21 | |||
22 | public function setLabel($label) { |
||
26 | |||
27 | private function createBar() { |
||
32 | |||
33 | public function setIndicating() { |
||
36 | |||
37 | public function setActive() { |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * {@inheritDoc} |
||
44 | * |
||
45 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
46 | */ |
||
47 | public function compile(JsUtils $js=NULL, View $view=NULL) { |
||
51 | |||
52 | public function jsSetValue($value) { |
||
55 | |||
56 | public function jsIncValue() { |
||
59 | |||
60 | public function jsDecValue() { |
||
63 | |||
64 | /** |
||
65 | * |
||
66 | * @param mixed $active |
||
67 | * @param mixed $error |
||
68 | * @param mixed $success |
||
69 | * @param mixed $warning |
||
70 | * @param mixed $percent |
||
71 | * @param mixed $ratio |
||
72 | * @return HtmlProgress |
||
73 | */ |
||
74 | public function setTextValues($active=false, $error=false, $success=false, $warning=false, $percent="{percent}%", $ratio="{value} of {total}") { |
||
86 | |||
87 | public function onChange($jsCode) { |
||
90 | |||
91 | /* |
||
92 | * (non-PHPdoc) |
||
93 | * @see BaseHtml::run() |
||
94 | */ |
||
95 | public function run(JsUtils $js) { |
||
101 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.