Lastname   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 4
1
<?php
2
3
namespace Hryvinskyi\QuoteAddressValidator\Model\Validation;
4
5
use Hryvinskyi\QuoteAddressValidator\Model\ConfigInterface;
6
use Hryvinskyi\QuoteAddressValidator\Model\ValidationInterface;
7
use Magento\Framework\Exception\LocalizedException;
8
use Magento\Quote\Api\Data\AddressInterface;
9
10
class Lastname extends AbstractValidator
11
{
12
    /**
13
     * @inheritDoc
14
     */
15
    public function execute(AddressInterface $address): bool
16
    {
17
        if (!$this->getConfig()->isEnabledLastname()) {
18
            return true;
19
        }
20
21
        $value = (string)$address->getLastname();
22
23
        if ($value === '' || $this->validate($value, $this->getConfig()->getLastnameRegex(), $this->getConfig()->getLastnameStopwords())) {
24
            return true;
25
        }
26
27
        throw new LocalizedException(__($this->getConfig()->getLastnameErrorMessage(), $address->getLastname()));
28
    }
29
}
30