Issues (87)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/model/EcommerceDashboardPanel.php (20 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class EcommerceDashboardPanel extends DashboardPanel
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
6
7
    /**
8
     * @var bool Show the configure form after creating. Used for panels that require
9
     * configuration in order to show data
10
     */
11
    private static $configure_on_create = true;
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...
The property $configure_on_create 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
13
14
    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...
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...
15
        'DaysBack' => 'Int'
16
    );
17
18
    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...
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...
19
        'DaysBack' => 7
20
    );
21
22
23
    private static $icon = "ecommerce_dashboard/images/icons";
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...
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...
24
25
    public function getLabel()
26
    {
27
        return $this->getLabelPrefix();
28
    }
29
30
    public function getTitle()
31
    {
32
        $str = $this->getLabelPrefix();
33
        if ($this->DaysBack) {
0 ignored issues
show
The property DaysBack does not exist on object<EcommerceDashboardPanel>. 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...
34
            $str .= ' '.sprintf(_t('EcommerceDashboardPanel.IN_THE_LAST_XXX_DAYS', 'in the last %s days.'), $this->DaysBack);
0 ignored issues
show
The property DaysBack does not exist on object<EcommerceDashboardPanel>. 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...
35
        }
36
        return $str;
37
    }
38
39
    public function getLabelPrefix()
40
    {
41
        return 'please set in '.$this->ClassName;
42
    }
43
44
    public function getConfiguration()
45
    {
46
        $fields = parent::getConfiguration();
47
        $fields->push(NumericField::create("DaysBack", "Number of days back"));
48
        $fields->replaceField('Title', ReadonlyField::create('Title', ''));
49
50
        return $fields;
51
    }
52
53
    /**
54
     *
55
     *
56
     * @return DataList
57
     */
58
    protected function openOrders($numberOfDaysBack = 7)
0 ignored issues
show
The parameter $numberOfDaysBack is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        $firstStep = DataObject::get_one('OrderStep');
61
        $orders = Order::get()
62
            ->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"')
63
            ->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"')
0 ignored issues
show
The variable $submittedOrderStatusLogClassName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
64
            ->filter(array('StatusID' => $firstStep->ID))
65
            ->exclude(array('MemberID' => $this->excludedMembers()));
0 ignored issues
show
The method excludedMembers() does not exist on EcommerceDashboardPanel. Did you maybe mean excludedMembersArray()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
67
        return $orders;
68
    }
69
70
    /**
71
     *
72
     *
73
     * @return DataList
74
     */
75
    protected function submittedOrders($numberOfDaysBack = 0)
76
    {
77
        $orders = Order::get_datalist_of_orders_with_submit_record();
78
        $orders = $orders
79
            ->exclude(array('MemberID' => $this->excludedMembersArray()))
80
            ->where($this->daysBackWhereStatement($numberOfDaysBack));
81
82
        return $orders;
83
    }
84
85
    /**
86
     *
87
     *
88
     * @return DataList
89
     */
90
    protected function archivedOrders($numberOfDaysBack = 0)
91
    {
92
        $submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order');
93
        $lastStep = OrderStep::last_order_step();
94
        return Order::get()
95
            ->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"')
96
            ->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"')
97
            ->filter(array('StatusID' => $lastStep->ID))
98
            ->exclude(array('MemberID' => $this->excludedMembersArray()))
99
            ->where($this->daysBackWhereStatement($numberOfDaysBack));
100
        return $orders;
0 ignored issues
show
return $orders; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
101
    }
102
103
104
105
    /**
106
     * An accessor to the Dashboard controller
107
     *
108
     * @return Dashboard
109
     */
110
    public function getDashboard()
111
    {
112
        return Injector::inst()->get("EcommerceDashboard");
113
    }
114
115
    /**
116
     *
117
     *
118
     * @var array
119
     */
120
    private static $_excluded_members_array = array();
121
122
    /**
123
     *
124
     *
125
     * @return array array of member IDs
126
     */
127
    protected function excludedMembersArray()
128
    {
129
        if (! count(self::$_excluded_members_array)) {
130
            self::$_excluded_members_array = array(-1 => -1);
131
            $adminGroup = EcommerceRole::get_admin_group();
132
            $assitantGroup = EcommerceRole::get_assistant_group();
133
            if ($adminGroup) {
134
                foreach ($adminGroup->Members() as $member) {
135
                    self::$_excluded_members_array[$member->ID] = $member->ID;
136
                }
137
            }
138
            if ($assitantGroup) {
139
                foreach ($assitantGroup->Members() as $member) {
140
                    self::$_excluded_members_array[$member->ID] = $member->ID;
141
                }
142
            }
143
        }
144
145
        return self::$_excluded_members_array;
146
    }
147
148
    /**
149
     *
150
     *
151
     * @return string where statement for orders that have been submitted.
152
     */
153
    protected function daysBackWhereStatement($daysBack = 0)
154
    {
155
        if (! $daysBack) {
156
            $daysBack = $this->DaysBack ? $this->DaysBack : $this->Config()->defaults['DaysBack'];
0 ignored issues
show
The property DaysBack does not exist on object<EcommerceDashboardPanel>. 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...
157
        }
158
        return '"OrderStatusLog"."Created" > ( NOW() - INTERVAL '.($daysBack).' DAY )';
159
    }
160
161
    /**
162
     * @var int The "weight" of the dashboard panel when listed in the available panels.
163
     *			Higher is lower in the list.
164
     */
165
    //private static $priority = 100;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
167
168
169
    /**
170
     * @var string The name of the template used for the contents of this panel.
171
     */
172
    //protected $template;
173
174
    public function maxOrdersForLoop()
175
    {
176
        return 500;
177
    }
178
179
180
    /**
181
     * Allows the panel to be added
182
     *
183
     * @return string
184
     */
185
    public function registered()
186
    {
187
        $enabled = Config::inst()->get($this->ClassName, 'enabled');
188
        if (is_bool($enabled)) {
189
            return self::config()->enabled;
190
        }
191
        if (strtolower(self::config()->enabled) == 'no') {
0 ignored issues
show
This if statement, and the following return statement can be replaced with return !(strtolower(self...g()->enabled) == 'no');.
Loading history...
192
            return false;
193
        }
194
        return true;
195
    }
196
197
    protected function CalculatedDaysBack()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
198
    {
199
        return $this->DaysBack ? : 7;
0 ignored issues
show
The property DaysBack does not exist on object<EcommerceDashboardPanel>. 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...
200
    }
201
}
202