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 TopPage extends AbstractFrontPage |
||
| 28 | { |
||
| 29 | |||
| 30 | public static $検索_カテゴリ選択 = ['id' => 'category_id']; |
||
| 31 | public static $検索_キーワード = ['id' => 'name']; |
||
| 32 | |||
| 33 | |||
| 34 | public static function go(\AcceptanceTester $I) |
||
| 35 | { |
||
| 36 | $page = new self($I); |
||
| 37 | return $page->goPage(''); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function 新着情報選択($rowNum) |
||
| 41 | { |
||
| 42 | $this->tester->click(['css' => "div.ec-news .ec-newsline:nth-child($rowNum) a"]); |
||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function 新着情報詳細($rowNum) |
||
| 47 | { |
||
| 48 | return $this->tester->grabTextFrom(['css' => "div.ec-news .ec-newsline:nth-child($rowNum) .ec-newsline__description"]); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function 新着情報リンククリック($rowNum) |
||
| 52 | { |
||
| 53 | $this->tester->click(['css' => "div.ec-news .ec-newsline:nth-child($rowNum) .ec-newsline__description a"]); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function カテゴリ選択($categories) |
||
| 57 | { |
||
| 58 | $xpath = "//*[@class='ec-layoutRole__header']/"; |
||
| 59 | foreach ($categories as $i=>$category) { |
||
| 60 | $xpath .= "/ul/li/a[contains(text(), '$category')]/parent::node()"; |
||
| 61 | $this->tester->waitForElement(['xpath' => $xpath]); |
||
| 62 | $this->tester->moveMouseOver(['xpath' => $xpath]); |
||
| 63 | } |
||
| 64 | $this->tester->click(['xpath' => $xpath]); |
||
| 65 | return $this; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function 検索() |
||
| 69 | { |
||
| 70 | $this->tester->click('button.ec-headerSearch__keywordBtn'); |
||
| 71 | return $this; |
||
| 72 | } |
||
| 73 | } |