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 | class HtmlProgress extends HtmlSemDoubleElement { |
||
| 12 | private $_params=array (); |
||
| 13 | |||
| 14 | public function __construct($identifier, $value=NULL, $label=NULL, $attributes=array()) { |
||
| 24 | |||
| 25 | public function setLabel($label) { |
||
| 29 | |||
| 30 | private function createBar() { |
||
| 35 | |||
| 36 | public function setTotal($value) { |
||
| 39 | |||
| 40 | public function setValue($value) { |
||
| 43 | |||
| 44 | public function setPercent($value) { |
||
| 47 | |||
| 48 | public function setIndicating() { |
||
| 51 | |||
| 52 | public function setWarning() { |
||
| 55 | |||
| 56 | public function setError() { |
||
| 59 | |||
| 60 | /** |
||
| 61 | * |
||
| 62 | * {@inheritDoc} |
||
| 63 | * |
||
| 64 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
| 65 | */ |
||
| 66 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
| 70 | |||
| 71 | public function jsSetValue($value) { |
||
| 74 | |||
| 75 | public function jsIncValue() { |
||
| 78 | |||
| 79 | public function jsDecValue() { |
||
| 82 | |||
| 83 | /** |
||
| 84 | * |
||
| 85 | * @param mixed $active |
||
| 86 | * @param mixed $error |
||
| 87 | * @param mixed $success |
||
| 88 | * @param mixed $warning |
||
| 89 | * @param mixed $percent |
||
| 90 | * @param mixed $ratio |
||
| 91 | * @return HtmlProgress |
||
| 92 | */ |
||
| 93 | public function setTextValues($active=false, $error=false, $success=false, $warning=false, $percent="{percent}%", $ratio="{value} of {total}") { |
||
| 105 | |||
| 106 | public function onChange($jsCode) { |
||
| 109 | |||
| 110 | /* |
||
| 111 | * (non-PHPdoc) |
||
| 112 | * @see BaseHtml::run() |
||
| 113 | */ |
||
| 114 | public function run(JsUtils $js) { |
||
| 120 | |||
| 121 | public static function create($identifier, $value=NULL, $label=NULL, $attributes=array()) { |
||
| 124 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.