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.

ProductCollection::hasLayeredNavigation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Magium\Magento\Extractors\Catalog;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Facebook\WebDriver\WebDriverElement;
7
use Magium\Extractors\AbstractExtractor;
8
use Magium\Magento\AbstractMagentoTestCase;
9
use Magium\Magento\Extractors\Catalog\LayeredNavigation\HasLayeredNavigation;
10
use Magium\Magento\Extractors\Catalog\Products\ProductGrid;
11
use Magium\Magento\Extractors\Catalog\Products\ProductList;
12
use Magium\Magento\Themes\AbstractThemeConfiguration;
13
use Magium\Magento\Themes\Magento19\ThemeConfiguration;
14
use Magium\WebDriver\ExpectedCondition;
15
use Magium\WebDriver\WebDriver;
16
17
18
class ProductCollection extends AbstractExtractor
19
{
20
    const EXTRACTOR = 'Catalog\ProductCollection';
21
22
    const VIEW_MODE_LIST = 'list';
23
    const VIEW_MODE_GRID = 'grid';
24
25
    protected $hasLayeredNavigation;
26
    protected $productList;
27
    protected $productGrid;
28
29
    protected $statedProductCount;
30
    protected $viewMode;
31
    protected $sortBy;
32
    protected $showCount;
33
    protected $showCountOptions;
34
35
    protected $products;
36
37
    protected $elementTest;
38
39
    /**
40
     * @var ThemeConfiguration
41
     */
42
43
    protected $theme;
44
45
    public function __construct(
46
        WebDriver $webDriver,
47
        AbstractMagentoTestCase $testCase,
48
        AbstractThemeConfiguration $theme,
49
        HasLayeredNavigation $hasLayeredNavigation,
50
        ProductList $productList,
51
        ProductGrid $productGrid
52
    )
53
    {
54
        parent::__construct($webDriver, $testCase, $theme);
55
        $this->hasLayeredNavigation = $hasLayeredNavigation;
56
        $this->productList = $productList;
57
        $this->productGrid = $productGrid;
58
    }
59
60
    public function getStatedProductCount()
61
    {
62
        return $this->statedProductCount;
63
    }
64
65
    public function getStatedProductCountNumber()
66
    {
67
        return (int)$this->getStatedProductCount();
68
    }
69
70
    public function getCalculatedProductCount()
71
    {
72
        return count($this->getProducts());
73
    }
74
75
    public function getViewMode()
76
    {
77
        return $this->viewMode;
78
    }
79
80
    public function getSortBy()
81
    {
82
        return $this->sortBy;
83
    }
84
85
    public function getShowCount()
86
    {
87
        return $this->showCount;
88
    }
89
90
    public function getShowCountOptions()
91
    {
92
        return $this->showCountOptions;
93
    }
94
95
    /**
96
     * @return array
97
     */
98
99
    public function getProducts()
100
    {
101
        if ($this->getViewMode() == self::VIEW_MODE_GRID) {
102
            return $this->productGrid->getProductList();
103
        } else if ($this->getViewMode() == self::VIEW_MODE_LIST) {
104
            return $this->productList->getProductList();
105
        }
106
    }
107
108
    public function hasLayeredNavigation()
109
    {
110
        return $this->hasLayeredNavigation->hasLayeredNavigation();
111
    }
112
113
    public function extract()
114
    {
115
        if ($this->elementTest instanceof WebDriverElement && $this->webDriver->elementAttached($this->elementTest)) {
116
            return;
117
        }
118
119
        // For some reason Firefox sometimes cannot find the body element, so we'll wait for it to exist instead.
120
        $this->webDriver->wait()->until(ExpectedCondition::elementExists('//body', 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...
121
122
        $this->elementTest = $this->webDriver->byXpath('//body');
123
124
        $element = $this->webDriver->byXpath($this->theme->getProductCollectionProductCountXpath());
125
        $this->statedProductCount = trim($element->getText());
126
127
        $element = $this->webDriver->byXpath($this->theme->getProductCollectionViewModeXpath());
128
        $this->viewMode = strtolower($element->getAttribute($this->theme->getViewModeAttributeName()));
129
130
        $element = $this->webDriver->byXpath($this->theme->getProductCollectionSortByXpath());
131
        $this->sortBy = trim($element->getText());
132
133
        $element = $this->webDriver->byXpath($this->theme->getProductCollectionShowCountXpath());
134
        $this->showCount = trim($element->getText());
135
136
        $this->showCountOptions = [];
137
        $elements = $this->webDriver->findElements(WebDriverBy::xpath($this->theme->getProductCollectionShowCountOptionsXpath()));
138
        foreach ($elements as $element) {
139
            $this->showCountOptions[] = trim($element->getText());
140
        }
141
    }
142
}