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.

CartSummary   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 130
Duplicated Lines 20 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
c 1
b 0
f 0
lcom 2
cbo 8
dl 26
loc 130
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getProducts() 0 4 1
A getSubTotal() 0 4 1
A getShippingAndHandling() 0 4 1
A getTax() 0 4 1
A getGrandTotal() 0 4 1
A execute() 0 5 1
A nextAction() 0 4 1
B extract() 26 63 7

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\Extractors\Checkout;
4
5
use Magium\AbstractTestCase;
6
use Magium\Extractors\AbstractExtractor;
7
use Magium\Magento\Actions\Checkout\Steps\StepInterface;
8
use Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration;
9
use Magium\WebDriver\ExpectedCondition;
10
use Magium\WebDriver\WebDriver;
11
12
class CartSummary extends AbstractExtractor implements StepInterface
13
{
14
    const EXTRACTOR = 'Checkout\CartSummary';
15
    /**
16
     * Redefined here has a code completion helper
17
     *
18
     * @var \Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration
19
     */
20
21
    protected $theme;
22
23
    const VALUE_PRODUCTS    = 'products';
24
    const VALUE_SUBTOTAL    = 'subtotal';
25
    const VALUE_SnH         = 'ship-handle';
26
    const VALUE_TAX         = 'tax';
27
    const VALUE_GRAND_TOTAL = 'grand-total';
28
29
    public function __construct(
30
        WebDriver           $webDriver,
31
        AbstractTestCase    $testCase,
32
        AbstractThemeConfiguration $theme
33
    )
34
    {
35
        parent::__construct($webDriver, $testCase, $theme);
36
    }
37
38
    /**
39
     * @return ProductIterator
40
     */
41
42
    public function getProducts()
43
    {
44
        return $this->getValue(self::VALUE_PRODUCTS);
45
    }
46
47
    public function getSubTotal()
48
    {
49
        return $this->getValue(self::VALUE_SUBTOTAL);
50
    }
51
52
    public function getShippingAndHandling()
53
    {
54
        return $this->getValue(self::VALUE_SnH);
55
    }
56
57
    public function getTax()
58
    {
59
        return $this->getValue(self::VALUE_TAX);
60
    }
61
62
    public function getGrandTotal()
63
    {
64
        return $this->getValue(self::VALUE_GRAND_TOTAL);
65
    }
66
67
    public function extract()
68
    {
69
        $productIterator = new ProductIterator();
70
        $this->values[self::VALUE_PRODUCTS] = $productIterator;
71
        $count = 1;
72
73
        $testProductXpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath($count);
74
        $this->webDriver->wait()->until(ExpectedCondition::elementExists($testProductXpath, WebDriver::BY_XPATH));
0 ignored issues
show
Documentation introduced by
\Magium\WebDriver\Expect...er\WebDriver::BY_XPATH) 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...
75
76
        while ($this->webDriver->elementExists($testProductXpath, WebDriver::BY_XPATH)) {
77
78
            $xpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath($count);
79
            $nameElement = $this->webDriver->byXpath($xpath);
80
            $name = trim($nameElement->getText());
81
82
            $xpath = $this->theme->getCartSummaryCheckoutProductLoopPriceXpath($count);
83 View Code Duplication
            if ($this->webDriver->elementExists($xpath, 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...
84
                $priceElement = $this->webDriver->byXpath($xpath);
85
                $price = trim($priceElement->getText()); // We do not extract the number value so currency checks can be done
86
            } else {
87
                $price = 0;
88
            }
89
90
            $xpath = $this->theme->getCartSummaryCheckoutProductLoopQtyXpath($count);
91 View Code Duplication
            if ($this->webDriver->elementExists($xpath, 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...
92
                $qtyElement = $this->webDriver->byXpath($xpath);
93
                $qty = trim($qtyElement->getText());
94
            } else {
95
                $qty = 0;
96
            }
97
98
            $xpath = $this->theme->getCartSummaryCheckoutProductLoopSubtotalXpath($count);
99 View Code Duplication
            if ($this->webDriver->elementExists($xpath, 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...
100
                $subtotalElement = $this->webDriver->byXpath($xpath);
101
                $subtotal = trim($subtotalElement->getText());
102
            } else {
103
                $subtotal = 0;
104
            }
105
106
            $product = new Product($name, $qty, $price, $subtotal);
107
            $productIterator->addProduct($product);
108
            $testProductXpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath(++$count);
109
        }
110
111
        // Tax and shipping may not be displayed
112
113 View Code Duplication
        if ($this->webDriver->elementDisplayed($this->theme->getCartSummaryCheckoutTax(), 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...
114
            $this->values[self::VALUE_TAX]
115
                = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutTax())->getText());
116
        }
117 View Code Duplication
        if ($this->webDriver->elementDisplayed($this->theme->getCartSummaryCheckoutShippingTotal(), 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...
118
            $this->values[self::VALUE_SnH]
119
                = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutShippingTotal())->getText());
120
        }
121
122
123
124
        $this->values[self::VALUE_GRAND_TOTAL]
125
            = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutGrandTotal())->getText());
126
        $this->values[self::VALUE_SUBTOTAL]
127
            = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutSubTotal())->getText());
128
129
    }
130
131
    public function execute()
132
    {
133
        $this->extract();
134
        return true;
135
    }
136
137
    public function nextAction()
138
    {
139
        return true;
140
    }
141
}