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.

OrderItems::extract()   B
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 61
Code Lines 53

Duplication

Lines 9
Ratio 14.75 %

Importance

Changes 0
Metric Value
dl 9
loc 61
rs 8.6806
c 0
b 0
f 0
cc 5
eloc 53
nc 9
nop 0

How to fix   Long Method   

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\Extractors\Admin\Order;
4
5
use Magium\Extractors\AbstractExtractor;
6
use Magium\Magento\AbstractMagentoTestCase;
7
use Magium\Magento\Themes\Admin\ThemeConfiguration;
8
use Magium\WebDriver\WebDriver;
9
10
class OrderItems extends AbstractExtractor
11
{
12
    const EXTRACTOR = 'Admin\Order\OrderItems';
13
14
    protected $orderItems = [];
15
16
    public function __construct(WebDriver $webDriver, AbstractMagentoTestCase $testCase, ThemeConfiguration $theme)
17
    {
18
        parent::__construct($webDriver, $testCase, $theme);
19
    }
20
21
    public function getOrderItems()
22
    {
23
        return $this->orderItems;
24
    }
25
26
    public function extract()
27
    {
28
        $translator = $this->testCase->getTranslator();
29
        $baseXpath              = '//h4[contains(concat(" ",normalize-space(@class)," ")," head-products ")]/../../following-sibling::div[1]/descendant::tr[%d]';
30
        $titleXpath             = $baseXpath . '/descendant::div[contains(concat(" ",normalize-space(@class)," ")," item-text ")]/h5';
31
        $skuXpath               = $baseXpath . '/descendant::div[contains(concat(" ",normalize-space(@class)," ")," item-text ")]/div';
32
        $itemStatusXpath        = $baseXpath . '/td[2]';
33
        $originalPriceXpath     = $baseXpath . '/td[3]/span';
34
        $priceXpath             = $baseXpath . '/td[4]/descendant::span[contains(concat(" ",normalize-space(@class)," ")," price ")]';
35
        $orderedQtyXpath        = $baseXpath . sprintf('/td[5]/descendant::td[.="%s"]/../td/strong', $translator->translate('Ordered'));
36
        $invoicedQtyXpath       = $baseXpath . sprintf('/td[5]/descendant::td[.="%s"]/../td/strong', $translator->translate('Invoiced'));
37
        $shippedQtyXpath        = $baseXpath . sprintf('/td[5]/descendant::td[.="%s"]/../td/strong', $translator->translate('Shipped'));
38
        $subtotalXpath          = $baseXpath . '/td[6]/descendant::span[contains(concat(" ",normalize-space(@class)," ")," price ")]';
39
        $taxXpath               = $baseXpath . '/td[7]/descendant::span[contains(concat(" ",normalize-space(@class)," ")," price ")]';
40
        $taxPercentXpath        = $baseXpath . '/td[8]';
41
        $discountAmountXpath    = $baseXpath . '/td[9]/descendant::span[contains(concat(" ",normalize-space(@class)," ")," price ")]';
42
        $rowTotalXpath          = $baseXpath . '/td[10]/descendant::span[contains(concat(" ",normalize-space(@class)," ")," price ")]';
43
44
        $count = 2; // To take into account the order items header
45
        while ($this->webDriver->elementExists(sprintf($skuXpath, $count), WebDriver::BY_XPATH)) {
46
            $productName = trim($this->webDriver->byXpath(sprintf($titleXpath, $count))->getText());
47
            $sku = $this->webDriver->byXpath(sprintf($skuXpath, $count))->getText();
48
            $sku = trim(str_replace($translator->translate('SKU').':', '', $sku));
49
            $status = trim($this->webDriver->byXpath(sprintf($itemStatusXpath, $count))->getText());
50
            $originalPrice = trim($this->webDriver->byXpath(sprintf($originalPriceXpath, $count))->getText());
51
            $price = trim($this->webDriver->byXpath(sprintf($priceXpath, $count))->getText());
52
            $qtyOrdered = 0;
53 View Code Duplication
            if ($this->webDriver->elementExists(sprintf($orderedQtyXpath, $count), 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...
54
                $qtyOrdered = trim($this->webDriver->byXpath(sprintf($orderedQtyXpath, $count))->getText());
55
            }
56
            $qtyInvoiced = 0;
57 View Code Duplication
            if ($this->webDriver->elementExists(sprintf($invoicedQtyXpath, $count), 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...
58
                $qtyInvoiced = trim($this->webDriver->byXpath(sprintf($invoicedQtyXpath, $count))->getText());
59
            }
60
            $qtyShipped = 0;
61 View Code Duplication
            if ($this->webDriver->elementExists(sprintf($shippedQtyXpath, $count), 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...
62
                $qtyShipped = trim($this->webDriver->byXpath(sprintf($shippedQtyXpath, $count))->getText());
63
            }
64
            $subTotal = trim($this->webDriver->byXpath(sprintf($subtotalXpath, $count))->getText());
65
            $taxAmount = trim($this->webDriver->byXpath(sprintf($taxXpath, $count))->getText());
66
            $taxPercent = trim($this->webDriver->byXpath(sprintf($taxPercentXpath, $count))->getText());
67
            $discountAmount = trim($this->webDriver->byXpath(sprintf($discountAmountXpath, $count))->getText());
68
            $rowTotal = trim($this->webDriver->byXpath(sprintf($rowTotalXpath, $count))->getText());
69
            $this->orderItems[] = new OrderItem(
70
                $productName,
71
                $sku,
72
                $status,
73
                $originalPrice,
74
                $price,
75
                $qtyOrdered,
76
                $qtyInvoiced,
77
                $qtyShipped,
78
                $subTotal,
79
                $taxAmount,
80
                $taxPercent,
81
                $discountAmount,
82
                $rowTotal
83
            );
84
            $count++;
85
        }
86
    }
87
88
}