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 |
||
| 12 | class BaseModel extends Model |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | public static $tag; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string[] |
||
| 21 | */ |
||
| 22 | public static function getTagProperties() { |
||
| 25 | |||
| 26 | 9 | /** |
|
| 27 | * @return string[] |
||
| 28 | 9 | */ |
|
| 29 | public function getYmlAttributes() |
||
| 33 | |||
| 34 | 9 | /** |
|
| 35 | * @return string |
||
| 36 | 9 | */ |
|
| 37 | public function getYml() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param array $params |
||
| 50 | */ |
||
| 51 | public function setParams(array $params) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param array $pictures |
||
| 58 | */ |
||
| 59 | public function setPictures(array $pictures) |
||
| 63 | |||
| 64 | 9 | /** |
|
| 65 | * @param array $options |
||
| 66 | 9 | */ |
|
| 67 | 9 | public function setDeliveryOptions(array $options) |
|
| 71 | 9 | ||
| 72 | /** |
||
| 73 | * @param $data |
||
| 74 | * @param null $onValidationError |
||
| 75 | * |
||
| 76 | * @return bool |
||
| 77 | 9 | * @throws Exception |
|
| 78 | */ |
||
| 79 | 9 | public function loadAndValidate($data, $onValidationError = null) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @param $valuesModel |
||
| 97 | * @param null $onValidationError |
||
| 98 | 9 | * |
|
| 99 | * @return bool |
||
| 100 | 9 | * @throws Exception |
|
| 101 | 9 | */ |
|
| 102 | public function loadModel($valuesModel, $onValidationError = null) |
||
| 130 | 9 | ||
| 131 | /** |
||
| 132 | * @return string |
||
| 133 | 9 | */ |
|
| 134 | View Code Duplication | protected function getYmlStartTag() |
|
| 143 | |||
| 144 | /** |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | View Code Duplication | protected function getYmlEndTag() |
|
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | protected function getYmlBody() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | protected function getYmlTagProperties() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param string $attribute |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | protected function getAttributeValue($attribute) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param string $attribute |
||
| 194 | * @return string |
||
| 195 | */ |
||
| 196 | protected function getYmlAttribute($attribute) |
||
| 212 | } |
||
| 213 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.