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.

Content()   B
last analyzed

Complexity

Conditions 10
Paths 3

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 3
nop 0
dl 0
loc 44
rs 7.6666
c 0
b 0
f 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
class EcommerceDashboardPanel_FavouriteProducts extends EcommerceDashboardPanel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private static $icon = "ecommerce_dashboard/images/icons/EcommerceDashboardPanel_FavouriteProducts.png";
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
6
7
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
8
        'NumberOfProducts' => 'Int'
9
    );
10
11
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        'NumberOfProducts' => 7
13
    );
14
15
    public function getLabelPrefix()
16
    {
17
        return 'Favourite sellers';
18
    }
19
20
    public function getTitle()
21
    {
22
        return parent::getTitle();
23
    }
24
25
    public function getConfiguration()
26
    {
27
        $fields = parent::getConfiguration();
28
        $fields->push(NumericField::create('NumberOfProducts', 'Number of products to show'));
29
        return $fields;
30
    }
31
32
    public function Content()
33
    {
34
        $submittedOrders = $this->submittedOrders();
35
        $html = '
36
            <ul>';
37
        $buyableArray = array();
38
        $count = $submittedOrders->count();
39
        if ($count < $this->maxOrdersForLoop() && $count > 0) {
40
            foreach ($submittedOrders as $order) {
41
                foreach ($order->Items() as $item) {
42
                    $key = $item->BuyableClassName.".".$item->BuyableID;
43
                    if (! isset($buyableArray[$key])) {
44
                        $buyableArray[$key] = 0;
45
                    }
46
                    $buyableArray[$key]++;
47
                }
48
            }
49
            arsort($buyableArray, SORT_NUMERIC);
50
            for ($i = 0; $i < $this->NumberOfProducts; $i++) {
0 ignored issues
show
Documentation introduced by
The property NumberOfProducts does not exist on object<EcommerceDashboardPanel_FavouriteProducts>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
51
                $oneRow = array_slice($buyableArray, $i, 1);
52
                foreach ($oneRow as $key => $count) {
53
                    list($className, $id) = explode('.', $key);
54
                    $buyable = $className::get()->byID($id);
55
                    if ($buyable) {
56
                        $html .= '<li class="pos'.$i.'"><span><strong>'.$count.'</strong> × </span><a href="'.$buyable->Link().'">'.$buyable->FullName.'</a></li>';
57
                    } else {
58
                        $html .= '<li class="pos'.$i.'">Error with '.$key.'</li>';
59
                    }
60
                }
61
            }
62
        } elseif ($count >= $this->maxOrdersForLoop()) {
63
            $html .= '
64
                    <li>There are too many orders to work out the favourite products, please reduce the time period.</li>';
65
        } else {
66
            $html .= '
67
                    <li>There are no favourite sellers.</li>';
68
        }
69
70
71
        $html .= '
72
            </ul>';
73
74
        return $html;
75
    }
76
}
77