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 ( 0e8d57...0cb85b )
by Kevin
06:52 queued 03:23
created

TermsAndConditions::setContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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