CompositeOrderItemProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A provide() 0 8 2
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\OrderItem;
14
15
use BitBag\SyliusVueStorefrontPlugin\Command\Cart\UpdateCart;
16
use BitBag\SyliusVueStorefrontPlugin\Sylius\Entity\Order\OrderItemInterface;
17
18
final class CompositeOrderItemProvider implements OrderItemProviderInterface
19
{
20
    /** @var OrderItemProviderInterface */
21
    private $existingOrderItemProvider;
22
23
    /** @var OrderItemProviderInterface */
24
    private $newOrderItemProvider;
25
26
    public function __construct(
27
        OrderItemProviderInterface $existingOrderItemProvider,
28
        OrderItemProviderInterface $newOrderItemProvider
29
    ) {
30
        $this->existingOrderItemProvider = $existingOrderItemProvider;
31
        $this->newOrderItemProvider = $newOrderItemProvider;
32
    }
33
34
    public function provide(UpdateCart $updateCart): OrderItemInterface
35
    {
36
        if ($updateCart->cartItem()->getItemId()) {
37
            return $this->existingOrderItemProvider->provide($updateCart);
38
        }
39
40
        return $this->newOrderItemProvider->provide($updateCart);
41
    }
42
}
43