Completed
Branch master (734dbe)
by G
12:13
created

DepositHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrice() 0 8 2
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gweb\SyliusProductDepositPlugin\Templating\Helper;
6
7
use Gweb\SyliusProductDepositPlugin\Entity\ProductVariantInterface;
8
use Symfony\Component\Templating\Helper\Helper;
9
use Webmozart\Assert\Assert;
10
11
/**
12
 * Template helper to get deposit fee
13
 *
14
 * @author Gerd Weitenberg <[email protected]>
15
 */
16
class DepositHelper extends Helper
17
{
18
    /**
19
     * Get deposit fee by given product variant and context
20
     * @param ProductVariantInterface $productVariant
21
     * @param array $context
22
     * @return int|null
23
     */
24
    public function getPrice(ProductVariantInterface $productVariant, array $context): ?int
25
    {
26
        Assert::keyExists($context, 'channel');
27
28
        if ($productVariant->hasChannelDepositForChannel($context['channel'])) {
29
            return $productVariant->getChannelDepositForChannel($context['channel'])->getPrice();
30
        }
31
        return null;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getName(): string
38
    {
39
        return 'gweb_calculate_deposit';
40
    }
41
}
42