Passed
Push — trunk ( b03e0c...bc72f3 )
by Christian
13:43 queued 13s
created

CartFacadeHelper::validatePrice()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 6
nop 1
dl 0
loc 23
rs 9.2222
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Cart\Facade;
4
5
use Shopware\Core\Checkout\Cart\Cart;
6
use Shopware\Core\Checkout\Cart\CartBehavior;
7
use Shopware\Core\Checkout\Cart\LineItem\LineItem;
8
use Shopware\Core\Checkout\Cart\LineItemFactoryRegistry;
9
use Shopware\Core\Checkout\Cart\Processor;
10
use Shopware\Core\Framework\Log\Package;
11
use Shopware\Core\System\SalesChannel\SalesChannelContext;
12
13
/**
14
 * @internal
15
 */
16
#[Package('checkout')]
17
class CartFacadeHelper
18
{
19
    /**
20
     * @internal
21
     */
22
    public function __construct(
23
        private readonly LineItemFactoryRegistry $factory,
24
        private readonly Processor $processor
25
    ) {
26
    }
27
28
    public function product(string $productId, int $quantity, SalesChannelContext $context): LineItem
29
    {
30
        $data = [
31
            'type' => LineItem::PRODUCT_LINE_ITEM_TYPE,
32
            'id' => $productId,
33
            'referencedId' => $productId,
34
            'quantity' => $quantity,
35
        ];
36
37
        return $this->factory->create($data, $context);
38
    }
39
40
    public function calculate(Cart $cart, CartBehavior $behavior, SalesChannelContext $context): Cart
41
    {
42
        return $this->processor->process($cart, $context, $behavior);
43
    }
44
}
45