Passed
Push — trunk ( e12360...bd02e6 )
by Christian
17:36 queued 05:07
created

CustomerLoggedInRule::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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 CustomerLoggedInRule extends Rule
15
{
16
    public const RULE_NAME = 'customerLoggedIn';
17
18
    protected bool $isLoggedIn;
19
20
    /**
21
     * @internal
22
     */
23
    public function __construct(bool $isLoggedIn = false)
24
    {
25
        parent::__construct();
26
        $this->isLoggedIn = $isLoggedIn;
27
    }
28
29
    public function match(RuleScope $scope): bool
30
    {
31
        if (!$scope instanceof CheckoutRuleScope) {
32
            return false;
33
        }
34
35
        $customer = $scope->getSalesChannelContext()->getCustomer();
36
37
        $loggedIn = $customer !== null;
38
39
        return $this->isLoggedIn === $loggedIn;
40
    }
41
42
    public function getConstraints(): array
43
    {
44
        return [
45
            'isLoggedIn' => RuleConstraints::bool(true),
46
        ];
47
    }
48
49
    public function getConfig(): RuleConfig
50
    {
51
        return (new RuleConfig())
52
            ->booleanField('isLoggedIn');
53
    }
54
}
55