Passed
Pull Request — master (#16)
by
unknown
04:17 queued 10s
created

Simulator::getPositionSelector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace DigitalOrigin\Pmt\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 DigitalOrigin\Pmt\Helper\ExtraConfig;
11
12
/**
13
 * Class Simulator
14
 * @package DigitalOrigin\Pmt\Block\Product
15
 */
16
class Simulator extends Template
17
{
18
    const PROMOTIONS_CATEGORY = 'paylater-promotion-product';
19
20
    /**
21
     * @var bool
22
     */
23
    protected $enabled;
24
25
    /**
26
     * @var string
27
     */
28
    protected $publicKey;
29
30
    /**
31
     * @var string
32
     */
33
    protected $productSimulator;
34
35
    /**
36
     * @var string
37
     */
38
    protected $promotionProductExtra;
39
40
    /**
41
     * @var Product
42
     */
43
    protected $product;
44
45
    /**
46
     * @var float
47
     */
48
    protected $minAmount;
49
50
    /**
51
     * @var int
52
     */
53
    protected $minInstallments;
54
55
    /**
56
     * @var string
57
     */
58
    protected $priceSelector;
59
60
    /**
61
     * @var string
62
     */
63
    protected $quantitySelector;
64
65
    /**
66
     * @var String
67
     */
68
    protected $positionSelector;
69
70
    /**
71
     * @var Registry
72
     */
73
    protected $registry;
74
75
    /**
76
     * @var Config
0 ignored issues
show
Bug introduced by
The type DigitalOrigin\Pmt\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...
77
     */
78
    protected $extraConfig;
79
80
    /**
81
     * @var String
82
     */
83
    protected $simulatorType;
84
85
    /**
86
     * Simulator constructor.
87
     *
88
     * @param Context  $context
89
     * @param Registry $registry
90
     * @param ExtraConfig   $extraConfig
91
     * @param array    $data
92
     */
93
    public function __construct(
94
        Context $context,
95
        Registry $registry,
96
        ExtraConfig $extraConfig,
97
        array $data = []
98
    ) {
99
        parent::__construct($context, $data);
100
        $this->registry = $registry;
101
        /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */
102
        $scopeConfig = $this->_scopeConfig;
103
        $config = $scopeConfig->getValue('payment/paylater');
104
105
        $this->enabled = $config['active'];
106
        $this->publicKey = isset($config['pmt_public_key']) ? $config['pmt_public_key'] : '';
107
        $this->productSimulator = $config['product_simulator'];
108
        $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 DigitalOrigin\Pmt\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...
109
        $this->minAmount = $this->extraConfig['PMT_DISPLAY_MIN_AMOUNT'];
110
        $this->minInstallments = $this->extraConfig['PMT_SIMULATOR_START_INSTALLMENTS'];
111
        $this->priceSelector = $this->extraConfig['PMT_SIMULATOR_CSS_PRICE_SELECTOR'];
112
        $this->quantitySelector = $this->extraConfig['PMT_SIMULATOR_CSS_QUANTITY_SELECTOR'];
113
        $this->positionSelector = $this->extraConfig['PMT_SIMULATOR_CSS_POSITION_SELECTOR'];
114
        $this->simulatorType = $this->extraConfig['PMT_SIMULATOR_DISPLAY_TYPE'];
115
    }
116
117
    /**
118
     * @return Product
119
     */
120
    protected function getProduct()
121
    {
122
        if (is_null($this->product)) {
123
            $this->product = $this->registry->registry('product');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Registry::registry() has been deprecated. ( Ignorable by Annotation )

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

123
            $this->product = /** @scrutinizer ignore-deprecated */ $this->registry->registry('product');
Loading history...
124
        }
125
126
        return $this->product;
127
    }
128
129
    /**
130
     * @return bool
131
     */
132
    public function isEnabled()
133
    {
134
        return $this->enabled;
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    public function getPublicKey()
141
    {
142
        return $this->publicKey;
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getPromotionProductExtra()
149
    {
150
        return $this->promotionProductExtra;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156
    public function isProductInPromotion()
157
    {
158
        try {
159
            /** @var Category $category */
160
            $category = $this->getProduct()->getCategoryCollection()->addFieldToFilter(
161
                'name',
162
                array('eq' => self::PROMOTIONS_CATEGORY)
163
            )->getFirstItem();
164
        } catch (\Exception $exception) {
165
            return false;
166
        }
167
168
        return $category->getName() === self::PROMOTIONS_CATEGORY ? 1 : 0;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $category->getNam...OTIONS_CATEGORY ? 1 : 0 returns the type integer which is incompatible with the documented return type boolean.
Loading history...
169
    }
170
171
    /**
172
     * @return float
173
     */
174
    public function getFinalPrice()
175
    {
176
        return $this->getProduct()->getFinalPrice();
177
    }
178
179
    /**
180
     * @return array|false|string
181
     */
182
    public function getProductSimulator()
183
    {
184
        return $this->productSimulator;
185
    }
186
187
    /**
188
     * @param int $productSimulator
189
     */
190
    public function setProductSimulator($productSimulator)
191
    {
192
        $this->productSimulator = $productSimulator;
193
    }
194
195
    /**
196
     * @return float
197
     */
198
    public function getMinAmount()
199
    {
200
        return $this->minAmount;
201
    }
202
203
    /**
204
     * @param float $minAmount
205
     */
206
    public function setMinAmount($minAmount)
207
    {
208
        $this->minAmount = $minAmount;
209
    }
210
211
    /**
212
     * @return int
213
     */
214
    public function getMinInstallments()
215
    {
216
        return $this->minInstallments;
217
    }
218
219
    /**
220
     * @param int $minInstallments
221
     */
222
    public function setMinInstallments($minInstallments)
223
    {
224
        $this->minInstallments = $minInstallments;
225
    }
226
227
    /**
228
     * @return string
229
     */
230
    public function getPriceSelector()
231
    {
232
        return $this->priceSelector;
233
    }
234
235
    /**
236
     * @param string $priceSelector
237
     */
238
    public function setPriceSelector($priceSelector)
239
    {
240
        $this->priceSelector = $priceSelector;
241
    }
242
243
    /**
244
     * @return string
245
     */
246
    public function getQuantitySelector()
247
    {
248
        return $this->quantitySelector;
249
    }
250
251
    /**
252
     * @param string $quantitySelector
253
     */
254
    public function setQuantitySelector($quantitySelector)
255
    {
256
        $this->quantitySelector = $quantitySelector;
257
    }
258
259
    /**
260
     * @return String
261
     */
262
    public function getPositionSelector()
263
    {
264
        return $this->positionSelector;
265
    }
266
267
    /**
268
     * @param String $positionSelector
269
     */
270
    public function setPositionSelector($positionSelector)
271
    {
272
        $this->positionSelector = $positionSelector;
273
    }
274
275
276
    /**
277
     * @return String
278
     */
279
    public function getSimulatorType()
280
    {
281
        return $this->simulatorType;
282
    }
283
284
    /**
285
     * @param String $simulatorType
286
     */
287
    public function setSimulatorType($simulatorType)
288
    {
289
        $this->simulatorType = $simulatorType;
290
    }
291
}
292