Issues (41)

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.

src/controllers/CartController.php (5 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
 * Cart module for Yii2
5
 *
6
 * @link      https://github.com/hiqdev/yii2-cart
7
 * @package   yii2-cart
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\yii2\cart\controllers;
13
14
use hiqdev\yii2\cart\NotPurchasableException;
15
use hiqdev\yii2\cart\ShoppingCart;
16
use hiqdev\yii2\cart\widgets\CartTeaser;
17
use Yii;
18
use yii\base\ViewContextInterface;
19
use yii\data\ArrayDataProvider;
20
use yii\web\Controller;
21
use yii\web\NotFoundHttpException;
22
23
/**
24
 * Cart controller.
25
 *
26
 * @property ShoppingCart $cart The shopping cart instance
27
 */
28
class CartController extends Controller implements ViewContextInterface
29
{
30
    /**
31
     * @return ShoppingCart
32
     */
33
    public function getCart()
34
    {
35
        return $this->module->getCart();
36
    }
37
38
    public function actionIndex()
39
    {
40
        $cart = $this->getCart();
41
        $dataProvider = new ArrayDataProvider([
42
            'allModels' => $cart->getRootPositions(),
43
            'pagination' => false
44
        ]);
45
46
        if (Yii::$app->request->isAjax) {
47
            return $this->renderAjax('index', [
48
                'cart' => $cart,
49
                'module' => $this->module,
50
                'dataProvider' => $dataProvider,
51
            ]);
52
        }
53
54
        return $this->render('index', [
55
            'cart' => $cart,
56
            'module' => $this->module,
57
            'dataProvider' => $dataProvider,
58
        ]);
59
    }
60
61
    public function actionTopcart()
62
    {
63
        return $this->renderPartial('topcart', ['widgetClass' => CartTeaser::class]);
64
    }
65
66
    public function actionRemove($id)
67
    {
68
        try {
69
            $this->getCart()->removeById($id);
70
        } catch (NotPurchasableException $exception) {
71
            Yii::$app->getSession()->setFlash('error', $exception->getMessage());
0 ignored issues
show
The method getSession does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
72
            $exception->resolve();
0 ignored issues
show
The call to the method hiqdev\yii2\cart\NotPurc...bleException::resolve() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
73
        }
74
75
        if (Yii::$app->request->isAjax) {
76
            Yii::$app->end();
77
        }
78
79
        return $this->redirect(['index']);
80
    }
81
82
    public function actionUpdateQuantity()
83
    {
84
        $request = Yii::$app->request;
85
        $id = $request->post('id');
86
        $quantity = $request->post('quantity');
87
        if ($id && $quantity) {
88
            $position = $this->getCart()->getPositionById($id);
89
            if ($position) {
90
                try {
91
                    $this->getCart()->update($position, $quantity);
92
                } catch (NotPurchasableException $exception) {
93
                    Yii::$app->getSession()->setFlash('error', $exception->getMessage());
0 ignored issues
show
The method getSession does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
94
                    $exception->resolve();
0 ignored issues
show
The call to the method hiqdev\yii2\cart\NotPurc...bleException::resolve() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
95
                }
96
97
                return $this->redirect('index');
98
            }
99
        }
100
101
        throw new NotFoundHttpException('Either position ID or Quantity is not set');
102
    }
103
104
    public function actionClear()
105
    {
106
        $this->getCart()->removeAll();
107
108
        if (Yii::$app->request->isAjax) {
109
            Yii::$app->end();
110
        }
111
112
        return $this->redirect(['index']);
113
    }
114
115
    public function getViewPath()
116
    {
117
        if ($this->getCart()->module->viewPath) {
118
            return Yii::getAlias($this->getCart()->module->viewPath . DIRECTORY_SEPARATOR . 'cart');
0 ignored issues
show
Bug Compatibility introduced by
The expression \Yii::getAlias($this->ge...RY_SEPARATOR . 'cart'); of type string|boolean adds the type boolean to the return on line 118 which is incompatible with the return type declared by the interface yii\base\ViewContextInterface::getViewPath of type string.
Loading history...
119
        }
120
121
        return parent::getViewPath();
122
    }
123
}
124