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.

EcommerceDashboardPanel_OrderCount::Content()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 0
dl 0
loc 52
rs 8.7361
c 0
b 0
f 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
class EcommerceDashboardPanel_OrderCount 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_OrderCount.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 $has_one = 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 $has_one 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
        'EcommerceCurrency' => 'EcommerceCurrency'
9
    );
10
11
    public function getLabelPrefix()
12
    {
13
        $currencyStatement = '';
14 View Code Duplication
        if ($currency = $this->EcommerceCurrency()) {
0 ignored issues
show
Documentation Bug introduced by
The method EcommerceCurrency does not exist on object<EcommerceDashboardPanel_OrderCount>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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...
15
            if ($currency->exists()) {
16
                $currencyStatement = ", in ".$currency->Code.', ';
17
            }
18
        }
19
        return 'Orders Placed'.$currencyStatement;
20
    }
21
22
23
    public function getConfiguration()
24
    {
25
        $fields = parent::getConfiguration();
26
        $fields->push(
27
            DropdownField::create(
28
                "EcommerceCurrencyID",
29
                "Currency",
30
                EcommerceCurrency::get()->map()
31
            )
32
        );
33
34
        return $fields;
35
    }
36
37
    public function Content()
38
    {
39
        $submittedOrders = $this->submittedOrders();
40
        $submittedOrders = $submittedOrders->filter(array('CurrencyUsedID' => $this->EcommerceCurrencyID));
0 ignored issues
show
Documentation introduced by
The property EcommerceCurrencyID does not exist on object<EcommerceDashboardPanel_OrderCount>. 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...
41
        $count = $submittedOrders->count();
42
        $sum = 0;
43
        $itemCount = 0;
44
        $html = '
45
            <dl>';
46
        $html .= '
47
                <dt>Count of orders</dt>
48
                <dd>'.$count.'</dd>';
49
        if ($count < $this->maxOrdersForLoop() && $count > 0) {
50
            foreach ($submittedOrders as $order) {
51
                $sum += $order->getSubTotal();
52
                $itemCount += $order->getTotalItemsTimesQuantity();
53
            }
54
            $sumDBField = DBField::create_field('Currency', $sum);
55
            $html .= '
56
                    <dt>Sum of sub-totals</dt>
57
                    <dd>'.$sumDBField->Nice().'</dd>';
58
            $averagePerOrder =  ($sum / $count);
59
            $averagePerOrderDBField = DBField::create_field('Currency', $averagePerOrder);
60
            $html .= '
61
                    <dt>Average sub-total per order</dt>
62
                    <dd>'.$averagePerOrderDBField->Nice().'</dd>';
63
            $html .= '
64
                    <dt>Total count of items sold</dt>
65
                    <dd>'.$itemCount.'</dd>';
66
            $itemCountPerOrder = round($itemCount / $count, 3);
67
            $html .= '
68
                    <dt>Average items sold per order</dt>
69
                    <dd>'.$itemCountPerOrder.'</dd>';
70
            $costPerItem = $sum / $itemCount;
71
            $costPerItemDBField = DBField::create_field('Currency', $costPerItem);
72
            $html .= '
73
                    <dt>Average cost per item</dt>
74
                    <dd>'.$costPerItemDBField->Nice().'</dd>';
75
        } elseif ($count >= $this->maxOrdersForLoop()) {
76
            $html .= '
77
                    <dt>Sum of sub-totals</dt>
78
                    <dd>Please reduce the number of orders to calculate the total.</dd>';
79
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
80
            //..
81
        }
82
83
84
        $html .= '
85
            </dl>';
86
87
        return $html;
88
    }
89
}
90