Completed
Push — symfony3-wololo-packages ( fecf70...6bf04d )
by Kamil
28:46 queued 11:35
created

OrderPricesRecalculator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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
namespace Sylius\Component\Core\OrderProcessing;
13
14
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
15
use Sylius\Component\Core\Model\OrderInterface;
16
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
17
use Sylius\Component\Order\Processor\OrderProcessorInterface;
18
use Webmozart\Assert\Assert;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
final class OrderPricesRecalculator implements OrderProcessorInterface
24
{
25
    /**
26
     * @var ProductVariantPriceCalculatorInterface
27
     */
28
    private $productVariantPriceCalculator;
29
30
    /**
31
     * @param ProductVariantPriceCalculatorInterface $productVariantPriceCalculator
32
     */
33
    public function __construct(ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $productVariantPriceCalculator exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
34
    {
35
        $this->productVariantPriceCalculator = $productVariantPriceCalculator;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function process(BaseOrderInterface $order)
42
    {
43
        /** @var OrderInterface $order */
44
        Assert::isInstanceOf($order, OrderInterface::class);
45
        $channel = $order->getChannel();
46
47
        foreach ($order->getItems() as $item) {
48
            if ($item->isImmutable()) {
49
                continue;
50
            }
51
52
            $item->setUnitPrice($this->productVariantPriceCalculator->calculate(
53
                $item->getVariant(),
54
                ['channel' => $channel]
55
            ));
56
        }
57
    }
58
}
59