Completed
Push — master ( fcfa74...4ea0bb )
by Paweł
20s
created

getConfigurationFormType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\CoreBundle\Form\Type\Promotion\Rule\CustomerGroupConfigurationType;
15
use Sylius\Component\Core\Model\CustomerInterface;
16
use Sylius\Component\Core\Model\OrderInterface;
17
use Sylius\Component\Promotion\Checker\Rule\RuleCheckerInterface;
18
use Sylius\Component\Promotion\Exception\UnsupportedTypeException;
19
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
20
21
/**
22
 * @author Michał Marcinkowski <[email protected]>
23
 */
24
class CustomerGroupRuleChecker implements RuleCheckerInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function isEligible(PromotionSubjectInterface $subject, array $configuration)
30
    {
31
        if (!$subject instanceof OrderInterface) {
32
            throw new UnsupportedTypeException($subject, OrderInterface::class);
33
        }
34
35
        if (null === $customer = $subject->getCustomer()) {
36
            return false;
37
        }
38
39
        if (!$customer instanceof CustomerInterface) {
40
            return false;
41
        }
42
43
        if (null === $customer->getGroup()) {
44
            return false;
45
        }
46
47
        return $configuration['group_code'] === $customer->getGroup()->getCode();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getConfigurationFormType()
54
    {
55
        return CustomerGroupConfigurationType::class;
56
    }
57
}
58