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 |
||
| 27 | class ProductClassEditPage extends AbstractAdminPageStyleGuide |
||
| 28 | { |
||
| 29 | public static $登録完了メッセージ = ['css' => '#page_admin_product_product_class > div > div.c-contentsArea > div.alert.alert-success.alert-dismissible.fade.show.m-3']; |
||
| 30 | |||
| 31 | public static $初期化ボタン = ['css' => '#page_admin_product_product_class > div > div.c-contentsArea > div.c-contentsArea__cols > div > div > div > div.card-header > div > div.col-4.text-right > button']; |
||
| 32 | |||
| 33 | public static $規格一覧 = ['css' => '#page_admin_product_product_class > div > div.c-contentsArea > div.c-contentsArea__cols > div > div > form > div.card.rounded.border-0.mb-4 > div.card-body.p-0 > table']; |
||
| 34 | /** |
||
| 35 | * ProductReProductClassEditPagegisterPage constructor. |
||
| 36 | */ |
||
| 37 | public function __construct(\AcceptanceTester $I) |
||
| 38 | { |
||
| 39 | parent::__construct($I); |
||
| 40 | } |
||
| 41 | |||
| 42 | public static function at($I) |
||
| 43 | { |
||
| 44 | $page = new ProductClassEditPage($I); |
||
| 45 | $page->atPage('商品登録(規格設定)商品管理'); |
||
| 46 | return $page; |
||
| 47 | } |
||
| 48 | |||
| 49 | public function 規格設定() |
||
| 50 | { |
||
| 51 | $this->tester->click(['css' => 'div.c-contentsArea form button']); |
||
| 52 | return $this; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function 入力_規格1($value) |
||
| 56 | { |
||
| 57 | $this->tester->selectOption(['id' => 'product_class_matrix_class_name1'], $value); |
||
| 58 | return $this; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function 入力_在庫数無制限($rowNum) |
||
| 62 | { |
||
| 63 | $rowNum -= 1; |
||
| 64 | $this->tester->checkOption(['id' => "product_class_matrix_product_classes_${rowNum}_stock_unlimited"]); |
||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function 入力_販売価格($rowNum, $value) |
||
| 69 | { |
||
| 70 | $rowNum -= 1; |
||
| 71 | $this->tester->fillField(['id' => "product_class_matrix_product_classes_${rowNum}_price02"], $value); |
||
| 72 | return $this; |
||
| 73 | |||
| 74 | } |
||
| 75 | |||
| 76 | public function 選択($rowNum) |
||
| 77 | { |
||
| 78 | $rowNum -= 1; |
||
| 79 | $this->tester->checkOption(['id' => "product_class_matrix_product_classes_${rowNum}_checked"]); |
||
| 80 | return $this; |
||
| 81 | } |
||
| 82 | |||
| 83 | public function 規格初期化() |
||
| 84 | { |
||
| 85 | $this->tester->click(self::$初期化ボタン); |
||
| 86 | $this->tester->waitForElement(['css' => '#initializationConfirm > div > div > div.modal-footer > form > button']); |
||
| 87 | $this->tester->wait(1); |
||
| 88 | $this->tester->click(['css' => '#initializationConfirm > div > div > div.modal-footer > form > button']); |
||
| 89 | return $this; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function 登録() |
||
| 93 | { |
||
| 94 | $this->tester->click(['css' => 'button[name="product_class_matrix[save]"]']); |
||
| 95 | return $this; |
||
| 96 | } |
||
| 97 | } |