AdjustmentProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A provide() 0 14 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Sylius\Provider;
14
15
use Sylius\Component\Core\Model\AdjustmentInterface;
16
use Sylius\Component\Core\Model\ShippingMethodInterface;
17
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface;
18
use Sylius\Component\Order\Model\AdjustmentInterface as BaseAdjustmentInterface;
19
20
final class AdjustmentProvider implements AdjustmentProviderInterface
21
{
22
    /** @var AdjustmentFactoryInterface $adjustmentFactory */
23
    private $adjustmentFactory;
24
25
    /** @var ChannelProviderInterface */
26
    private $channelProvider;
27
28
    public function __construct(AdjustmentFactoryInterface $adjustmentFactory, ChannelProviderInterface $channelProvider)
29
    {
30
        $this->adjustmentFactory = $adjustmentFactory;
31
        $this->channelProvider = $channelProvider;
32
    }
33
34
    public function provide(ShippingMethodInterface $shippingMethod): BaseAdjustmentInterface
35
    {
36
        /** @var BaseAdjustmentInterface $adjustment */
37
        $adjustment = $this->adjustmentFactory->createNew();
38
        $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT);
39
        $adjustment->setLabel($shippingMethod->getName());
40
41
        $channelCode = $this->channelProvider->provide()->getCode();
42
        $configuration = $shippingMethod->getConfiguration();
43
44
        $adjustment->setAmount((int) $configuration[$channelCode]['amount']);
45
46
        return $adjustment;
47
    }
48
}
49