Firstname   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
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 19
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 Firstname extends AbstractValidator
11
{
12
13
    /**
14
     * @inheritDoc
15
     */
16
    public function execute(AddressInterface $address): bool
17
    {
18
        if (!$this->getConfig()->isEnabledFirstname()) {
19
            return true;
20
        }
21
22
        $value = (string)$address->getFirstname();
23
24
        if ($value === '' || $this->validate($value, $this->getConfig()->getFirstnameRegex(), $this->getConfig()->getFirstnameStopwords())) {
25
            return true;
26
        }
27
28
        throw new LocalizedException(__($this->getConfig()->getFirstnameErrorMessage(), $address->getFirstname()));
29
    }
30
}
31