Issues (244)

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/Sylius/Behat/Page/Shop/Cart/SummaryPage.php (1 issue)

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
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Page\Shop\Cart;
15
16
use Behat\Mink\Exception\ElementNotFoundException;
17
use Sylius\Behat\Page\SymfonyPage;
18
use Sylius\Component\Core\Model\ProductInterface;
19
20
class SummaryPage extends SymfonyPage implements SummaryPageInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getRouteName()
26
    {
27
        return 'sylius_shop_cart_summary';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getGrandTotal()
34
    {
35
        $totalElement = $this->getElement('grand_total');
36
37
        return $totalElement->getText();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getBaseGrandTotal()
44
    {
45
        $totalElement = $this->getElement('base_grand_total');
46
47
        return $totalElement->getText();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getTaxTotal()
54
    {
55
        $taxTotalElement = $this->getElement('tax_total');
56
57
        return $taxTotalElement->getText();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getShippingTotal()
64
    {
65
        $shippingTotalElement = $this->getElement('shipping_total');
66
67
        return $shippingTotalElement->getText();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getPromotionTotal()
74
    {
75
        $shippingTotalElement = $this->getElement('promotion_total');
76
77
        return $shippingTotalElement->getText();
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getItemTotal($productName)
84
    {
85
        $itemTotalElement = $this->getElement('product_total', ['%name%' => $productName]);
86
87
        return  $itemTotalElement->getText();
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getItemUnitRegularPrice($productName)
94
    {
95
        $regularUnitPrice = $this->getElement('product_unit_regular_price', ['%name%' => $productName]);
96
97
        return $this->getPriceFromString(trim($regularUnitPrice->getText()));
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function getItemUnitPrice($productName)
104
    {
105
        $unitPrice = $this->getElement('product_unit_price', ['%name%' => $productName]);
106
107
        return $this->getPriceFromString(trim($unitPrice->getText()));
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function isItemDiscounted($productName)
114
    {
115
        return $this->hasElement('product_unit_regular_price', ['%name%' => $productName]);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function removeProduct($productName)
122
    {
123
        $itemElement = $this->getElement('product_row', ['%name%' => $productName]);
124
        $itemElement->find('css', 'button.sylius-cart-remove-button')->press();
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function applyCoupon($couponCode)
131
    {
132
        $this->getElement('coupon_field')->setValue($couponCode);
133
        $this->getElement('apply_coupon_button')->press();
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function changeQuantity($productName, $quantity)
140
    {
141
        $itemElement = $this->getElement('product_row', ['%name%' => $productName]);
142
        $itemElement->find('css', 'input[type=number]')->setValue($quantity);
143
144
        $this->getElement('save_button')->click();
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    public function isSingleItemOnPage()
151
    {
152
        $items = $this->getElement('cart_items')->findAll('css', 'tbody > tr');
153
154
        return 1 === count($items);
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function hasItemNamed($name)
161
    {
162
        return $this->hasItemWith($name, '.sylius-product-name');
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168
    public function hasItemWithVariantNamed($variantName)
169
    {
170
        return $this->hasItemWith($variantName, '.sylius-product-variant-name');
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function hasItemWithOptionValue($productName, $optionName, $optionValue)
177
    {
178
        $itemElement = $this->getElement('product_row', ['%name%' => $productName]);
179
180
        $selector = sprintf('.sylius-product-options > .item[data-sylius-option-name="%s"]', $optionName);
181
        $optionValueElement = $itemElement->find('css', $selector);
182
183
        if (null === $optionValueElement) {
184
            throw new ElementNotFoundException($this->getSession(), sprintf('ProductOption value of "%s"', $optionName), 'css', $selector);
185
        }
186
187
        return $optionValue === $optionValueElement->getText();
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $optionValue === ...alueElement->getText(); (boolean) is incompatible with the return type declared by the interface Sylius\Behat\Page\Shop\C...:hasItemWithOptionValue of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193
    public function hasItemWithCode($code)
194
    {
195
        return $this->hasItemWith($code, '.sylius-product-variant-code');
196
    }
197
198
    /**
199
     * {@inheritdoc}
200
     */
201
    public function hasProductOutOfStockValidationMessage(ProductInterface $product)
202
    {
203
        $message = sprintf('%s does not have sufficient stock.', $product->getName());
204
205
        try {
206
            return $this->getElement('validation_errors')->getText() === $message;
207
        } catch (ElementNotFoundException $exception) {
208
            return false;
209
        }
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215
    public function isEmpty()
216
    {
217
        return false !== strpos($this->getDocument()->find('css', '.message')->getText(), 'Your cart is empty');
218
    }
219
220
    /**
221
     * {@inheritdoc}
222
     */
223
    public function getQuantity($productName)
224
    {
225
        $itemElement = $this->getElement('product_row', ['%name%' => $productName]);
226
227
        return (int) $itemElement->find('css', 'input[type=number]')->getValue();
228
    }
229
230
    /**
231
     * {@inheritdoc}
232
     */
233
    public function getCartTotal()
234
    {
235
        $cartTotalText = $this->getElement('cart_total')->getText();
236
237
        if (strpos($cartTotalText, ',') !== false) {
238
            return strstr($cartTotalText, ',', true);
239
        }
240
241
        return trim($cartTotalText);
242
    }
243
244
    public function clearCart()
245
    {
246
        $this->getElement('clear_button')->click();
247
    }
248
249
    public function updateCart()
250
    {
251
        $this->getElement('update_button')->click();
252
    }
253
254
    /**
255
     * {@inheritdoc}
256
     */
257
    public function waitForRedirect($timeout)
258
    {
259
        $this->getDocument()->waitFor($timeout, function () {
260
            return $this->isOpen();
261
        });
262
    }
263
264
    /**
265
     * {@inheritdoc}
266
     */
267
    public function getPromotionCouponValidationMessage()
268
    {
269
        return $this->getElement('promotion_coupon_validation_message')->getText();
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    protected function getDefinedElements()
276
    {
277
        return array_merge(parent::getDefinedElements(), [
278
            'apply_coupon_button' => 'button:contains("Apply coupon")',
279
            'cart_items' => '#sylius-cart-items',
280
            'cart_total' => '#sylius-cart-total',
281
            'clear_button' => '#sylius-cart-clear',
282
            'coupon_field' => '#sylius_cart_promotionCoupon',
283
            'grand_total' => '#sylius-cart-grand-total',
284
            'base_grand_total' => '#sylius-cart-base-grand-total',
285
            'product_discounted_total' => '#sylius-cart-items tr:contains("%name%") .sylius-discounted-total',
286
            'product_row' => '#sylius-cart-items tbody tr:contains("%name%")',
287
            'product_total' => '#sylius-cart-items tr:contains("%name%") .sylius-total',
288
            'product_unit_price' => '#sylius-cart-items tr:contains("%name%") .sylius-unit-price',
289
            'product_unit_regular_price' => '#sylius-cart-items tr:contains("%name%") .sylius-regular-unit-price',
290
            'promotion_coupon_validation_message' => '#sylius-coupon .sylius-validation-error',
291
            'promotion_total' => '#sylius-cart-promotion-total',
292
            'save_button' => '#sylius-save',
293
            'shipping_total' => '#sylius-cart-shipping-total',
294
            'tax_total' => '#sylius-cart-tax-total',
295
            'update_button' => '#sylius-cart-update',
296
            'validation_errors' => '.sylius-validation-error',
297
        ]);
298
    }
299
300
    /**
301
     * @param string $attributeName
302
     * @param string|array $selector
303
     *
304
     * @return bool
305
     *
306
     * @throws ElementNotFoundException
307
     */
308
    private function hasItemWith($attributeName, $selector)
309
    {
310
        $itemsAttributes = $this->getElement('cart_items')->findAll('css', $selector);
311
312
        foreach ($itemsAttributes as $itemAttribute) {
313
            if ($attributeName === $itemAttribute->getText()) {
314
                return true;
315
            }
316
        }
317
318
        return false;
319
    }
320
321
    private function getPriceFromString(string $price): int
322
    {
323
        return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2);
324
    }
325
}
326