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 |
||
| 15 | View Code Duplication | class ShippingDiscount extends \app\modules\shop\models\AbstractDiscountType |
|
| 16 | { |
||
| 17 | /** |
||
| 18 | * getShippingOption |
||
| 19 | * @return ShippingOption |
||
|
|
|||
| 20 | */ |
||
| 21 | public function getShippingOption() |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @inheritdoc |
||
| 28 | */ |
||
| 29 | public function getFullName() { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @inheritdoc |
||
| 36 | */ |
||
| 37 | public function checkDiscount(Discount $discount, Product $product = null, Order $order = null) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @inheritdoc |
||
| 60 | */ |
||
| 61 | public static function tableName() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @inheritdoc |
||
| 68 | */ |
||
| 69 | public function rules() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @inheritdoc |
||
| 79 | */ |
||
| 80 | public function attributeLabels() |
||
| 88 | } |
||
| 89 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.