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.

AbstractProductCollection   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 73
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
getElementXpath() 0 1 ?
A getProductList() 0 5 1
A getByXpath() 0 15 4
B extract() 0 37 5
1
<?php
2
3
namespace Magium\Magento\Extractors\Catalog\Products;
4
5
6
use Facebook\WebDriver\WebDriverElement;
7
use Magium\Extractors\AbstractExtractor;
8
use Magium\WebDriver\WebDriver;
9
10
abstract class AbstractProductCollection extends AbstractExtractor
11
{
12
13
    protected $products = [];
14
    protected $testElement;
15
16
    abstract function getElementXpath($type, $count);
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
18
    /**
19
     * @return ProductSummary[]
20
     */
21
22
    public function getProductList()
23
    {
24
        $this->extract();
25
        return $this->products;
26
    }
27
28
    protected function getByXpath($type, $count, $attribute = null, $getElement = false)
29
    {
30
        $xpath = $this->getElementXpath($type, $count);
31
        if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) {
32
            $element = $this->webDriver->byXpath($xpath);
33
            if ($getElement) {
34
                return $element;
35
            } else if ($attribute) {
36
                return $element->getAttribute($attribute);
37
            } else {
38
                return trim($element->getText());
39
            }
40
        }
41
        return null;
42
    }
43
44
    public function extract()
45
    {
46
        if ($this->testElement instanceof WebDriverElement && $this->webDriver->elementAttached($this->testElement)) {
47
            return;
48
        }
49
        $this->testElement = $this->webDriver->byXpath('//body');
50
        $this->products = [];
51
        $count = 0;
52
        while ($this->webDriver->elementExists($this->getElementXpath(ProductSummary::TITLE, ++$count), WebDriver::BY_XPATH)) {
53
            $title = $this->getByXpath(ProductSummary::TITLE, $count);
54
            $price = $this->getByXpath(ProductSummary::PRICE, $count);
55
            $link = $this->getByXpath(ProductSummary::LINK, $count, 'href');
56
            $image = $this->getByXpath(ProductSummary::IMAGE, $count, 'src');
57
            $originalPrice = $this->getByXpath(ProductSummary::ORIGINAL_PRICE, $count);
58
            if ($originalPrice === null) {
59
                $originalPrice = $price;
60
            }
61
            $wishlistLink = $this->getByXpath(ProductSummary::WISHLIST_LINK, $count, null, true);
62
            $compareLink = $this->getByXpath(ProductSummary::COMPARE_LINK, $count, null, true);
63
            $description = $this->getByXpath(ProductSummary::DESCRIPTION, $count);
64
            $addToCartLink = $this->getByXpath(ProductSummary::ADD_TO_CART_LINK, $count, null, true);
65
66
            $product = new ProductSummary(
67
                $title,
68
                $price,
69
                $link,
70
                $image,
71
                $originalPrice,
72
                $wishlistLink,
0 ignored issues
show
Bug introduced by
It seems like $wishlistLink defined by $this->getByXpath(\Magiu...NK, $count, null, true) on line 61 can also be of type string; however, Magium\Magento\Extractor...tSummary::__construct() does only seem to accept null|object<Facebook\WebDriver\WebDriverElement>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
73
                $compareLink,
0 ignored issues
show
Bug introduced by
It seems like $compareLink defined by $this->getByXpath(\Magiu...NK, $count, null, true) on line 62 can also be of type string; however, Magium\Magento\Extractor...tSummary::__construct() does only seem to accept null|object<Facebook\WebDriver\WebDriverElement>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
74
                $description,
75
                $addToCartLink
0 ignored issues
show
Bug introduced by
It seems like $addToCartLink defined by $this->getByXpath(\Magiu...NK, $count, null, true) on line 64 can also be of type string; however, Magium\Magento\Extractor...tSummary::__construct() does only seem to accept null|object<Facebook\WebDriver\WebDriverElement>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
            );
77
78
            $this->products[] = $product;
79
        }
80
    }
81
82
}