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.

BillingAddress   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 128
Duplicated Lines 11.72 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 7
dl 15
loc 128
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A bypassElement() 0 4 1
A shipToDifferentAddress() 0 4 1
A enterNewAddress() 0 4 1
A shouldProcess() 0 7 2
C preExecute() 8 23 7
A sendData() 0 7 2
B execute() 0 30 4
A nextAction() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 shouldProcess($xpath)
84
    {
85
        if (!$xpath) {
86
            return false;
87
        }
88
        return array_search($xpath, $this->bypass) === false;
89
    }
90
91
    protected function sendData($xpath, $data)
92
    {
93
        if ($this->shouldProcess($xpath)) {
94
            $this->testCase->byXpath($xpath)->clear();
95
            $this->testCase->byXpath($xpath)->sendKeys($data);
96
        }
97
    }
98
99
    public function execute()
100
    {
101
        if ($this->preExecute()) {
102
            return true;
103
        }
104
        $this->sendData($this->theme->getBillingEmailAddressXpath(), $this->customerIdentity->getEmailAddress());
105
        $this->sendData($this->theme->getBillingFirstNameXpath(), $this->customerIdentity->getBillingFirstName());
106
        $this->sendData($this->theme->getBillingLastNameXpath(), $this->customerIdentity->getBillingLastName());
107
        $this->sendData($this->theme->getBillingCompanyXpath(), $this->customerIdentity->getBillingCompany());
108
        $this->sendData($this->theme->getBillingAddressXpath(), $this->customerIdentity->getBillingAddress());
109
        $this->sendData($this->theme->getBillingAddress2Xpath(), $this->customerIdentity->getBillingAddress2());
110
        $this->sendData($this->theme->getBillingCityXpath(), $this->customerIdentity->getBillingCity());
111
112
        $countryXpath = $this->theme->getBillingCountryIdXpath($this->customerIdentity->getBillingCountryId());
113
        if ($this->shouldProcess($countryXpath)) {
114
            $this->testCase->byXpath($countryXpath)->click();
115
        }
116
117
        $regionXpath = $this->theme->getBillingRegionIdXpath($this->customerIdentity->getBillingRegionId());
118
        if ($this->shouldProcess($regionXpath)) {
119
            $this->testCase->byXpath($regionXpath)->click();
120
        }
121
122
        $this->sendData($this->theme->getBillingPostCodeXpath(), $this->customerIdentity->getBillingPostCode());
123
124
        $this->sendData($this->theme->getBillingTelephoneXpath(), $this->customerIdentity->getBillingTelephone());
125
        $this->sendData($this->theme->getBillingFaxXpath(), $this->customerIdentity->getBillingFax());
126
127
        return true;
128
    }
129
130
131 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...
132
    {
133
        $this->testCase->byXpath($this->theme->getBillingContinueButtonXpath())->click();
134
135
        $this->webdriver->wait()->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getBillingContinueCompletedXpath()))));
0 ignored issues
show
Documentation introduced by
\Facebook\WebDriver\WebD...inueCompletedXpath()))) is of type object<Facebook\WebDrive...riverExpectedCondition>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
        return true;
137
    }
138
}