Completed
Push — master ( cfaf77...b5ed7c )
by Kamil
47:11 queued 29:42
created

ChannelBasedPriceHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getPriceForCurrentChannel() 0 10 1
A getName() 0 4 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\Bundle\CoreBundle\Templating\Helper;
13
14
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
15
use Sylius\Component\Core\Model\OrderInterface;
16
use Sylius\Component\Core\Model\ProductVariantInterface;
17
use Sylius\Component\Order\Context\CartContextInterface;
18
use Symfony\Component\Templating\Helper\Helper;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
class ChannelBasedPriceHelper extends Helper implements ChannelBasedPriceHelperInterface
24
{
25
    /**
26
     * @var CartContextInterface
27
     */
28
    private $cartContext;
29
30
    /**
31
     * @var ProductVariantPriceCalculatorInterface
32
     */
33
    private $productVariantPriceCalculator;
34
35
    /**
36
     * @param CartContextInterface $cartContext
37
     * @param ProductVariantPriceCalculatorInterface $productVariantPriceCalculator
38
     */
39
    public function __construct(
40
        CartContextInterface $cartContext,
41
        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...
42
    ) {
43
        $this->cartContext = $cartContext;
44
        $this->productVariantPriceCalculator = $productVariantPriceCalculator;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getPriceForCurrentChannel(ProductVariantInterface $productVariant)
51
    {
52
        /** @var OrderInterface $currentCart */
53
        $currentCart = $this->cartContext->getCart();
54
55
        return $this
56
            ->productVariantPriceCalculator
57
            ->calculate($productVariant, ['channel' => $currentCart->getChannel()])
58
        ;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getName()
65
    {
66
        return 'sylius_channel_variant_price';
67
    }
68
}
69