Issues (201)

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/StockControlController.php (10 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
 * @author Nicolaas [at] sunnysideup.co.nz
4
 * @package: ecommerce
5
 * @sub-package: ecommerce_stockcontrol
6
 * @description:
7
 *  This is the central management page for organising stock control
8
 *  You will need to "turn on" the MinMaxModifier and add MinMaxModifier::set_use_stock_quantities(true)
9
 *  to get this page working.
10
 *
11
 *
12
 **/
13
14
15
16
17
class StockControlController extends ContentController
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...
18
{
19
    private static $allowed_actions = 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 $allowed_actions 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...
20
        "update" => "SHOPADMIN",
21
        "history" => "SHOPADMIN"
22
    );
23
24
    public function init()
25
    {
26
        // Only administrators can run this method
27
        $shopAdminCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code");
28
        if (!Permission::check("ADMIN") && !Permission::check($shopAdminCode)) {
29
            Security::permissionFailure($this, _t('Security.PERMFAILURE', ' This page is secured and you need administrator rights to access it. Enter your credentials below and we will send you right along.'));
30
        }
31
        parent::init();
32
33
        Requirements::themedCSS("StockControlPage", 'ecommerce_stockcontrol');
34
        Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
35
        //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js");
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
36
        //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
37
        Requirements::javascript("ecommerce_stockcontrol/javascript/StockControlPage.js");
38
        $url = Director::absoluteURL($this->Link()."update/");
39
        Requirements::customScript("StockControlPage.set_url('".$url."');", "StockControlPage.set_url");
40
    }
41
42
    public function Link($action = null)
43
    {
44
        $link =  "/update-stock/";
45
        if ($action) {
46
            $link .=  $action ."/";
47
        }
48
        return $link;
49
    }
50
51
    public function StockProductObjects()
52
    {
53
        $buyableStockCalculatedQuantities = BuyableStockCalculatedQuantity::get()->limit(1000);
54
        if ($buyableStockCalculatedQuantities->count()) {
55
            foreach ($buyableStockCalculatedQuantities as $buyableStockCalculatedQuantity) {
56
                $buyable = $buyableStockCalculatedQuantity->Buyable();
57
                if ($buyable) {
58
                    if ($buyable->UnlimitedStock) {
59
                        $buyableStockCalculatedQuantities->remove($buyableStockCalculatedQuantity);
60
                    } else {
61
                        $buyableStockCalculatedQuantity->calculatedBaseQuantity();
62
                    }
63
                } else {
0 ignored issues
show
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...
64
                    //user_error("Buyable can not be found!", E_USER_NOTICE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
65
                }
66
            }
67
            return $buyableStockCalculatedQuantities;
68
        }
69
    }
70
71
    public function update($request = null)
72
    {
73
        $id = intval($request->param("ID"));
74
        $newValue = intval($request->param("OtherID"));
75
        if ($newValue || $newValue === 0) {
76
            $obj = BuyableStockCalculatedQuantity::get()->byID($id);
77
            if ($obj) {
78
                if ($buyable = $obj->getBuyable()) {
79
                    $buyable->setActualQuantity($newValue);
80
                    $msg = "<em>".$obj->Name . "</em> quantity updated to <strong>".$newValue."</strong>";
81
                    return $this->customise(array("Message" => $msg))->renderWith("UpdateStockQuantity");
82
                } else {
83
                    user_error("Could not create Calculation object", E_USER_NOTICE);
84
                }
85
            } else {
86
                user_error("could not find record: $id ", E_USER_NOTICE);
87
            }
88
        } else {
89
            user_error("new quantity specified is unknown", E_USER_NOTICE);
90
        }
91
    }
92
93
    public function history($request = null)
94
    {
95
        $id = intval($request->param("ID"));
96
        $buyableStockCalculatedQuantity = BuyableStockCalculatedQuantity::get()->byID($id);
97
        if ($buyableStockCalculatedQuantity) {
98
            $buyableStockCalculatedQuantity->ManualUpdates = BuyableStockManualUpdate::get()->filter(array('ParentID' => $buyableStockCalculatedQuantity->ID));
99
            $buyableStockCalculatedQuantity->OrderEntries = BuyableStockOrderEntry::get()->filter(array('ParentID' => $buyableStockCalculatedQuantity->ID));
100
            $graphArray = array();
0 ignored issues
show
$graphArray is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
101
            if ($buyableStockCalculatedQuantity->ManualUpdates) {
102
                foreach ($buyableStockCalculatedQuantity->ManualUpdates as $obj) {
0 ignored issues
show
This foreach statement is empty and can be removed.

This check looks for foreach loops 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.

Consider removing the loop.

Loading history...
103
                }
104
            }
105
            if ($buyableStockCalculatedQuantity->OrderEntries) {
106
                foreach ($buyableStockCalculatedQuantity->OrderEntries as $obj) {
0 ignored issues
show
This foreach statement is empty and can be removed.

This check looks for foreach loops 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.

Consider removing the loop.

Loading history...
107
                }
108
            }
109
            return $this->customise($buyableStockCalculatedQuantity)->renderWith("AjaxStockControlPageHistory");
110
        } else {
111
            return " could not find historical data";
112
        }
113
    }
114
}
115