GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0cb85b...c6c0d3 )
by Kevin
06:38 queued 03:18
created

TermsAndConditions::execute()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 45
Code Lines 28

Duplication

Lines 8
Ratio 17.78 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 8
loc 45
rs 8.439
cc 6
eloc 28
nc 32
nop 1
1
<?php
2
3
namespace Magium\Magento\Actions\Admin\Widget;
4
5
use Facebook\WebDriver\Exception\NoSuchElementException;
6
use Facebook\WebDriver\WebDriverBy;
7
use Facebook\WebDriver\WebDriverElement;
8
use Facebook\WebDriver\WebDriverSelect;
9
use Magium\Magento\Extractors\Admin\Widget\Attribute;
10
use Magium\Magento\Navigators\Admin\AdminMenu;
11
use Magium\Magento\Themes\Admin\ThemeConfiguration;
12
use Magium\Util\Translator\Translator;
13
use Magium\WebDriver\WebDriver;
14
15
class TermsAndConditions
16
{
17
18
    const ACTION = 'Admin\Widget\TermsAndConditions';
19
20
    const STATUS_ENABLED = 'Enabled';
21
    const STATUS_DISABLED = 'Disabled';
22
23
    protected $webDriver;
24
    protected $themeConfiguration;
25
    protected $navigator;
26
    protected $clickActionButton;
27
    protected $translator;
28
    protected $attribute;
29
30
    protected $name;
31
    protected $status;
32
    protected $contentAs;
33
    protected $storeView;
34
    protected $checkboxText;
35
    protected $content;
36
    protected $contentHeight;
37
38
    protected $save = true;
39
40 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
41
        WebDriver $webDriver,
42
        ThemeConfiguration $themeConfiguration,
43
        AdminMenu $navigator,
44
        ClickActionButton $clickActionButton,
45
        Translator $translator,
46
        Attribute $attribute
47
    )
48
    {
49
        $this->webDriver = $webDriver;
50
        $this->themeConfiguration = $themeConfiguration;
51
        $this->navigator = $navigator;
52
        $this->clickActionButton = $clickActionButton;
53
        $this->translator = $translator;
54
        $this->attribute = $attribute;
55
56
    }
57
58
    /**
59
     * @param mixed $checkboxText
60
     */
61
    public function setCheckboxText($checkboxText)
62
    {
63
        $this->checkboxText = $checkboxText;
64
    }
65
66
    /**
67
     * @param mixed $content
68
     */
69
    public function setContent($content)
70
    {
71
        $this->content = $content;
72
    }
73
74
    /**
75
     * @param mixed $contentAs
76
     */
77
    public function setContentAs($contentAs)
78
    {
79
        $this->contentAs = $contentAs;
80
    }
81
82
    /**
83
     * @param mixed $contentHeight
84
     */
85
    public function setContentHeight($contentHeight)
86
    {
87
        $this->contentHeight = $contentHeight;
88
    }
89
90
    /**
91
     * @param mixed $name
92
     */
93
    public function setName($name)
94
    {
95
        $this->name = $name;
96
    }
97
98
    /**
99
     * @param mixed $status
100
     */
101
    public function setStatus($status)
102
    {
103
        $this->status = $status;
104
    }
105
106
    /**
107
     * @param string $storeView
108
     */
109
    public function setStoreView($storeView)
110
    {
111
        $this->storeView = $storeView;
112
    }
113
114
    public function execute($save = true)
115
    {
116
        $this->save = $save;
117
        try {
118
            $this->clickActionButton->click($this->translator->translate('Add New Condition'));
119
        } catch (NoSuchElementException $e) {
120
            // Don't worry about it.  Perhaps we're not on the main terms page.
121
        }
122
123
        $element = $this->attribute->getElementByLabel($this->translator->translate('Condition Name'));
124
        $this->setValue($element, $this->name);
125
126 View Code Duplication
        if ($this->contentAs) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
127
            $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Show Content as')));
128
            $select->selectByVisibleText($this->contentAs);
129
        }
130
131 View Code Duplication
        if ($this->status) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
132
            $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Status')));
133
            $select->selectByVisibleText($this->status);
134
        }
135
136
        if ($this->storeView) {
137
            $storeViewElement = $this->attribute->getElementByLabel($this->translator->translate('Store View'));
138
            $xpath = sprintf('//option[.="%s"]', $this->storeView);
139
            $element = $storeViewElement->findElement(WebDriverBy::xpath($xpath));
140
            $element->click();
141
        }
142
143
144
        $element = $this->attribute->getElementByLabel($this->translator->translate('Checkbox Text'));
145
        $this->setValue($element, $this->checkboxText);
146
147
        $element = $this->attribute->getElementByLabel($this->translator->translate('Content'));
148
        $this->setValue($element, $this->content);
149
150
        $element = $this->attribute->getElementByLabel($this->translator->translate('Content Height (css)'));
151
        $this->setValue($element, $this->contentHeight);
152
153
        $this->preSave();
154
        if ($this->save) {
155
            $this->webDriver->executeScript('window.scrollTo(0, 0);');
156
            $this->clickActionButton->click($this->translator->translate('Save Condition'));
157
        }
158
    }
159
160
    protected function setValue(WebDriverElement $element, $value)
161
    {
162
        $element->clear();
163
        if ($value) {
164
            $element->sendKeys($value);
165
        }
166
    }
167
168
    protected function preSave()
169
    {
170
171
    }
172
}