Config::getLastnameStopwords()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Hryvinskyi\QuoteAddressValidator\Model;
4
5
use Magento\Framework\App\Config\ScopeConfigInterface;
6
use Magento\Store\Model\ScopeInterface;
7
8
class Config implements ConfigInterface
9
{
10
    public const XML_CONF_ENABLED = 'quote_address_validator/general/enabled';
11
    public const XML_CONF_ENABLED_FIRSTNAME = 'quote_address_validator/general/enabled_firstname';
12
    public const XML_CONF_ENABLED_LASTNAME = 'quote_address_validator/general/enabled_lastname';
13
    public const XML_CONF_ENABLED_STREET = 'quote_address_validator/general/enabled_street';
14
15
    public const XML_CONF_VALIDATION_TYPE = 'quote_address_validator/general/validation_type';
16
17
    public const XML_CONF_FIRSTNAME_STOPWORDS = 'quote_address_validator/general/firstname_stopwords';
18
    public const XML_CONF_LASTNAME_STOPWORDS = 'quote_address_validator/general/lastname_stopwords';
19
    public const XML_CONF_STREET_STOPWORDS = 'quote_address_validator/general/street_stopwords';
20
21
    public const XML_CONF_FIRSTNAME_REGEX = 'quote_address_validator/general/firstname_regex';
22
    public const XML_CONF_LASTNAME_REGEX = 'quote_address_validator/general/lastname_regex';
23
    public const XML_CONF_STREET_REGEX = 'quote_address_validator/general/street_regex';
24
25
    public const XML_CONF_FIRSTNAME_ERROR_MESSAGE = 'quote_address_validator/general/firstname_error_message';
26
    public const XML_CONF_LASTNAME_ERROR_MESSAGE = 'quote_address_validator/general/lastname_error_message';
27
    public const XML_CONF_STREET_ERROR_MESSAGE = 'quote_address_validator/general/street_error_message';
28
29
    /**
30
     * @var ScopeConfigInterface
31
     */
32
    private $scopeConfig;
33
34
    public function __construct(ScopeConfigInterface $scopeConfig)
35
    {
36
        $this->scopeConfig = $scopeConfig;
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function isEnabled($store = null, string $scope = ScopeInterface::SCOPE_STORE): bool
43
    {
44
        return $this->scopeConfig->isSetFlag(self::XML_CONF_ENABLED, $scope, $store);
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function getValidationType($store = null, string $scope = ScopeInterface::SCOPE_STORE): int
51
    {
52
        return (int)$this->scopeConfig->getValue(self::XML_CONF_VALIDATION_TYPE, $scope, $store);
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function isEnabledFirstname($store = null, string $scope = ScopeInterface::SCOPE_STORE): bool
59
    {
60
        return $this->scopeConfig->isSetFlag(self::XML_CONF_ENABLED_FIRSTNAME, $scope, $store);
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66
    public function isEnabledLastname($store = null, string $scope = ScopeInterface::SCOPE_STORE): bool
67
    {
68
        return $this->scopeConfig->isSetFlag(self::XML_CONF_ENABLED_LASTNAME, $scope, $store);
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74
    public function isEnabledStreet($store = null, string $scope = ScopeInterface::SCOPE_STORE): bool
75
    {
76
        return $this->scopeConfig->isSetFlag(self::XML_CONF_ENABLED_STREET, $scope, $store);
77
    }
78
79
    /**
80
     * @inheritDoc
81
     */
82
    public function getFirstnameStopwords($store = null, string $scope = ScopeInterface::SCOPE_STORE): array
83
    {
84
        $stopwords = $this->scopeConfig->getValue(self::XML_CONF_FIRSTNAME_STOPWORDS, $scope, $store);
85
86
        if (!$stopwords) {
87
            return [];
88
        }
89
90
        return array_values(array_unique(array_filter(array_map('trim', explode(',', $stopwords)))));
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96
    public function getLastnameStopwords($store = null, string $scope = ScopeInterface::SCOPE_STORE): array
97
    {
98
        $stopwords = $this->scopeConfig->getValue(self::XML_CONF_LASTNAME_STOPWORDS, $scope, $store);
99
100
        if (!$stopwords) {
101
            return [];
102
        }
103
104
        return array_values(array_unique(array_filter(array_map('trim', explode(',', $stopwords)))));
105
    }
106
107
    /**
108
     * @inheritDoc
109
     */
110
    public function getStreetStopwords($store = null, string $scope = ScopeInterface::SCOPE_STORE): array
111
    {
112
        $stopwords = $this->scopeConfig->getValue(self::XML_CONF_STREET_STOPWORDS, $scope, $store);
113
114
        if (!$stopwords) {
115
            return [];
116
        }
117
118
        return array_values(array_unique(array_filter(array_map('trim', explode(',', $stopwords)))));
119
    }
120
121
    /**
122
     * @inheritDoc
123
     */
124
    public function getFirstnameRegex($store = null, string $scope = ScopeInterface::SCOPE_STORE): string
125
    {
126
        return (string)$this->scopeConfig->getValue(self::XML_CONF_FIRSTNAME_REGEX, $scope, $store);
127
    }
128
129
    /**
130
     * @inheritDoc
131
     */
132
    public function getLastnameRegex($store = null, string $scope = ScopeInterface::SCOPE_STORE): string
133
    {
134
        return (string)$this->scopeConfig->getValue(self::XML_CONF_LASTNAME_REGEX, $scope, $store);
135
    }
136
137
    /**
138
     * @inheritDoc
139
     */
140
    public function getStreetRegex($store = null, string $scope = ScopeInterface::SCOPE_STORE): string
141
    {
142
        return (string)$this->scopeConfig->getValue(self::XML_CONF_STREET_REGEX, $scope, $store);
143
    }
144
145
    /**
146
     * @inheritDoc
147
     */
148
    public function getFirstnameErrorMessage($store = null, string $scope = ScopeInterface::SCOPE_STORE): string
149
    {
150
        return (string)$this->scopeConfig->getValue(self::XML_CONF_FIRSTNAME_ERROR_MESSAGE, $scope, $store);
151
    }
152
153
    /**
154
     * @inheritDoc
155
     */
156
    public function getLastnameErrorMessage($store = null, string $scope = ScopeInterface::SCOPE_STORE): string
157
    {
158
        return (string)$this->scopeConfig->getValue(self::XML_CONF_LASTNAME_ERROR_MESSAGE, $scope, $store);
159
    }
160
161
    /**
162
     * @inheritDoc
163
     */
164
    public function getStreetErrorMessage($store = null, string $scope = ScopeInterface::SCOPE_STORE): string
165
    {
166
        return (string)$this->scopeConfig->getValue(self::XML_CONF_STREET_ERROR_MESSAGE, $scope, $store);
167
    }
168
}
169