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.

TermsAndConditions::execute()   B
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 45
Code Lines 28

Duplication

Lines 8
Ratio 17.78 %

Importance

Changes 0
Metric Value
dl 8
loc 45
rs 8.439
c 0
b 0
f 0
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\Actions\OptionallyConfigurableActionInterface;
10
use Magium\Magento\Extractors\Admin\Widget\Attribute;
11
use Magium\Magento\Navigators\Admin\AdminMenu;
12
use Magium\Magento\Themes\Admin\ThemeConfiguration;
13
use Magium\Util\Translator\Translator;
14
use Magium\WebDriver\WebDriver;
15
16
class TermsAndConditions implements OptionallyConfigurableActionInterface
17
{
18
19
    const ACTION = 'Admin\Widget\TermsAndConditions';
20
21
    const STATUS_ENABLED = 'Enabled';
22
    const STATUS_DISABLED = 'Disabled';
23
24
    protected $webDriver;
25
    protected $themeConfiguration;
26
    protected $navigator;
27
    protected $clickActionButton;
28
    protected $translator;
29
    protected $attribute;
30
31
    protected $name;
32
    protected $status;
33
    protected $contentAs;
34
    protected $storeView;
35
    protected $checkboxText;
36
    protected $content;
37
    protected $contentHeight;
38
39
    protected $save = true;
40
41 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...
42
        WebDriver $webDriver,
43
        ThemeConfiguration $themeConfiguration,
44
        AdminMenu $navigator,
45
        ClickActionButton $clickActionButton,
46
        Translator $translator,
47
        Attribute $attribute
48
    )
49
    {
50
        $this->webDriver = $webDriver;
51
        $this->themeConfiguration = $themeConfiguration;
52
        $this->navigator = $navigator;
53
        $this->clickActionButton = $clickActionButton;
54
        $this->translator = $translator;
55
        $this->attribute = $attribute;
56
57
    }
58
59
    /**
60
     * @param mixed $checkboxText
61
     */
62
    public function setCheckboxText($checkboxText)
63
    {
64
        $this->checkboxText = $checkboxText;
65
    }
66
67
    /**
68
     * @param mixed $content
69
     */
70
    public function setContent($content)
71
    {
72
        $this->content = $content;
73
    }
74
75
    /**
76
     * @param mixed $contentAs
77
     */
78
    public function setContentAs($contentAs)
79
    {
80
        $this->contentAs = $contentAs;
81
    }
82
83
    /**
84
     * @param mixed $contentHeight
85
     */
86
    public function setContentHeight($contentHeight)
87
    {
88
        $this->contentHeight = $contentHeight;
89
    }
90
91
    /**
92
     * @param mixed $name
93
     */
94
    public function setName($name)
95
    {
96
        $this->name = $name;
97
    }
98
99
    /**
100
     * @param mixed $status
101
     */
102
    public function setStatus($status)
103
    {
104
        $this->status = $status;
105
    }
106
107
    /**
108
     * @param string $storeView
109
     */
110
    public function setStoreView($storeView)
111
    {
112
        $this->storeView = $storeView;
113
    }
114
115
    public function execute($save = true)
116
    {
117
        $this->save = $save;
118
        try {
119
            $this->clickActionButton->click($this->translator->translate('Add New Condition'));
120
        } catch (NoSuchElementException $e) {
121
            // Don't worry about it.  Perhaps we're not on the main terms page.
122
        }
123
124
        $element = $this->attribute->getElementByLabel($this->translator->translate('Condition Name'));
125
        $this->setValue($element, $this->name);
126
127 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...
128
            $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Show Content as')));
129
            $select->selectByVisibleText($this->contentAs);
130
        }
131
132 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...
133
            $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Status')));
134
            $select->selectByVisibleText($this->status);
135
        }
136
137
        if ($this->storeView) {
138
            $storeViewElement = $this->attribute->getElementByLabel($this->translator->translate('Store View'));
139
            $xpath = sprintf('//option[.="%s"]', $this->storeView);
140
            $element = $storeViewElement->findElement(WebDriverBy::xpath($xpath));
141
            $element->click();
142
        }
143
144
145
        $element = $this->attribute->getElementByLabel($this->translator->translate('Checkbox Text'));
146
        $this->setValue($element, $this->checkboxText);
147
148
        $element = $this->attribute->getElementByLabel($this->translator->translate('Content'));
149
        $this->setValue($element, $this->content);
150
151
        $element = $this->attribute->getElementByLabel($this->translator->translate('Content Height (css)'));
152
        $this->setValue($element, $this->contentHeight);
153
154
        $this->preSave();
155
        if ($this->save) {
156
            $this->webDriver->executeScript('window.scrollTo(0, 0);');
157
            $this->clickActionButton->click($this->translator->translate('Save Condition'));
158
        }
159
    }
160
161
    protected function setValue(WebDriverElement $element, $value)
162
    {
163
        $element->clear();
164
        if ($value) {
165
            $element->sendKeys($value);
166
        }
167
    }
168
169
    protected function preSave()
170
    {
171
172
    }
173
}