Issues (8)

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/Domain/Model/Cart.php (1 issue)

Severity

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
declare(strict_types = 1);
4
5
namespace SyliusCart\Domain\Model;
6
7
use Broadway\EventSourcing\EventSourcedAggregateRoot;
8
use Money\Currency;
9
use Money\Money;
10
use Ramsey\Uuid\UuidInterface;
11
use SyliusCart\Domain\Adapter\AvailableCurrencies\AvailableCurrenciesProviderInterface;
12
use SyliusCart\Domain\Event\CartCleared;
13
use SyliusCart\Domain\Event\CartInitialized;
14
use SyliusCart\Domain\Event\CartItemAdded;
15
use SyliusCart\Domain\Event\CartItemQuantityChanged;
16
use SyliusCart\Domain\Event\CartItemRemoved;
17
use SyliusCart\Domain\Exception\CartCurrencyMismatchException;
18
use SyliusCart\Domain\Exception\CartCurrencyNotSupportedException;
19
use SyliusCart\Domain\Exception\InvalidCartItemUnitPriceException;
20
use SyliusCart\Domain\ModelCollection\CartItemCollection;
21
use SyliusCart\Domain\ModelCollection\CartItems;
22
use SyliusCart\Domain\ValueObject\CartItemQuantity;
23
use SyliusCart\Domain\ValueObject\ProductCode;
24
25
/**
26
 * @author Arkadiusz Krakowiak <[email protected]>
27
 */
28
final class Cart extends EventSourcedAggregateRoot implements CartContract
29
{
30
    /**
31
     * @var UuidInterface
32
     */
33
    private $cartId;
34
35
    /**
36
     * @var CartItemCollection
37
     */
38
    private $cartItems;
39
40
    /**
41
     * @var Currency
42
     */
43
    private $cartCurrency;
44
45
    /**
46
     * @var AvailableCurrenciesProviderInterface
47
     */
48
    private $availableCurrenciesProvider;
49
50
    /**
51
     * @param AvailableCurrenciesProviderInterface $availableCurrenciesProvider
52
     */
53
    private function __construct(AvailableCurrenciesProviderInterface $availableCurrenciesProvider)
54
    {
55
        $this->availableCurrenciesProvider = $availableCurrenciesProvider;
56
    }
57
58
    /**
59
     * @param UuidInterface $cartId
60
     * @param string $currencyCode
61
     * @param AvailableCurrenciesProviderInterface $availableCurrenciesProvider
62
     *
63
     * @return CartContract
64
     */
65
    public static function initialize(
66
        UuidInterface $cartId,
67
        string $currencyCode,
68
        AvailableCurrenciesProviderInterface $availableCurrenciesProvider
69
    ): CartContract {
70
        $cart = new self($availableCurrenciesProvider);
71
72
        $cartCurrency = new Currency($currencyCode);
73
74
        if (!$cartCurrency->isAvailableWithin($cart->availableCurrenciesProvider->provideAvailableCurrencies())) {
75
            throw new CartCurrencyNotSupportedException();
76
        }
77
78
        $cart->apply(CartInitialized::occur($cartId, $cartCurrency));
79
80
        return $cart;
81
    }
82
83
    /**
84
     * @param AvailableCurrenciesProviderInterface $availableCurrenciesProvider
85
     *
86
     * @return CartContract
87
     */
88
    public static function createWithAdapters(
89
        AvailableCurrenciesProviderInterface $availableCurrenciesProvider
90
    ): CartContract {
91
        return new self($availableCurrenciesProvider);
92
    }
93
94
    /**
95
     * @param string $productCode
96
     * @param int $quantity
97
     * @param int $price
98
     * @param string $productCurrencyCode
99
     */
100
    public function addProductToCart(string $productCode, int $quantity, int $price, string $productCurrencyCode): void
101
    {
102
        $price = new Money($price, new Currency($productCurrencyCode));
103
        $quantity = CartItemQuantity::create($quantity);
104
        $productCode = ProductCode::fromString($productCode);
105
106
        if ($price->isNegative()) {
107
            throw new InvalidCartItemUnitPriceException('Cart item unit price cannot be below zero.');
108
        }
109
110
        if (!$this->cartCurrency->equals($price->getCurrency())) {
111
            throw new CartCurrencyMismatchException($this->cartCurrency, $price->getCurrency());
112
        }
113
114
        $cartItem = CartItem::create(
115
            $productCode,
116
            $quantity,
117
            $price
118
        );
119
120
        $this->apply(CartItemAdded::occur($this->cartId, $cartItem));
121
    }
122
123
    /**
124
     * @param string $productCode
125
     */
126
    public function removeProductFromCart(string $productCode): void
127
    {
128
        $cartItem = $this->cartItems->findOneByProductCode(ProductCode::fromString($productCode));
129
130
        $this->apply(CartItemRemoved::occur($this->cartId, $cartItem->productCode()));
131
    }
132
133
    public function clear(): void
134
    {
135
        if (!$this->cartItems->isEmpty()) {
136
            $this->apply(CartCleared::occur($this->cartId));
137
        }
138
    }
139
140
    /**
141
     * @param string $productCode
142
     * @param int $quantity
143
     */
144
    public function changeProductQuantity(string $productCode, int $quantity): void
145
    {
146
        $productCode = ProductCode::fromString($productCode);
147
        $cartItem = $this->cartItems->findOneByProductCode($productCode);
148
        $newQuantity = CartItemQuantity::create($quantity);
149
150
        $this->apply(CartItemQuantityChanged::occur($this->cartId, $productCode, $cartItem->quantity(), $newQuantity));
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function getAggregateRootId(): UuidInterface
157
    {
158
        return $this->cartId;
159
    }
160
161
    /**
162
     * @param CartInitialized $event
163
     */
164
    protected function applyCartInitialized(CartInitialized $event): void
165
    {
166
        $this->cartId = $event->getCartId();
167
        $this->cartCurrency = $event->getCartCurrency();
168
        $this->cartItems = CartItems::createEmpty();
169
    }
170
171
    /**
172
     * @param CartItemAdded $event
173
     */
174
    protected function applyCartItemAdded(CartItemAdded $event): void
175
    {
176
        $this->cartItems->add($event->getCartItem());
177
    }
178
179
    /**
180
     * @param CartItemRemoved $event
181
     */
182
    protected function applyCartItemRemoved(CartItemRemoved $event): void
183
    {
184
        $cartItem = $this->cartItems->findOneByProductCode($event->getProductCode());
185
        $this->cartItems->remove($cartItem);
186
    }
187
188
    /**
189
     * @param CartCleared $event
190
     */
191
    protected function applyCartCleared(CartCleared $event): void
0 ignored issues
show
The parameter $event 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...
192
    {
193
        $this->cartItems->clear();
194
    }
195
}
196