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 |
||
| 28 | class CustomerAddressAddPage extends AbstractFrontPage |
||
| 29 | { |
||
| 30 | public function __construct(\AcceptanceTester $I) |
||
| 31 | { |
||
| 32 | parent::__construct($I); |
||
| 33 | } |
||
| 34 | |||
| 35 | public static function at($I) |
||
| 36 | { |
||
| 37 | $page = new self($I); |
||
| 38 | $page->tester->see('お届け先の追加', 'div.ec-layoutRole__main h1'); |
||
| 39 | return $page; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function 入力_姓($value) |
||
| 43 | { |
||
| 44 | $this->tester->fillField(['id' => 'shopping_shipping_name_name01'], $value); |
||
| 45 | return $this; |
||
| 46 | } |
||
| 47 | |||
| 48 | public function 入力_名($value) |
||
| 49 | { |
||
| 50 | $this->tester->fillField(['id' => 'shopping_shipping_name_name02'], $value); |
||
| 51 | return $this; |
||
| 52 | } |
||
| 53 | |||
| 54 | public function 入力_セイ($value) |
||
| 55 | { |
||
| 56 | $this->tester->fillField(['id' => 'shopping_shipping_kana_kana01'], $value); |
||
| 57 | return $this; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function 入力_メイ($value) |
||
| 61 | { |
||
| 62 | $this->tester->fillField(['id' => 'shopping_shipping_kana_kana02'], $value); |
||
| 63 | return $this; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function 入力_郵便番号($value) |
||
| 67 | { |
||
| 68 | $this->tester->fillField(['id' => 'shopping_shipping_postal_code'], $value); |
||
| 69 | |||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function 入力_都道府県($value) |
||
| 74 | { |
||
| 75 | $this->tester->selectOption(['id' => 'shopping_shipping_address_pref'], $value); |
||
| 76 | return $this; |
||
| 77 | } |
||
| 78 | |||
| 79 | public function 入力_市区町村名($value) |
||
| 80 | { |
||
| 81 | $this->tester->fillField(['id' => 'shopping_shipping_address_addr01'], $value); |
||
| 82 | return $this; |
||
| 83 | } |
||
| 84 | |||
| 85 | public function 入力_番地_ビル名($value) |
||
| 86 | { |
||
| 87 | $this->tester->fillField(['id' => 'shopping_shipping_address_addr02'], $value); |
||
| 88 | return $this; |
||
| 89 | } |
||
| 90 | |||
| 91 | public function 入力_電話番号($value) |
||
| 92 | { |
||
| 93 | $this->tester->fillField(['id' => 'shopping_shipping_phone_number'], $value); |
||
| 94 | |||
| 95 | return $this; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function 登録する() |
||
| 99 | { |
||
| 100 | $this->tester->click('#detail_box__insert_button > button'); |
||
| 101 | } |
||
| 102 | } |
||
| 103 |