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 ProductEditPage extends AbstractAdminPageStyleGuide |
||
| 9 | { |
||
| 10 | public static $登録結果メッセージ = '#page_admin_product_product_edit > div.c-container > div.c-contentsArea > div.alert.alert-success.alert-dismissible.fade.show.m-3'; |
||
| 11 | public static $販売種別 = ['id' => 'admin_product_class_sale_type']; |
||
| 12 | public static $通常価格 = ['id' => 'admin_product_class_price01']; |
||
| 13 | public static $販売価格 = ['id' => 'admin_product_class_price02']; |
||
| 14 | public static $在庫数 = ['id' => 'admin_product_class_stock']; |
||
| 15 | public static $商品コード = ['id' => 'admin_product_class_code']; |
||
| 16 | public static $販売制限数 = ['id' => 'admin_product_class_sale_limit']; |
||
| 17 | public static $お届可能日 = ['id' => 'admin_product_class_delivery_duration']; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * ProductRegisterPage constructor. |
||
| 21 | */ |
||
| 22 | public function __construct(\AcceptanceTester $I) |
||
| 26 | |||
| 27 | public static function go($I) |
||
| 32 | |||
| 33 | public static function at($I) |
||
| 39 | |||
| 40 | public function 入力_商品名($value) |
||
| 45 | |||
| 46 | public function 入力_販売価格($value) |
||
| 51 | |||
| 52 | public function 入力_公開() |
||
| 57 | |||
| 58 | public function クリックして開くタグリスト() |
||
| 63 | |||
| 64 | public function クリックして選択タグ($num) |
||
| 69 | |||
| 70 | public function 入力_カテゴリ($category_id) |
||
| 75 | |||
| 76 | View Code Duplication | public function 規格管理() |
|
| 84 | |||
| 85 | public function 登録() |
||
| 90 | |||
| 91 | } |
||
| 92 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.