Completed
Push — master ( 26132b...c9e982 )
by Kamil
31:04 queued 12:47
created

ItemTotalRuleChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isEligible() 0 11 2
A getConfigurationFormType() 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\Component\Core\Promotion\Checker\Rule;
13
14
use Sylius\Bundle\PromotionBundle\Form\Type\Rule\ItemTotalConfigurationType;
15
use Sylius\Component\Core\Model\OrderInterface;
16
use Sylius\Component\Promotion\Checker\Rule\RuleCheckerInterface;
17
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
18
use Webmozart\Assert\Assert;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
final class ItemTotalRuleChecker implements RuleCheckerInterface, ChannelBasedRuleCheckerInterface
24
{
25
    /**
26
     * @var RuleCheckerInterface
27
     */
28
    private $itemTotalRuleChecker;
29
30
    /**
31
     * @param RuleCheckerInterface $itemTotalRuleChecker
32
     */
33
    public function __construct(RuleCheckerInterface $itemTotalRuleChecker)
34
    {
35
        $this->itemTotalRuleChecker = $itemTotalRuleChecker;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function isEligible(PromotionSubjectInterface $subject, array $configuration)
42
    {
43
        Assert::isInstanceOf($subject, OrderInterface::class);
44
45
        $channelCode = $subject->getChannel()->getCode();
46
        if (!isset($configuration[$channelCode])) {
47
            return false;
48
        }
49
50
        return $this->itemTotalRuleChecker->isEligible($subject, $configuration[$channelCode]);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getConfigurationFormType()
57
    {
58
        return ItemTotalConfigurationType::class;
59
    }
60
}
61