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) |
||
| 23 | { |
||
| 24 | parent::__construct($I); |
||
| 25 | } |
||
| 26 | |||
| 27 | public static function go($I) |
||
| 28 | { |
||
| 29 | $page = new ProductEditPage($I); |
||
| 30 | return $page->goPage('/product/product/new', '商品管理商品登録'); |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function at($I) |
||
| 34 | { |
||
| 35 | $page = new ProductEditPage($I); |
||
| 36 | $page->tester->see('商品管理商品登録', '#page_admin_product_product_edit > div.c-container > div.c-contentsArea > div > div'); |
||
| 37 | return $page; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function 入力_商品名($value) |
||
| 41 | { |
||
| 42 | $this->tester->fillField(['id' => 'admin_product_name'], $value); |
||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function 入力_販売価格($value) |
||
| 47 | { |
||
| 48 | $this->tester->fillField(self::$販売価格, $value); |
||
| 49 | return $this; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function 入力_公開() |
||
| 53 | { |
||
| 54 | $this->tester->selectOption('#admin_product_Status', '公開'); |
||
| 55 | return $this; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function クリックして開くタグリスト() |
||
| 59 | { |
||
| 60 | $this->tester->click(['css' => 'div[href="#allTags"] > a']); |
||
| 61 | return $this; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function クリックして選択タグ($num) |
||
| 65 | { |
||
| 66 | $this->tester->click(['css' => "#allTags > div:nth-child(${num}) button"]); |
||
| 67 | return $this; |
||
| 68 | } |
||
| 69 | |||
| 70 | public function 入力_カテゴリ($category_id) |
||
| 71 | { |
||
| 72 | $this->tester->checkOption(['id' => 'admin_product_category_'.$category_id]); |
||
| 73 | return $this; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function 規格管理() |
||
| 77 | { |
||
| 78 | $this->tester->click(['css' => '#standardConfig > div > div.d-block.text-center.text-center > a']); |
||
| 79 | $this->tester->waitForElement(['css' => '#confirmFormChangeModal > div > div > div.modal-footer > a']); |
||
| 80 | $this->tester->wait(1); |
||
| 81 | $this->tester->click(['css' => '#confirmFormChangeModal > div > div > div.modal-footer > a']); |
||
| 82 | return $this; |
||
| 83 | } |
||
| 84 | |||
| 85 | public function 登録() |
||
| 86 | { |
||
| 87 | $this->tester->click('#form1 > div.c-conversionArea > div > div > div:nth-child(2) > div > div:nth-child(2) > button'); |
||
| 88 | return $this; |
||
| 89 | } |
||
| 90 | |||
| 91 | } |
||
| 92 |