Passed
Pull Request — master (#24)
by
unknown
27:37 queued 22:33
created

Simulator::getPublicKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pagantis\Pagantis\Block\Product;
4
5
use Magento\Backend\Block\Template\Context;
6
use Magento\Catalog\Model\Category;
7
use Magento\Catalog\Model\Product;
8
use Magento\Framework\Registry;
9
use Magento\Framework\View\Element\Template;
10
use Pagantis\Pagantis\Helper\ExtraConfig;
11
use Magento\Framework\Locale\Resolver;
12
use Zend\Db\Sql\Ddl\Column\Boolean;
13
14
/**
15
 * Class Simulator
16
 * @package Pagantis\Pagantis\Block\Product
17
 */
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 Product
44
     */
45
    protected $product;
46
47
    /**
48
     * @var float
49
     */
50
    protected $minAmount;
51
52
    /**
53
     * @var int
54
     */
55
    protected $minInstallments;
56
57
    /**
58
     * @var string
59
     */
60
    protected $priceSelector;
61
62
    /**
63
     * @var string
64
     */
65
    protected $quantitySelector;
66
67
    /**
68
     * @var String
69
     */
70
    protected $positionSelector;
71
72
    /**
73
     * @var Registry
74
     */
75
    protected $registry;
76
77
    /**
78
     * @var Config
0 ignored issues
show
Bug introduced by
The type Pagantis\Pagantis\Block\Product\Config was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
79
     */
80
    protected $extraConfig;
81
82
    /**
83
     * @var String
84
     */
85
    protected $simulatorType;
86
87
    /**
88
     * @var String
89
     */
90
    protected $store;
91
92
    /**
93
     * @var Boolean
94
     */
95
    protected $promoted;
96
97
    /**
98
     * @var String
99
     */
100
    protected $promotedMessage;
101
102
    /**
103
     * @var String
104
     */
105
    protected $thousandSeparator;
106
107
    /**
108
     * @var String
109
     */
110
    protected $decimalSeparator;
111
112
    /**
113
     * Simulator constructor.
114
     *
115
     * @param Context        $context
116
     * @param Registry       $registry
117
     * @param ExtraConfig    $extraConfig
118
     * @param Resolver $store
119
     * @param array          $data
120
     */
121
    public function __construct(
122
        Context $context,
123
        Registry $registry,
124
        ExtraConfig $extraConfig,
125
        Resolver $store,
126
        array $data = []
127
    ) {
128
        parent::__construct($context, $data);
129
        $this->registry = $registry;
130
        $this->store = $store;
0 ignored issues
show
Documentation Bug introduced by
It seems like $store of type Magento\Framework\Locale\Resolver is incompatible with the declared type string of property $store.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
131
        /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */
132
        $scopeConfig = $this->_scopeConfig;
133
        $config = $scopeConfig->getValue('payment/pagantis');
134
135
        $this->enabled = $config['active'];
136
        $this->publicKey = isset($config['pagantis_public_key']) ? $config['pagantis_public_key'] : '';
137
        $this->productSimulator = $config['product_simulator'];
138
        $this->extraConfig = $extraConfig->getExtraConfig();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extraConfig->getExtraConfig() of type array or array is incompatible with the declared type Pagantis\Pagantis\Block\Product\Config of property $extraConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
139
140
        $this->minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'];
141
        $this->minInstallments = $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'];
142
        $this->priceSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'];
143
        $this->quantitySelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'];
144
        $this->positionSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'];
145
        $this->simulatorType = $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'];
146
        $this->promotedMessage = $this->extraConfig['PAGANTIS_PROMOTION_EXTRA'];
147
        $this->thousandSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'];
148
        $this->decimalSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'];
149
150
        $this->promoted = $this->isProductInPromotion();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->isProductInPromotion() of type boolean is incompatible with the declared type Zend\Db\Sql\Ddl\Column\Boolean of property $promoted.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getLocale()
157
    {
158
        return strstr($this->store->getLocale(), '_', true);
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    public function getCountry()
165
    {
166
        return strstr($this->store->getLocale(), '_', true);
167
    }
168
169
    /**
170
     * @param $locale
171
     *
172
     * @return bool
173
     */
174
    public function getAllowedCountry($locale)
175
    {
176
        $locale = strtolower($locale);
177
        $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
178
        return (in_array(strtolower($locale), $allowedCountries));
179
    }
180
181
    /**
182
     * @return Product
183
     */
184
    protected function getProduct()
185
    {
186
        if (is_null($this->product)) {
187
            $this->product = $this->registry->registry('product');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Registry::registry() has been deprecated: 102.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

187
            $this->product = /** @scrutinizer ignore-deprecated */ $this->registry->registry('product');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
188
        }
189
190
        return $this->product;
191
    }
192
193
    /**
194
     * @return bool
195
     */
196
    public function isEnabled()
197
    {
198
        return $this->enabled;
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    public function getPublicKey()
205
    {
206
        return $this->publicKey;
207
    }
208
209
    /**
210
     * @return string
211
     */
212
    public function getPromotionProductExtra()
213
    {
214
        return $this->promotionProductExtra;
215
    }
216
217
    /**
218
     * @return bool
219
     */
220
    public function isProductInPromotion()
221
    {
222
        try {
223
            return ($this->getProduct()->getData('pagantis_promoted') === '1') ? 'true' : 'false';
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getProduct... '1' ? 'true' : 'false' returns the type string which is incompatible with the documented return type boolean.
Loading history...
224
        } catch (\Exception $exception) {
225
            return 'false';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'false' returns the type string which is incompatible with the documented return type boolean.
Loading history...
226
        }
227
    }
228
229
    /**
230
     * @return float
231
     */
232
    public function getFinalPrice()
233
    {
234
        return $this->getProduct()->getFinalPrice();
235
    }
236
237
    /**
238
     * @return array|false|string
239
     */
240
    public function getProductSimulator()
241
    {
242
        return $this->productSimulator;
243
    }
244
245
    /**
246
     * @param int $productSimulator
247
     */
248
    public function setProductSimulator($productSimulator)
249
    {
250
        $this->productSimulator = $productSimulator;
251
    }
252
253
    /**
254
     * @return float
255
     */
256
    public function getMinAmount()
257
    {
258
        return $this->minAmount;
259
    }
260
261
    /**
262
     * @param float $minAmount
263
     */
264
    public function setMinAmount($minAmount)
265
    {
266
        $this->minAmount = $minAmount;
267
    }
268
269
    /**
270
     * @return int
271
     */
272
    public function getMinInstallments()
273
    {
274
        return $this->minInstallments;
275
    }
276
277
    /**
278
     * @param int $minInstallments
279
     */
280
    public function setMinInstallments($minInstallments)
281
    {
282
        $this->minInstallments = $minInstallments;
283
    }
284
285
    /**
286
     * @return string
287
     */
288
    public function getPriceSelector()
289
    {
290
        return $this->priceSelector;
291
    }
292
293
    /**
294
     * @param string $priceSelector
295
     */
296
    public function setPriceSelector($priceSelector)
297
    {
298
        $this->priceSelector = $priceSelector;
299
    }
300
301
    /**
302
     * @return string
303
     */
304
    public function getQuantitySelector()
305
    {
306
        return $this->quantitySelector;
307
    }
308
309
    /**
310
     * @param string $quantitySelector
311
     */
312
    public function setQuantitySelector($quantitySelector)
313
    {
314
        $this->quantitySelector = $quantitySelector;
315
    }
316
317
    /**
318
     * @return String
319
     */
320
    public function getPositionSelector()
321
    {
322
        return $this->positionSelector;
323
    }
324
325
    /**
326
     * @param String $positionSelector
327
     */
328
    public function setPositionSelector($positionSelector)
329
    {
330
        $this->positionSelector = $positionSelector;
331
    }
332
333
334
    /**
335
     * @return String
336
     */
337
    public function getSimulatorType()
338
    {
339
        return $this->simulatorType;
340
    }
341
342
    /**
343
     * @param String $simulatorType
344
     */
345
    public function setSimulatorType($simulatorType)
346
    {
347
        $this->simulatorType = $simulatorType;
348
    }
349
350
    /**
351
     * @return Boolean
352
     */
353
    public function getPromoted()
354
    {
355
        return $this->promoted;
356
    }
357
358
    /**
359
     * @param Boolean $promoted
360
     */
361
    public function setPromoted($promoted)
362
    {
363
        $this->promoted = $promoted;
364
    }
365
366
    /**
367
     * @return String
368
     */
369
    public function getPromotedMessage()
370
    {
371
        return $this->promotedMessage;
372
    }
373
374
    /**
375
     * @param String $promotedMessage
376
     */
377
    public function setPromotedMessage($promotedMessage)
378
    {
379
        $this->promotedMessage = $promotedMessage;
380
    }
381
382
    /**
383
     * @return String
384
     */
385
    public function getThousandSeparator()
386
    {
387
        return $this->thousandSeparator;
388
    }
389
390
    /**
391
     * @param String $thousandSeparator
392
     */
393
    public function setThousandSeparator($thousandSeparator)
394
    {
395
        $this->thousandSeparator = $thousandSeparator;
396
    }
397
398
    /**
399
     * @return String
400
     */
401
    public function getDecimalSeparator()
402
    {
403
        return $this->decimalSeparator;
404
    }
405
406
    /**
407
     * @param String $decimalSeparator
408
     */
409
    public function setDecimalSeparator($decimalSeparator)
410
    {
411
        $this->decimalSeparator = $decimalSeparator;
412
    }
413
}
414