Issues (15)

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.

src/CartItem.php (7 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
namespace jamesdb\Cart;
4
5
use ArrayAccess;
6
use jamesdb\Cart\Exception\CartPropertyNotIntegerException;
7
use Money\Currency;
8
9
class CartItem implements ArrayAccess
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $item = [];
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param array $data
20
     */
21 51
    public function __construct(array $data = [])
22
    {
23
        $defaults = [
24 51
            'options'  => [],
25 51
            'price'    => 0,
26 51
            'quantity' => 1,
27
            'tax'      => 0
28 51
        ];
29
30 51
        $data = array_merge($defaults, $data);
31
32 51
        foreach ($data as $key => $value) {
33 51
            $this->set($key, $value);
34 51
        }
35 51
    }
36
37
    /**
38
     * Return the rowid of item.
39
     *
40
     * @return string
41
     */
42 45
    public function getRowId()
43
    {
44 45
        $rowId = $this->item;
45
46 45
        $ignoredProperties = ['quantity'];
47
48 45
        foreach ($ignoredProperties as $property) {
49 45
            if (array_key_exists($property, $rowId)) {
50 45
                unset($rowId[$property]);
51 45
            }
52 45
        }
53
54 45
        return md5(serialize($rowId));
55
    }
56
57
    /**
58
     * Set property key and value.
59
     *
60
     * @param  string $key
61
     * @param  mixed  $value
62
     *
63
     * @throws \jamesdb\Cart\Exception\CartPropertyNotIntegerException
64
     *
65
     * @return void
66
     */
67 51
    public function set($key, $value)
68
    {
69 51
        $numeric = ['price', 'tax', 'quantity'];
70
71 51
        if ((in_array($key, $numeric)) && (! is_int($value))) {
72 3
            throw new CartPropertyNotIntegerException(
73 3
                sprintf('The [%s] property must be an integer', $key)
74 3
            );
75
        }
76
77 51
        $this->item[$key] = $value;
78 51
    }
79
80
    /**
81
     * Get a property by key.
82
     *
83
     * @param  string $key
84
     *
85
     * @return mixed
86
     */
87 39
    public function get($key)
88
    {
89 39
        if ($key === 'rowid') {
90 3
            return $this->getRowId();
91
        }
92
93 36
        return $this->item[$key];
94
    }
95
96
    /**
97
     * Return item price excluding tax.
98
     *
99
     * @param  \Money\Currency $currency
100
     *
101
     * @return \Money\Money
102
     */
103 3
    public function getPriceExcludingTax(Currency $currency)
104
    {
105 3
        return (new Money($this->price, $currency))->getMoney()->multiply($this->quantity);
0 ignored issues
show
The property price does not exist on object<jamesdb\Cart\CartItem>. 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...
The property quantity does not exist on object<jamesdb\Cart\CartItem>. 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...
106
    }
107
108
    /**
109
     * Return item price including tax.
110
     *
111
     * @param  \Money\Currency $currency
112
     *
113
     * @return \Money\Money
114
     */
115 6
    public function getPrice(Currency $currency)
116
    {
117 6
        return (new Money($this->price + $this->tax, $currency))->getMoney()->multiply($this->quantity);
0 ignored issues
show
The property price does not exist on object<jamesdb\Cart\CartItem>. 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...
The property tax does not exist on object<jamesdb\Cart\CartItem>. 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...
The property quantity does not exist on object<jamesdb\Cart\CartItem>. 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...
118
    }
119
120
    /**
121
     * Return the item tax.
122
     *
123
     * @param  \Money\Currency $currency
124
     *
125
     * @return \Money\Money
126
     */
127 3
    public function getTax(Currency $currency)
128
    {
129 3
        return (new Money($this->tax, $currency))->getMoney()->multiply($this->quantity);
0 ignored issues
show
The property tax does not exist on object<jamesdb\Cart\CartItem>. 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...
The property quantity does not exist on object<jamesdb\Cart\CartItem>. 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...
130
    }
131
132
    /**
133
     * Export the item as array.
134
     *
135
     * @return array
136
     */
137 42
    public function toArray()
138
    {
139
        return [
140 42
            'id'   => $this->getRowId(),
141 42
            'data' => $this->item
142 42
        ];
143
    }
144
145
    /**
146
     * Set property key and value.
147
     *
148
     * @param  string $key
149
     * @param  mixed  $value
150
     *
151
     * @return void
152
     */
153 21
    public function __set($key, $value)
154
    {
155 21
        $this->set($key, $value);
156 18
    }
157
158
    /**
159
     * Get a property by key.
160
     *
161
     * @param  string $key
162
     *
163
     * @return mixed
164
     */
165 36
    public function __get($key)
166
    {
167 36
        return $this->get($key);
168
    }
169
170
    /**
171
     * Array Access get.
172
     *
173
     * @param  string $offset
174
     *
175
     * @return boolean
176
     */
177 6
    public function offsetExists($offset)
178
    {
179 6
        return isset($this->item[$offset]);
180
    }
181
182
    /**
183
     * Array Access get.
184
     *
185
     * @param  string $offset
186
     *
187
     * @return mixed
188
     */
189 6
    public function offsetGet($offset)
190
    {
191 6
        return $this->get($offset);
192
    }
193
194
    /**
195
     * Array Access set.
196
     *
197
     * @param  string $key
198
     * @param  mixed  $value
199
     *
200
     * @return void
201
     */
202 3
    public function offsetSet($key, $value)
203
    {
204 3
        $this->set($key, $value);
205 3
    }
206
207
    /**
208
     * Array Access unset.
209
     *
210
     * @param  string $offset
211
     *
212
     * @return void
213
     */
214 3
    public function offsetUnset($offset)
215
    {
216 3
        unset($this->item[$offset]);
217 3
    }
218
}
219