Completed
Push — 1.7 ( 1627e8...895c05 )
by Kamil
73:45 queued 48:32
created

OrderItemsSubtotalExtension::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
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\Bundle\ShopBundle\Twig;
15
16
use Sylius\Bundle\ShopBundle\Calculator\OrderItemsSubtotalCalculator;
17
use Sylius\Bundle\ShopBundle\Calculator\OrderItemsSubtotalCalculatorInterface;
18
use Sylius\Component\Core\Model\OrderInterface;
19
use Twig\Extension\AbstractExtension;
20
use Twig\TwigFunction;
21
22
class OrderItemsSubtotalExtension extends AbstractExtension
23
{
24
    /** @var OrderItemsSubtotalCalculatorInterface */
25
    private $calculator;
26
27
    public function __construct(?OrderItemsSubtotalCalculatorInterface $calculator = null)
28
    {
29
        if (null === $calculator) {
30
            $calculator = new OrderItemsSubtotalCalculator();
31
32
            @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
33
                'Not passing a calculator is deprecated since 1.6. Argument will no longer be optional from 2.0.',
34
                \E_USER_DEPRECATED
35
            );
36
        }
37
38
        $this->calculator = $calculator;
39
    }
40
41
    public function getFunctions(): array
42
    {
43
        return [
44
            new TwigFunction('sylius_order_items_subtotal', [$this, 'getSubtotal']),
45
        ];
46
    }
47
48
    public function getSubtotal(OrderInterface $order): int
49
    {
50
        return $this->calculator->getSubtotal($order);
51
    }
52
}
53