Completed
Push — master ( da9ca3...5ae406 )
by Kamil
61:14 queued 52:32
created

OrderAdjustmentsClearer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
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\Component\Core\OrderProcessing;
15
16
use Sylius\Component\Core\Model\AdjustmentInterface;
17
use Sylius\Component\Order\Model\OrderInterface;
18
use Sylius\Component\Order\Processor\OrderProcessorInterface;
19
20
final class OrderAdjustmentsClearer implements OrderProcessorInterface
21
{
22
    /**
23
     * @var array
24
     */
25
    private $adjustmentsToRemove;
26
27
    public function __construct(array $adjustmentsToRemove = [])
28
    {
29
        if (0 === func_num_args()) {
30
            @trigger_error(
31
                'Not passing adjustments types explicitly is deprecated since 1.2 and will be prohibited in 2.0',
32
                E_USER_DEPRECATED
33
            );
34
35
            $adjustmentsToRemove = [
36
                AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT,
37
                AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT,
38
                AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT,
39
                AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT,
40
                AdjustmentInterface::TAX_ADJUSTMENT,
41
            ];
42
        }
43
44
        $this->adjustmentsToRemove = $adjustmentsToRemove;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function process(OrderInterface $order): void
51
    {
52
        foreach ($this->adjustmentsToRemove as $type) {
53
            $order->removeAdjustmentsRecursively($type);
54
        }
55
    }
56
}
57