Issues (13)

Security Analysis    no request data  

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/AddToCartPage.php (11 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
/**
4
 *
5
 *@author nicolaas [at] sunnysideup.co.nz
6
 *
7
 **/
8
9
class AddToCartPage extends Page
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...
10
{
11
    private static $icon = "ecommerce_quick_add/images/treeicons/AddToCartPage";
0 ignored issues
show
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...
12
13
    public function canCreate($member = null)
14
    {
15
        return AddToCartPage::get()->count() ? false : true;
16
    }
17
18
    private static $many_many = array(
0 ignored issues
show
The property $many_many 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
        "ExcludedProductsAndGroups" => "SiteTree",
20
    );
21
}
22
23
class AddToCartPage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
24
{
25
    private static $allowed_actions = array(
0 ignored issues
show
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...
26
        "AddMemberToCartForm" => true,
27
        "addmembertocartform_add" => true,
28
        "QuickAddToCartForm" => true,
29
        "quickaddtocartform_add" => true
30
    );
31
32
    public function init()
33
    {
34
        parent::init();
35
        Requirements::themedCSS('Products', 'ecommerce');
36
        Requirements::themedCSS('AddToCartPage', 'ecommerce_quick_add');
37
        Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
38
        //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...
39
        //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...
40
        Requirements::javascript(THIRDPARTY_DIR."/jquery-form/jquery.form.js");
41
        Requirements::javascript("ecommerce_quick_add/javascript/AddToCartPage.js");
42
    }
43
44
    public function AddMemberToCartForm()
45
    {
46
        $member = Member::currentUser();
47
        $order = ShoppingCart::current_order();
48
        $currentCustomer = $order->CreateOrReturnExistingMember(false);
49
        if ($member && $member->IsShopAdmin()) {
50
            $fields = new FieldList(
51
                new HeaderField("SelectCustomer", _t("AddToCartPage.SELECTCUSTOMER", "Select Customer")),
52
                new ReadonlyField("CurrentMember", _t("AddToCartPage.CURRENTCUSTOMER", "Current"), $currentCustomer->getTitle()),
53
                new DropdownField("MemberID", _t("AddToCartPage.CUSTOMER", "Change to"), EcommerceRole::list_of_customers(), $currentCustomer->ID)
54
            );
55
            $actions = new FieldList(
56
                new FormAction("addmembertocartform_add", _t("AddToCartPage.ADDMEMBERTOORDER", "Update customer"))
57
            );
58
            $validator = new RequiredFields(array("MemberID"));
59
            return new Form($this, "AddMemberToCartForm", $fields, $actions, $validator);
60
        }
61
    }
62
63
    public function addmembertocartform_add($data, $form)
64
    {
65
        $member = Member::currentUser();
66
        if ($member && $member->IsShopAdmin()) {
67
            $order = ShoppingCart::current_order();
68
            $member = Member::get()->byID(intval($data["MemberID"]));
69
            if ($member) {
70
                if ($member->ID != $order->MemberID) {
71
                    $order->MemberID = $member->ID;
72
                    $order->BillingAddressID = 0;
73
                    $order->ShippingAddressID = 0;
74
                    $order->write();
75
                    $response = $member->getTitle()." "._t("AddToCartPage.ADDED", "customer has been added to order.");
76
                    $status = "good";
77
                } else {
78
                    $response = _t("AddToCartPage.NOCHANGE", "The order has not been changed.");
79
                    $status = "good";
80
                }
81
            } else {
82
                $response = _t("AddToCartPage.CUSTOMERNOTADDED", "Customer could not be added.");
83
                $status = "bad";
84
            }
85
            if (Director::is_ajax()) {
86
                return $response;
87
            } else {
88
                $form->setMessage($response, $status);
89
                $this->redirectBack();
90
            }
91
        }
92
    }
93
94
    public function QuickAddToCartForm()
95
    {
96
        $fields = new FieldList(
97
            new HeaderField("SelectCustomer", _t("AddToCartPage.ADDPRODUCTS", "Add Products to your order")),
98
            new HiddenField("BuyableID"),
99
            new HiddenField("BuyableClassName"),
100
            new HiddenField("Version"),
101
            new BuyableSelectField("FindBuyable", _t("AddToCartPage.PRODUCT", "Product")),
102
            new NumericField("Quantity", _t("AddToCartPage.QUANTITY", "Quantity"), 1)
103
        );
104
        $actions = new FieldList(
105
            new FormAction("quickaddtocartform_add", _t("AddToCartPage.ADD", "Add"))
106
        );
107
        $validator = new RequiredFields(array("Quantity"));
108
        return new Form($this, "QuickAddToCartForm", $fields, $actions, $validator);
109
    }
110
111
    public function quickaddtocartform_add($data, $form)
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...
112
    {
113
        $shoppingCart = ShoppingCart::singleton();
114
        $buyableID = intval($data["BuyableID"]);
115
        $buyableClassName = Convert::raw2sql($data["BuyableClassName"]);
116
        $version = Intval($data["Version"]);
0 ignored issues
show
$version 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...
117
        $quantity = floatval($data["Quantity"]);
118
        $status = "bad";
119
        $message = _t("AddToCartPage.ERRORPRODUCTNOTADDED", "ERROR: Product Not Added - make sure to find a product first.");
120
        if (class_exists($buyableClassName) && EcommerceDBConfig::is_buyable($buyableClassName)) {
0 ignored issues
show
It seems like $buyableClassName defined by \Convert::raw2sql($data['BuyableClassName']) on line 115 can also be of type array; however, EcommerceDBConfig::is_buyable() does only seem to accept string, 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...
121
            $buyable = $buyableClassName::get()->byID($buyableID);
122
            if ($buyable) {
123
                $shoppingCart->addBuyable($buyable, $quantity);
124
                $status = "good";
125
                $message = _t("AddToCartPage.ADDED", "Added");
126
            }
127
        }
128
        if (Director::is_ajax()) {
129
            return $shoppingCart->setMessageAndReturn($message, $status, $form);
130
        } else {
131
            $form->setMessage($message, $status);
132
            $this->redirectBack();
133
        }
134
    }
135
}
136