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 ( c903c8...24a7f8 )
by Kevin
06:19 queued 03:16
created

ShippingAddress::execute()   F

Complexity

Conditions 13
Paths 2049

Size

Total Lines 62
Code Lines 37

Duplication

Lines 36
Ratio 58.06 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 36
loc 62
rs 2.8934
cc 13
eloc 37
nc 2049
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Magium\Magento\Actions\Checkout\Steps;
4
5
use Facebook\WebDriver\WebDriverExpectedCondition;
6
use Magium\AbstractTestCase;
7
use Magium\Magento\AbstractMagentoTestCase;
8
use Magium\Magento\Identities\Customer;
9
use Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration;
10
use Magium\WebDriver\ExpectedCondition;
11
use Magium\WebDriver\WebDriver;
12
13
class ShippingAddress implements StepInterface
14
{
15
    const ACTION = 'Checkout\Steps\ShippingAddress';
16
17
    protected $webdriver;
18
    protected $theme;
19
    protected $customerIdentity;
20
    protected $testCase;
21
    protected $bypassNextStep = false;
22
23
    protected $enterNewAddress = false;
24
25
    public function __construct(
26
        WebDriver                   $webdriver,
27
        AbstractThemeConfiguration          $theme,
28
        Customer                    $customerIdentity,
29
        AbstractMagentoTestCase     $testCase
30
    ) {
31
        $this->webdriver        = $webdriver;
32
        $this->theme            = $theme;
33
        $this->customerIdentity = $customerIdentity;
34
        $this->testCase         = $testCase;
35
    }
36
37
    public function enterNewAddress($newAddress = true)
38
    {
39
        $this->enterNewAddress = $newAddress;
40
    }
41
42
    protected function preExecute()
43
    {
44
        if ($this->enterNewAddress) {
45
            $this->webdriver->wait()->until(
46
                ExpectedCondition::visibilityOf(
47
                    $this->webdriver->byXpath($this->theme->getShippingNewAddressXpath())
48
                )
49
            );
50
            $this->webdriver->byXpath($this->theme->getShippingNewAddressXpath())->click();
51
            $this->webdriver->wait()->until(
52
                ExpectedCondition::visibilityOf(
53
                    $this->webdriver->byXpath($this->theme->getShippingFirstNameXpath())
54
                )
55
            );
56
        }
57
        // We will bypass ourself if the billing address is the same as the shipping address.
58
        if (!$this->webdriver->elementDisplayed($this->theme->getShippingFirstNameXpath(), AbstractTestCase::BY_XPATH)) {
59
            $this->bypassNextStep = true;
60
            return true;
61
        }
62
        return false;
63
    }
64
65
    public function execute()
66
    {
67
        if ($this->preExecute()) {
68
            return true;
69
        }
70
71 View Code Duplication
        if ($this->theme->getShippingFirstNameXpath()) {
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...
72
            $this->testCase->byXpath($this->theme->getShippingFirstNameXpath())->clear();
73
            $this->testCase->byXpath($this->theme->getShippingFirstNameXpath())->sendKeys($this->customerIdentity->getShippingFirstName());
74
        }
75
76 View Code Duplication
        if ($this->theme->getShippingLastNameXpath()) {
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...
77
            $this->testCase->byXpath($this->theme->getShippingLastNameXpath())->clear();
78
            $this->testCase->byXpath($this->theme->getShippingLastNameXpath())->sendKeys($this->customerIdentity->getShippingLastName());
79
        }
80
81 View Code Duplication
        if ($this->theme->getShippingCompanyXpath()) {
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...
82
            $this->testCase->byXpath($this->theme->getShippingCompanyXpath())->clear();
83
            $this->testCase->byXpath($this->theme->getShippingCompanyXpath())->sendKeys($this->customerIdentity->getShippingCompany());
84
        }
85
86 View Code Duplication
        if ($this->theme->getShippingAddressXpath()) {
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...
87
            $this->testCase->byXpath($this->theme->getShippingAddressXpath())->clear();
88
            $this->testCase->byXpath($this->theme->getShippingAddressXpath())->sendKeys($this->customerIdentity->getShippingAddress());
89
        }
90
91 View Code Duplication
        if ($this->theme->getShippingAddress2Xpath()) {
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...
92
            $this->testCase->byXpath($this->theme->getShippingAddress2Xpath())->clear();
93
            $this->testCase->byXpath($this->theme->getShippingAddress2Xpath())->sendKeys($this->customerIdentity->getShippingAddress2());
94
        }
95
96 View Code Duplication
        if ($this->theme->getShippingCityXpath()) {
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...
97
            $this->testCase->byXpath($this->theme->getShippingCityXpath())->clear();
98
            $this->testCase->byXpath($this->theme->getShippingCityXpath())->sendKeys($this->customerIdentity->getShippingCity());
99
        }
100
101
        $regionXpath = $this->theme->getShippingRegionIdXpath($this->customerIdentity->getShippingRegionId());
102
        if ($regionXpath) {
103
            $this->testCase->byXpath($regionXpath)->click();
104
        }
105
106 View Code Duplication
        if ($this->theme->getShippingPostCodeXpath()) {
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->getShippingPostCodeXpath())->clear();
108
            $this->testCase->byXpath($this->theme->getShippingPostCodeXpath())->sendKeys($this->customerIdentity->getShippingPostCode());
109
        }
110
111
        $countryXpath = $this->theme->getShippingCountryIdXpath($this->customerIdentity->getShippingCountryId());
112
        if ($countryXpath) {
113
            $this->testCase->byXpath($countryXpath)->click();
114
        }
115
116 View Code Duplication
        if ($this->theme->getShippingTelephoneXpath()) {
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->getShippingTelephoneXpath())->clear();
118
            $this->testCase->byXpath($this->theme->getShippingTelephoneXpath())->sendKeys($this->customerIdentity->getShippingTelephone());
119
        }
120
121 View Code Duplication
        if ($this->theme->getShippingFaxXpath()) {
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->getShippingFaxXpath())->clear();
123
            $this->testCase->byXpath($this->theme->getShippingFaxXpath())->sendKeys($this->customerIdentity->getShippingFax());
124
        }
125
        return true;
126
    }
127
128 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...
129
    {
130
        if ($this->bypassNextStep) {
131
            return true;
132
        }
133
        $this->testCase->byXpath($this->theme->getShippingContinueButtonXpath())->click();
134
135
        $this->webdriver->wait()->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingContinueCompletedXpath()))));
136
        return true;
137
    }
138
}