Failed Conditions
Pull Request — experimental/sf (#3236)
by Kentaro
132:46 queued 125:39
created

LayoutEditPage   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 97
Duplicated Lines 27.84 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 27
loc 97
rs 10
c 0
b 0
f 0
wmc 13
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
        if (mb_strlen($blockName) > 10) {
36
            $blockName = mb_substr($blockName, 0, 10).'…';
37
        }
38
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'detail_box__layout_item')][div[div[1][a[text()='${blockName}']]]]"], $timeout);
39
        $this->tester->dragAndDrop(['xpath' => "//div[contains(@id, 'detail_box__layout_item')][div[div[1][a[text()='${blockName}']]]]"], $dest);
40
        return $this;
41
    }
42
43
    public function コンテキストメニューを開く($blockName)
44
    {
45
        $this->tester->click(['xpath' => "//div[contains(@id, 'detail_box__layout_item')][div[div[1][a[text()='${blockName}']]]]/div/div[2]"]);
46
        return $this;
47
    }
48
49
    public function コンテキストメニューで上に移動($blockName)
50
    {
51
        $this->コンテキストメニューを開く($blockName);
52
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[1]"]);
53
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[1]"]);
54
        return $this;
55
    }
56
57
    public function コンテキストメニューで下に移動($blockName)
58
    {
59
        $this->コンテキストメニューを開く($blockName);
60
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[2]"]);
61
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[2]"]);
62
        return $this;
63
    }
64
65
    public function コンテキストメニューでセクションに移動($blockName)
66
    {
67
        $this->コンテキストメニューを開く($blockName);
68
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[3]"]);
69
        $this->tester->wait(1);
70
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[3]"]);
71
        $this->tester->waitForElementVisible(['id' => "move-to-section"]);
72
        $this->tester->wait(1);
73
        $this->tester->click(['id' => "move-to-section"]);
74
        $this->tester->waitForElementNotVisible(['id' => "move-to-section"]);
75
        $this->tester->wait(1);
76
        return $this;
77
    }
78
79
    public function コンテキストメニューでコードプレビュー($blockName, $element = null, $timeout = 10)
80
    {
81
        $this->コンテキストメニューを開く($blockName);
82
        $this->tester->waitForElementVisible(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[4]"]);
83
        $this->tester->click(['xpath' => "//div[contains(@id, 'popover')]/div[2]/div/a[4]"]);
84
        $this->tester->waitForElementVisible(['id' => "codePreview"]);
85
        if ($element) {
86
            $this->tester->waitForElementVisible($element, $timeout);
87
        }
88
        $this->tester->click(['xpath' => "//*[@id='codePreview']/div/div/div[3]/button[1]"]);
89
        return $this;
90
    }
91
92
    public function プレビュー()
93
    {
94
        $this->tester->click("#preview_box__preview_button > button");
95
        return $this;
96
    }
97
98
    public function 検索ブロック名($value)
99
    {
100
        $this->tester->fillField(['css' => '#unused-block div.first input'], $value);
101
        return $this;
102
    }
103
}
104