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

IsActiveRule::getConstraints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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