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
Pull Request — master (#69)
by Kevin
03:33
created

BillingAddress::canProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Magium\Magento\Actions\Checkout\Steps;
4
5
use Facebook\WebDriver\WebDriverExpectedCondition;
6
use Magium\Magento\AbstractMagentoTestCase;
7
use Magium\Magento\Identities\Customer;
8
use Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration;
9
use Magium\WebDriver\WebDriver;
10
11
class BillingAddress implements StepInterface
12
{
13
    const ACTION = 'Checkout\Steps\BillingAddress';
14
15
    protected $webdriver;
16
    protected $theme;
17
    protected $customerIdentity;
18
    protected $testCase;
19
    protected $shipToDifferentAddress;
20
21
    protected $enterNewAddress;
22
    protected $bypass = [];
23
    
24
    public function __construct(
25
        WebDriver                   $webdriver,
26
        AbstractThemeConfiguration          $theme,
27
        Customer            $customerIdentity,
28
        AbstractMagentoTestCase     $testCase
29
    ) {
30
        $this->webdriver        = $webdriver;
31
        $this->theme            = $theme;
32
        $this->customerIdentity = $customerIdentity;
33
        $this->testCase         = $testCase;
34
    }
35
36
    /**
37
     * Allows you to bypass arbitrary element assertions and entry.  Currently only supports email address.
38
     *
39
     * @see Magium\Magento\Actions\Checkout\Steps\CustomerBillingAddress
40
     *
41
     * @param $element The name of the element
42
     */
43
44
    public function bypassElement($element)
45
    {
46
        $this->bypass[] = $element;
47
    }
48
49
    public function shipToDifferentAddress($ship = true)
50
    {
51
        $this->shipToDifferentAddress = $ship;
52
    }
53
54
    public function enterNewAddress($newAddress = true)
55
    {
56
        $this->enterNewAddress = $newAddress;
57
    }
58
59
    protected function preExecute()
60
    {
61
        if ($this->enterNewAddress & $this->webdriver->elementDisplayed($this->theme->getBillingNewAddressXpath(), WebDriver::BY_XPATH)) {
62
            $this->webdriver->byXpath($this->theme->getBillingNewAddressXpath())->click();
63
        }
64
65
        if ($this->shipToDifferentAddress) {
66 View Code Duplication
            if ($this->webdriver->elementExists($this->theme->getDoNotUseBillingAddressForShipping(), WebDriver::BY_XPATH)) {
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...
67
                $this->webdriver->byXpath($this->theme->getDoNotUseBillingAddressForShipping())->click();
68
            }
69 View Code Duplication
        } else {
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...
70
            if ($this->webdriver->elementExists($this->theme->getUseBillingAddressForShipping(), WebDriver::BY_XPATH)) {
71
                $this->webdriver->byXpath($this->theme->getUseBillingAddressForShipping())->click();
72
            }
73
        }
74
75
        if (!$this->enterNewAddress && $this->webdriver->elementDisplayed($this->theme->getBillingAddressDropdownXpath(), WebDriver::BY_XPATH)) {
76
            // We're logged in and we have an address.
77
78
            return true;
79
        }
80
        return false;
81
    }
82
83
    protected function canProcess($xpath)
84
    {
85
        if (!$xpath) {
86
            return false;
87
        }
88
        return array_search($xpath, $this->bypass) === false;
89
    }
90
91
    public function execute()
92
    {
93
        if ($this->preExecute()) {
94
            return true;
95
        }
96
97 View Code Duplication
        if ($this->canProcess($this->theme->getBillingEmailAddressXpath())) {
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...
98
            $this->testCase->byXpath($this->theme->getBillingEmailAddressXpath())->clear();
99
            $this->testCase->byXpath($this->theme->getBillingEmailAddressXpath())->sendKeys($this->customerIdentity->getEmailAddress());
100
        }
101 View Code Duplication
        if ($this->canProcess($this->theme->getBillingFirstNameXpath())) {
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...
102
            $this->testCase->byXpath($this->theme->getBillingFirstNameXpath())->clear();
103
            $this->testCase->byXpath($this->theme->getBillingFirstNameXpath())->sendKeys($this->customerIdentity->getBillingFirstName());
104
        }
105
106 View Code Duplication
        if ($this->canProcess($this->theme->getBillingLastNameXpath())) {
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...
107
            $this->testCase->byXpath($this->theme->getBillingLastNameXpath())->clear();
108
            $this->testCase->byXpath($this->theme->getBillingLastNameXpath())->sendKeys($this->customerIdentity->getBillingLastName());
109
        }
110
111 View Code Duplication
        if ($this->canProcess($this->theme->getBillingCompanyXpath())) {
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...
112
            $this->testCase->byXpath($this->theme->getBillingCompanyXpath())->clear();
113
            $this->testCase->byXpath($this->theme->getBillingCompanyXpath())->sendKeys($this->customerIdentity->getBillingCompany());
114
        }
115
116 View Code Duplication
        if ($this->canProcess($this->theme->getBillingAddressXpath())) {
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...
117
            $this->testCase->byXpath($this->theme->getBillingAddressXpath())->clear();
118
            $this->testCase->byXpath($this->theme->getBillingAddressXpath())->sendKeys($this->customerIdentity->getBillingAddress());
119
        }
120
121 View Code Duplication
        if ($this->canProcess($this->theme->getBillingAddress2Xpath())) {
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...
122
            $this->testCase->byXpath($this->theme->getBillingAddress2Xpath())->clear();
123
            $this->testCase->byXpath($this->theme->getBillingAddress2Xpath())->sendKeys($this->customerIdentity->getBillingAddress2());
124
        }
125
126 View Code Duplication
        if ($this->canProcess($this->theme->getBillingCityXpath())) {
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
            $this->testCase->byXpath($this->theme->getBillingCityXpath())->clear();
128
            $this->testCase->byXpath($this->theme->getBillingCityXpath())->sendKeys($this->customerIdentity->getBillingCity());
129
        }
130
131
        $regionXpath = $this->theme->getBillingRegionIdXpath($this->customerIdentity->getBillingRegionId());
132
        if ($this->canProcess($regionXpath)) {
133
            $this->testCase->byXpath($regionXpath)->click();
134
        }
135
136 View Code Duplication
        if ($this->canProcess($this->theme->getBillingPostCodeXpath())) {
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...
137
            $this->testCase->byXpath($this->theme->getBillingPostCodeXpath())->clear();
138
            $this->testCase->byXpath($this->theme->getBillingPostCodeXpath())->sendKeys($this->customerIdentity->getBillingPostCode());
139
        }
140
141
        $countryXpath = $this->theme->getBillingCountryIdXpath($this->customerIdentity->getBillingCountryId());
142
        if ($this->canProcess($countryXpath)) {
143
            $this->testCase->byXpath($countryXpath)->click();
144
        }
145
146 View Code Duplication
        if ($this->canProcess($this->theme->getBillingTelephoneXpath())) {
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...
147
            $this->testCase->byXpath($this->theme->getBillingTelephoneXpath())->clear();
148
            $this->testCase->byXpath($this->theme->getBillingTelephoneXpath())->sendKeys($this->customerIdentity->getBillingTelephone());
149
        }
150
151 View Code Duplication
        if ($this->canProcess($this->theme->getBillingFaxXpath())) {
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...
152
            $this->testCase->byXpath($this->theme->getBillingFaxXpath())->clear();
153
            $this->testCase->byXpath($this->theme->getBillingFaxXpath())->sendKeys($this->customerIdentity->getBillingFax());
154
        }
155
156
        return true;
157
    }
158
159
160 View Code Duplication
    public function nextAction()
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...
161
    {
162
        $this->testCase->byXpath($this->theme->getBillingContinueButtonXpath())->click();
163
164
        $this->webdriver->wait()->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getBillingContinueCompletedXpath()))));
165
        return true;
166
    }
167
}