| Total Complexity | 5 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 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 |
||
| 53 | } |
||
| 54 | } |
||
| 55 |