Completed
Push — checkout-consistent-prices ( af49ca )
by Kamil
13:24
created

OrderItemsSubtotalExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 6 1
A getSubtotal() 0 10 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\Component\Core\Model\OrderInterface;
17
use Sylius\Component\Core\Model\OrderItemInterface;
18
19
class OrderItemsSubtotalExtension extends \Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
{
21
    public function getFunctions(): array
22
    {
23
        return [
24
            new \Twig_Function('sylius_order_items_subtotal', [$this, 'getSubtotal']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Function has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
25
        ];
26
    }
27
28
    public function getSubtotal(OrderInterface $order): int
29
    {
30
        return array_reduce(
31
            $order->getItems()->toArray(),
32
            static function (int $subtotal, OrderItemInterface $item) {
33
                return $subtotal + $item->getSubtotal();
34
            },
35
            0
36
        );
37
    }
38
}
39