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.

AddConfigurableProductToCart::execute()   D
last analyzed

Complexity

Conditions 10
Paths 6

Size

Total Lines 38
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 26
nc 6
nop 0

How to fix   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\Cart;
4
5
use Magium\Actions\StaticActionInterface;
6
use Magium\Magento\Extractors\Catalog\Cart\AddToCart;
7
use Magium\Magento\Extractors\Catalog\Product\ConfigurableProductOptions;
8
use Magium\Magento\Extractors\Catalog\Product\Swatch;
9
use Magium\Magento\Extractors\Catalog\Product\Option;
10
use Magium\Magento\Extractors\Catalog\Product\SwatchValue;
11
use Magium\Magento\Extractors\Catalog\Product\Value;
12
use Magium\Magento\Themes\AbstractThemeConfiguration;
13
use Magium\WebDriver\WebDriver;
14
15
class AddConfigurableProductToCart extends AddSimpleProductToCart implements StaticActionInterface
16
{
17
18
    const ACTION = 'Cart\AddConfigurableProductToCart';
19
20
    const EXCEPTION_INVALID_CONFIGURABLE_OPTION = 'Magium\Magento\Actions\Cart\InvalidConfigurableOptionException';
21
22
    protected $option;
23
    protected $options = [];
24
25
    public function __construct(
26
        WebDriver $webDriver,
27
        AbstractThemeConfiguration $themeConfiguration,
28
        AddToCart $addToCart,
29
        ConfigurableProductOptions $option
30
    )
31
    {
32
        parent::__construct($webDriver, $themeConfiguration, $addToCart);
33
        $this->option = $option;
34
    }
35
36
    public function setOption($attribute, $option)
37
    {
38
        $this->options[strtolower($attribute)] = $option;
39
    }
40
41
    public function getOption($attribute)
42
    {
43
        $attribute = strtolower($attribute);
44
        foreach ($this->options as $name => $option) {
45
            if ($name == $attribute) {
46
                return $option;
47
            }
48
        }
49
50
    }
51
52
53
    public function execute()
54
    {
55
        $this->option->extract();
56
        if (count($this->options)) {
57
            $attributes = $this->option->getOptionNames();
58
            foreach ($attributes as $attributeName) {
59
                $elementOption = $this->option->getOption($attributeName);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $elementOption is correct as $this->option->getOption($attributeName) (which targets Magium\Magento\Extractor...uctOptions::getOption()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
60
                if (!$elementOption) continue;
61
                // The options are sorted by  their entry into the setOption() method.  Need to have it ordered by the page order
62
63
                if (!$elementOption instanceof Option) {
64
                    throw new InvalidConfigurableOptionException('Missing the attribute: ' . $attributeName);
65
                }
66
                $element = $elementOption->getValue($this->getOption($attributeName));
67
                if (!$element instanceof Value) {
68
                    throw new InvalidConfigurableOptionException(sprintf('Missing the option %s for the attribute %s ', $this->getOption($attributeName), $attributeName));
69
                }
70
                $element->getClickElement()->click();
71
            }
72
        } else {
73
            $names = $this->option->getOptionNames();
74
            foreach ($names as $name) {
75
                $option = $this->option->getOption($name);
76
                $items = $option->getValues();
77
                foreach ($items as $item) {
78
                    if ($item instanceof SwatchValue) {
79
                        if ($item->getAvailable()) {
80
                            $item->getClickElement()->click();
81
                            break;
82
                        }
83
                    } else {
84
                        $item->getClickElement()->click();
85
                    }
86
                }
87
            }
88
        }
89
        return parent::execute();
90
    }
91
92
}
93