Lastname::execute()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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