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 |
||
16 | class NewsManagePage extends AbstractAdminPage |
||
17 | { |
||
18 | public static $登録完了メッセージ = '.c-container .c-contentsArea .alert-success'; |
||
19 | |||
20 | /** |
||
21 | * ContentsRegisterPage constructor. |
||
22 | */ |
||
23 | public function __construct(\AcceptanceTester $I) |
||
24 | { |
||
25 | parent::__construct($I); |
||
26 | } |
||
27 | |||
28 | public static function go($I) |
||
29 | { |
||
30 | $page = new self($I); |
||
31 | |||
32 | return $page->goPage('/content/news', 'コンテンツ管理新着情報管理'); |
||
33 | } |
||
34 | |||
35 | public static function at($I) |
||
36 | { |
||
37 | $page = new self($I); |
||
38 | |||
39 | return $page->atPage('コンテンツ管理新着情報管理'); |
||
40 | } |
||
41 | |||
42 | public function 新規登録() |
||
43 | { |
||
44 | $this->tester->click('.c-contentsArea .c-contentsArea__cols .c-contentsArea__primaryCol .justify-content-between #addNew |
||
45 | '); |
||
46 | } |
||
47 | |||
48 | public function 一覧_編集($rowNum) |
||
49 | { |
||
50 | $this->tester->click(" ul .list-group li:nth-child(${rowNum}) |
||
51 | div > div :nth-child(4) > a"); |
||
52 | |||
53 | return $this; |
||
54 | } |
||
55 | |||
56 | public function 一覧_タイトル($rowNum) |
||
57 | { |
||
58 | return $this->tester->grabTextFrom(['css' => "ul.list-group li:nth-child(${rowNum}) div > div:nth-child(4) a"]); |
||
59 | } |
||
60 | |||
61 | public function 一覧_下へ($rowNum) |
||
62 | { |
||
63 | $this->tester->click(" ul .list-group li:nth-child(${rowNum}) |
||
64 | div > div :nth-child(4) > a"); |
||
65 | |||
66 | return $this; |
||
67 | } |
||
68 | |||
69 | public function 一覧_削除($rowNum) |
||
75 | |||
76 | View Code Duplication | public function ポップアップを受け入れます($rowNum) |
|
|
|||
77 | { |
||
78 | $modal = "ul.list-group li:nth-child(${rowNum}) div > div:nth-child(5) > div > div:nth-child(3) div.modal"; |
||
79 | $this->tester->waitForElementVisible(['css' => $modal]); |
||
80 | $this->tester->click($modal.' .modal-footer a.btn-ec-delete'); |
||
81 | |||
82 | return $this; |
||
84 | } |
||
85 |
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.