Street   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 16 7
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 Street extends AbstractValidator
11
{
12
    /**
13
     * @inheritDoc
14
     */
15
    public function execute(AddressInterface $address): bool
16
    {
17
        if (!$this->getConfig()->isEnabledStreet() || empty($address->getStreet()) || !is_array($address->getStreet())) {
18
            return true;
19
        }
20
21
        $pattern = $this->getConfig()->getStreetRegex();
22
23
        foreach ($address->getStreet() as $value) {
24
            $value = (string)$value;
25
            if ($value !== '' && $this->validate($value, $pattern, $this->getConfig()->getStreetStopwords()) === false) {
26
                throw new LocalizedException(__($this->getConfig()->getStreetErrorMessage(), $value));
27
            }
28
        }
29
30
        return true;
31
    }
32
}
33