Passed
Push — trunk ( 10200d...995d50 )
by Christian
11:59 queued 12s
created

IsActiveRule   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getConfig() 0 4 1
A match() 0 12 3
A __construct() 0 4 1
A getConstraints() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Customer\Rule;
4
5
use Shopware\Core\Checkout\CheckoutRuleScope;
6
use Shopware\Core\Framework\Rule\Rule;
7
use Shopware\Core\Framework\Rule\RuleConfig;
8
use Shopware\Core\Framework\Rule\RuleConstraints;
9
use Shopware\Core\Framework\Rule\RuleScope;
10
11
/**
12
 * @package business-ops
13
 */
14
class IsActiveRule extends Rule
15
{
16
    protected bool $isActive;
17
18
    /**
19
     * @internal
20
     */
21
    public function __construct(bool $isActive = false)
22
    {
23
        parent::__construct();
24
        $this->isActive = $isActive;
25
    }
26
27
    public function match(RuleScope $scope): bool
28
    {
29
        if (!$scope instanceof CheckoutRuleScope) {
30
            return false;
31
        }
32
33
        $customer = $scope->getSalesChannelContext()->getCustomer();
34
        if (!$customer) {
35
            return false;
36
        }
37
38
        return $this->isActive === $customer->getActive();
39
    }
40
41
    public function getName(): string
42
    {
43
        return 'customerIsActive';
44
    }
45
46
    public function getConfig(): RuleConfig
47
    {
48
        return (new RuleConfig())
49
            ->booleanField('isActive');
50
    }
51
52
    public function getConstraints(): array
53
    {
54
        return [
55
            'isActive' => RuleConstraints::bool(true),
56
        ];
57
    }
58
}
59