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 |
||
| 8 | class SimpleOffer extends BaseModel |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @inheritdoc |
||
| 12 | */ |
||
| 13 | public static $tag = 'offer'; |
||
| 14 | /** |
||
| 15 | * @inheritdoc |
||
| 16 | */ |
||
| 17 | public static $tagProperties = [ |
||
| 18 | 'id', |
||
| 19 | 'bid', |
||
| 20 | 'cbid', |
||
| 21 | 'available' |
||
| 22 | ]; |
||
| 23 | |||
| 24 | public $id; |
||
| 25 | public $bid; |
||
| 26 | public $cbid; |
||
| 27 | public $available; |
||
| 28 | |||
| 29 | public $url; |
||
| 30 | public $price; |
||
| 31 | public $oldprice; |
||
| 32 | public $currencyId; |
||
| 33 | public $categoryId; |
||
| 34 | public $market_Category; |
||
| 35 | public $store; |
||
| 36 | public $pickup; |
||
| 37 | public $delivery; |
||
| 38 | public $local_Delivery_Cost; |
||
| 39 | public $name; |
||
| 40 | public $vendor; |
||
| 41 | public $vendorCode; |
||
| 42 | public $description; |
||
| 43 | public $sales_notes; |
||
| 44 | public $manufacturer_Warranty; |
||
| 45 | public $country_Of_Origin; |
||
| 46 | public $adult; |
||
| 47 | public $age; |
||
| 48 | public $barcode; |
||
| 49 | public $cpa; |
||
| 50 | public $params = []; |
||
| 51 | public $pictures = []; |
||
| 52 | 6 | /** |
|
| 53 | * Опции доставки |
||
| 54 | * |
||
| 55 | 6 | * @var array |
|
| 56 | 4 | */ |
|
| 57 | 4 | public $deliveryOptions = []; |
|
| 58 | 4 | ||
| 59 | 4 | /** |
|
| 60 | 4 | * @inheritdoc |
|
| 61 | 4 | */ |
|
| 62 | 4 | public function getYmlAttributes() |
|
| 88 | 6 | ||
| 89 | /** |
||
| 90 | 4 | * @inheritdoc |
|
| 91 | 4 | */ |
|
| 92 | 4 | public function rules() |
|
| 172 | 6 | ||
| 173 | 6 | /** |
|
| 174 | * @param array $params |
||
| 175 | */ |
||
| 176 | public function setParams(array $params) |
||
| 180 | 6 | ||
| 181 | /** |
||
| 182 | 6 | * @param array $pictures |
|
| 183 | 6 | */ |
|
| 184 | 4 | public function setPictures(array $pictures) |
|
| 188 | 4 | ||
| 189 | /** |
||
| 190 | 6 | * @param array $options |
|
| 191 | 6 | * |
|
| 192 | 4 | * @throws Exception |
|
| 193 | */ |
||
| 194 | 6 | public function setDeliveryOptions(array $options) |
|
| 201 | |||
| 202 | /** |
||
| 203 | * @inheritdoc |
||
| 204 | */ |
||
| 205 | protected function getYmlBody() |
||
| 225 | |||
| 226 | 6 | /** |
|
| 227 | * Добавляет теги ддля опций доставки |
||
| 228 | * |
||
| 229 | * @param $string |
||
| 230 | * |
||
| 231 | * @throws Exception |
||
| 232 | */ |
||
| 233 | protected function appendDeliveryOptions(&$string) { |
||
| 243 | |||
| 244 | |||
| 245 | /** |
||
| 246 | * @param string $attribute |
||
| 247 | * @param string $value |
||
| 248 | * @return string |
||
| 249 | */ |
||
| 250 | View Code Duplication | protected function getYmlParamTag($attribute, $value) |
|
| 260 | |||
| 261 | /** |
||
| 262 | * @param string $value |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | View Code Duplication | protected function getYmlPictureTag($value) |
|
| 275 | } |
||
| 276 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.