Total Complexity | 41 |
Total Lines | 428 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like Simulator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Simulator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class Simulator extends Template |
||
19 | { |
||
20 | const PROMOTIONS_CATEGORY = 'pagantis-promotion-product'; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected $enabled; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $publicKey; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $productSimulator; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $promotionProductExtra; |
||
41 | |||
42 | /** |
||
43 | * @var float |
||
44 | */ |
||
45 | protected $minAmount; |
||
46 | |||
47 | /** |
||
48 | * @var float |
||
49 | */ |
||
50 | protected $maxAmount; |
||
51 | |||
52 | /** |
||
53 | * @var Product |
||
54 | */ |
||
55 | protected $product; |
||
56 | |||
57 | /** |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $minInstallments; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $priceSelector; |
||
66 | |||
67 | /** |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $quantitySelector; |
||
71 | |||
72 | /** |
||
73 | * @var String |
||
74 | */ |
||
75 | protected $positionSelector; |
||
76 | |||
77 | /** |
||
78 | * @var Registry |
||
79 | */ |
||
80 | protected $registry; |
||
81 | |||
82 | /** |
||
83 | * @var Config |
||
|
|||
84 | */ |
||
85 | protected $extraConfig; |
||
86 | |||
87 | /** |
||
88 | * @var String |
||
89 | */ |
||
90 | protected $simulatorType; |
||
91 | |||
92 | /** |
||
93 | * @var String |
||
94 | */ |
||
95 | protected $store; |
||
96 | |||
97 | /** |
||
98 | * @var Boolean |
||
99 | */ |
||
100 | protected $promoted; |
||
101 | |||
102 | /** |
||
103 | * @var String |
||
104 | */ |
||
105 | protected $promotedMessage; |
||
106 | |||
107 | /** |
||
108 | * @var String |
||
109 | */ |
||
110 | protected $thousandSeparator; |
||
111 | |||
112 | /** |
||
113 | * @var String |
||
114 | */ |
||
115 | protected $decimalSeparator; |
||
116 | |||
117 | /** |
||
118 | * Simulator constructor. |
||
119 | * |
||
120 | * @param Context $context |
||
121 | * @param Registry $registry |
||
122 | * @param ExtraConfig $extraConfig |
||
123 | * @param Resolver $store |
||
124 | * @param array $data |
||
125 | */ |
||
126 | public function __construct( |
||
127 | Context $context, |
||
128 | Registry $registry, |
||
129 | ExtraConfig $extraConfig, |
||
130 | Resolver $store, |
||
131 | array $data = [] |
||
132 | ) { |
||
133 | parent::__construct($context, $data); |
||
134 | $this->registry = $registry; |
||
135 | $this->store = $store; |
||
136 | /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */ |
||
137 | $scopeConfig = $this->_scopeConfig; |
||
138 | $config = $scopeConfig->getValue('payment/pagantis'); |
||
139 | |||
140 | $this->enabled = $config['active']; |
||
141 | $this->publicKey = isset($config['pagantis_public_key']) ? $config['pagantis_public_key'] : ''; |
||
142 | $this->productSimulator = $config['product_simulator']; |
||
143 | $this->extraConfig = $extraConfig->getExtraConfig(); |
||
144 | |||
145 | $this->minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']; |
||
146 | $this->maxAmount = $this->extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT']; |
||
147 | $this->minInstallments = $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']; |
||
148 | $this->priceSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']; |
||
149 | $this->quantitySelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']; |
||
150 | $this->positionSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']; |
||
151 | $this->simulatorType = $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE']; |
||
152 | $this->promotedMessage = $this->extraConfig['PAGANTIS_PROMOTION_EXTRA']; |
||
153 | $this->thousandSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR']; |
||
154 | $this->decimalSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR']; |
||
155 | |||
156 | $this->promoted = $this->isProductInPromotion(); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | public function getLocale() |
||
163 | { |
||
164 | return strstr($this->store->getLocale(), '_', true); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | public function getCountry() |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @param $locale |
||
177 | * |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function getAllowedCountry($locale) |
||
181 | { |
||
182 | $locale = strtolower($locale); |
||
183 | $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
||
184 | return (in_array(strtolower($locale), $allowedCountries)); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @return Product |
||
189 | */ |
||
190 | protected function getProduct() |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function isEnabled() |
||
203 | { |
||
204 | return $this->enabled; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return string |
||
209 | */ |
||
210 | public function getPublicKey() |
||
211 | { |
||
212 | return $this->publicKey; |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @return string |
||
217 | */ |
||
218 | public function getPromotionProductExtra() |
||
219 | { |
||
220 | return $this->promotionProductExtra; |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * @return bool |
||
225 | */ |
||
226 | public function isProductInPromotion() |
||
227 | { |
||
228 | try { |
||
229 | return ($this->getProduct()->getData('pagantis_promoted') === '1') ? 'true' : 'false'; |
||
230 | } catch (\Exception $exception) { |
||
231 | return 'false'; |
||
232 | } |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @return float |
||
237 | */ |
||
238 | public function getFinalPrice() |
||
239 | { |
||
240 | return $this->getProduct()->getFinalPrice(); |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @return array|false|string |
||
245 | */ |
||
246 | public function getProductSimulator() |
||
247 | { |
||
248 | return $this->productSimulator; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param int $productSimulator |
||
253 | */ |
||
254 | public function setProductSimulator($productSimulator) |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @return float |
||
261 | */ |
||
262 | public function getMinAmount() |
||
263 | { |
||
264 | return $this->minAmount; |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * @param float $minAmount |
||
269 | */ |
||
270 | public function setMinAmount($minAmount) |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @return float |
||
277 | */ |
||
278 | public function getMaxAmount() |
||
279 | { |
||
280 | return $this->maxAmount; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @param float $maxAmount |
||
285 | */ |
||
286 | public function setMaxAmount($maxAmount) |
||
287 | { |
||
288 | $this->maxAmount = $maxAmount; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @return int |
||
293 | */ |
||
294 | public function getMinInstallments() |
||
295 | { |
||
296 | return $this->minInstallments; |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * @param int $minInstallments |
||
301 | */ |
||
302 | public function setMinInstallments($minInstallments) |
||
303 | { |
||
304 | $this->minInstallments = $minInstallments; |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * @return string |
||
309 | */ |
||
310 | public function getPriceSelector() |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * @param string $priceSelector |
||
317 | */ |
||
318 | public function setPriceSelector($priceSelector) |
||
319 | { |
||
320 | $this->priceSelector = $priceSelector; |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * @return string |
||
325 | */ |
||
326 | public function getQuantitySelector() |
||
327 | { |
||
328 | return $this->quantitySelector; |
||
329 | } |
||
330 | |||
331 | /** |
||
332 | * @param string $quantitySelector |
||
333 | */ |
||
334 | public function setQuantitySelector($quantitySelector) |
||
335 | { |
||
336 | $this->quantitySelector = $quantitySelector; |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * @return String |
||
341 | */ |
||
342 | public function getPositionSelector() |
||
343 | { |
||
344 | return $this->positionSelector; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @param String $positionSelector |
||
349 | */ |
||
350 | public function setPositionSelector($positionSelector) |
||
353 | } |
||
354 | |||
355 | |||
356 | /** |
||
357 | * @return String |
||
358 | */ |
||
359 | public function getSimulatorType() |
||
360 | { |
||
361 | return $this->simulatorType; |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * @param String $simulatorType |
||
366 | */ |
||
367 | public function setSimulatorType($simulatorType) |
||
368 | { |
||
369 | $this->simulatorType = $simulatorType; |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * @return Boolean |
||
374 | */ |
||
375 | public function getPromoted() |
||
376 | { |
||
377 | return $this->promoted; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * @param Boolean $promoted |
||
382 | */ |
||
383 | public function setPromoted($promoted) |
||
384 | { |
||
385 | $this->promoted = $promoted; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * @return String |
||
390 | */ |
||
391 | public function getPromotedMessage() |
||
392 | { |
||
393 | return $this->promotedMessage; |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * @param String $promotedMessage |
||
398 | */ |
||
399 | public function setPromotedMessage($promotedMessage) |
||
400 | { |
||
401 | $this->promotedMessage = $promotedMessage; |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * @return String |
||
406 | */ |
||
407 | public function getThousandSeparator() |
||
408 | { |
||
409 | return $this->thousandSeparator; |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * @param String $thousandSeparator |
||
414 | */ |
||
415 | public function setThousandSeparator($thousandSeparator) |
||
416 | { |
||
417 | $this->thousandSeparator = $thousandSeparator; |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @return String |
||
422 | */ |
||
423 | public function getDecimalSeparator() |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * @param String $decimalSeparator |
||
430 | */ |
||
431 | public function setDecimalSeparator($decimalSeparator) |
||
432 | { |
||
433 | $this->decimalSeparator = $decimalSeparator; |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * @return bool |
||
438 | */ |
||
439 | public function checkValidAmount() |
||
446 | } |
||
447 | } |
||
448 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths