Failed Conditions
Pull Request — experimental/sf (#3236)
by Kentaro
142:37 queued 134:37
created

LayoutEditPage   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 94
Duplicated Lines 28.72 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 27
loc 94
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
4
namespace Page\Admin;
5
6
7
class LayoutEditPage extends AbstractAdminPageStyleGuide
8
{
9
    public static $未使用ブロックアイテム = ['css' => '#unused-block div.sort'];
10
    public static $登録完了メッセージ = ['xpath' => "//div[@class='alert alert-success alert-dismissible fade show m-3']"];
11
12
    /**
13
     * LayoutEditPage constructor.
14
     */
15
    public function __construct(\AcceptanceTester $I)
16
    {
17
        parent::__construct($I);
18
    }
19
20
    public static function at($I)
21
    {
22
        $page = new self($I);
23
        return $page->atPage('レイアウト管理コンテンツ管理');
24
    }
25
26
    public function 登録()
27
    {
28
        $this->tester->waitForElementVisible('#form1 > div > div.c-conversionArea > div > div > div:nth-child(2) > div > div > button');
29
        $this->tester->click('#form1 > div > div.c-conversionArea > div > div > div:nth-child(2) > div > div > button');
30
        return $this;
31
    }
32
33
    public function ブロックを移動($blockName, $dest, $timeout = 10)
34
    {
35
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'detail_box__layout_item')][div[div[1][a[text()='${blockName}']]]]"], $timeout);
36
        $this->tester->dragAndDrop(['xpath' => "//div[contains(@id, 'detail_box__layout_item')][div[div[1][a[text()='${blockName}']]]]"], $dest);
37
        return $this;
38
    }
39
40
    public function コンテキストメニューを開く($blockName)
41
    {
42
        $this->tester->click(['xpath' => "//div[contains(@id, 'detail_box__layout_item')][div[div[1][a[text()='${blockName}']]]]/div/div[2]"]);
43
        return $this;
44
    }
45
46
    public function コンテキストメニューで上に移動($blockName)
47
    {
48
        $this->コンテキストメニューを開く($blockName);
49
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[1]"]);
50
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[1]"]);
51
        return $this;
52
    }
53
54
    public function コンテキストメニューで下に移動($blockName)
55
    {
56
        $this->コンテキストメニューを開く($blockName);
57
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[2]"]);
58
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[2]"]);
59
        return $this;
60
    }
61
62
    public function コンテキストメニューでセクションに移動($blockName)
63
    {
64
        $this->コンテキストメニューを開く($blockName);
65
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[3]"]);
66
        $this->tester->wait(1);
67
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[3]"]);
68
        $this->tester->waitForElementVisible(['id' => "move-to-section"]);
69
        $this->tester->wait(1);
70
        $this->tester->click(['id' => "move-to-section"]);
71
        $this->tester->waitForElementNotVisible(['id' => "move-to-section"]);
72
        $this->tester->wait(1);
73
        return $this;
74
    }
75
76
    public function コンテキストメニューでコードプレビュー($blockName, $element = null, $timeout = 10)
77
    {
78
        $this->コンテキストメニューを開く($blockName);
79
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[4]"]);
80
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[4]"]);
81
        $this->tester->waitForElementVisible(['id' => "codePreview"]);
82
        if ($element) {
83
            $this->tester->waitForElementVisible($element, $timeout);
84
        }
85
        $this->tester->click(['xpath' => "//*[@id='codePreview']/div/div/div[3]/button[1]"]);
86
        return $this;
87
    }
88
89
    public function プレビュー()
90
    {
91
        $this->tester->click("#preview_box__preview_button > button");
92
        return $this;
93
    }
94
95
    public function 検索ブロック名($value)
96
    {
97
        $this->tester->fillField(['css' => '#unused-block div.first input'], $value);
98
        return $this;
99
    }
100
}
101