Review   A
last analyzed

Complexity

Total Complexity 36

Size/Duplication

Total Lines 355
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 93
dl 0
loc 355
rs 9.52
c 0
b 0
f 0
wmc 36

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaymentMethodTitle() 0 3 1
A isPayPalExpress() 0 6 2
A isPaydirekt() 0 6 2
A getFingerprintJsUrl() 0 8 1
A showPaydirektEmailMessage() 0 6 3
A _getShippingPrice() 0 3 1
A getShippingAddress() 0 6 2
A getCarrierName() 0 6 2
A renderAddress() 0 6 1
A getBillingAddress() 0 4 1
A getCurrentShippingRate() 0 3 1
A renderShippingRateValue() 0 6 2
A __construct() 0 18 1
A renderShippingRateOption() 0 17 4
A getEmail() 0 4 2
A getQuote() 0 6 2
A _formatPrice() 0 7 1
B _beforeToHtml() 0 36 7
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2017 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Block\Onepage;
28
29
use Magento\Checkout\Model\Session;
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Model\Session 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...
30
use Magento\Framework\Pricing\PriceCurrencyInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Pricing\PriceCurrencyInterface 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...
31
use Magento\Quote\Model\Quote\Address\Rate;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quote\Address\Rate 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...
32
use Magento\Quote\Model\Quote\Address;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quote\Address 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...
33
use Magento\Framework\DataObject;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\DataObject 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...
34
use Payone\Core\Model\PayoneConfig;
35
36
/**
37
 * Order review block
38
 */
39
class Review extends \Magento\Framework\View\Element\Template
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Element\Template 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...
40
{
41
    /**
42
     * Template
43
     *
44
     * @var string
45
     */
46
    protected $_template = 'Payone_Core::onepage/review.phtml';
47
48
    /**
49
     * @var \Magento\Quote\Model\Quote
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quote 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...
50
     */
51
    protected $_quote;
52
53
    /**
54
     * @var \Magento\Quote\Model\Quote\Address
55
     */
56
    protected $_address;
57
58
    /**
59
     * @var \Magento\Customer\Model\Address\Config
0 ignored issues
show
Bug introduced by
The type Magento\Customer\Model\Address\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...
60
     */
61
    protected $_addressConfig;
62
63
    /**
64
     * Currently selected shipping rate
65
     *
66
     * @var Rate
67
     */
68
    protected $_currentShippingRate = null;
69
70
    /**
71
     * Paypal controller path
72
     *
73
     * @var string
74
     */
75
    protected $_controllerPath = 'payone/onepage';
76
77
    /**
78
     * @var \Magento\Tax\Helper\Data
0 ignored issues
show
Bug introduced by
The type Magento\Tax\Helper\Data 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 $_taxHelper;
81
82
    /**
83
     * @var PriceCurrencyInterface
84
     */
85
    protected $priceCurrency;
86
87
    /**
88
     * Checkout session object
89
     *
90
     * @var Session
91
     */
92
    protected $checkoutSession;
93
94
    /**
95
     * @var \Payone\Core\Helper\Shop
96
     */
97
    protected $shopHelper;
98
99
    /**
100
     * @var \Payone\Core\Helper\Database
101
     */
102
    protected $databaseHelper;
103
104
    /**
105
     * @param \Magento\Framework\View\Element\Template\Context $context
106
     * @param \Magento\Tax\Helper\Data $taxHelper
107
     * @param \Magento\Customer\Model\Address\Config $addressConfig
108
     * @param PriceCurrencyInterface $priceCurrency
109
     * @param Session $checkoutSession
110
     * @param \Payone\Core\Helper\Shop $shopHelper
111
     * @param \Payone\Core\Helper\Database $databaseHelper
112
     * @param array $data
113
     */
114
    public function __construct(
115
        \Magento\Framework\View\Element\Template\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Element\Template\Context 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...
116
        \Magento\Tax\Helper\Data $taxHelper,
117
        \Magento\Customer\Model\Address\Config $addressConfig,
118
        PriceCurrencyInterface $priceCurrency,
119
        Session $checkoutSession,
120
        \Payone\Core\Helper\Shop $shopHelper,
121
        \Payone\Core\Helper\Database $databaseHelper,
122
        array $data = []
123
    ) {
124
        parent::__construct($context, $data);
125
        $this->priceCurrency = $priceCurrency;
126
        $this->_taxHelper = $taxHelper;
127
        $this->_addressConfig = $addressConfig;
128
        $this->checkoutSession = $checkoutSession;
129
        $this->shopHelper = $shopHelper;
130
        $this->databaseHelper = $databaseHelper;
131
        $this->getQuote(); // fill quote property
132
    }
133
134
    /**
135
     * Return checkout quote object
136
     *
137
     * @return \Magento\Quote\Model\Quote
138
     */
139
    protected function getQuote()
140
    {
141
        if (!$this->_quote) {
142
            $this->_quote = $this->checkoutSession->getQuote();
143
        }
144
        return $this->_quote;
145
    }
146
147
    /**
148
     * Return quote billing address
149
     *
150
     * @return Address
151
     */
152
    public function getBillingAddress()
153
    {
154
        $oBillingAddress = $this->_quote->getBillingAddress();
155
        return $oBillingAddress;
156
    }
157
158
    /**
159
     * Return quote shipping address
160
     *
161
     * @return false|Address
162
     */
163
    public function getShippingAddress()
164
    {
165
        if ($this->_quote->getIsVirtual()) {
166
            return false;
167
        }
168
        return $this->_quote->getShippingAddress();
169
    }
170
171
    /**
172
     * Get HTML output for specified address
173
     *
174
     * @param Address $address
175
     * @return string
176
     */
177
    public function renderAddress(Address $address)
178
    {
179
        /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
180
        $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
181
        $addressData = \Magento\Framework\Convert\ConvertArray::toFlatArray($address->getData());
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Convert\ConvertArray 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...
182
        return $renderer->renderArray($addressData);
183
    }
184
185
    /**
186
     * Return carrier name from config, base on carrier code
187
     *
188
     * @param string $carrierCode
189
     * @return string
190
     */
191
    public function getCarrierName($carrierCode)
192
    {
193
        if ($name = $this->_scopeConfig->getValue("carriers/{$carrierCode}/title", \Magento\Store\Model\ScopeInterface::SCOPE_STORES)) {
0 ignored issues
show
Bug introduced by
The type Magento\Store\Model\ScopeInterface 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...
194
            return $name;
195
        }
196
        return $carrierCode;
197
    }
198
199
    /**
200
     * Get either shipping rate code or empty value on error
201
     *
202
     * @param DataObject $rate
203
     * @return string
204
     */
205
    public function renderShippingRateValue(DataObject $rate)
206
    {
207
        if ($rate->getErrorMessage()) {
208
            return '';
209
        }
210
        return $rate->getCode();
211
    }
212
213
    /**
214
     * Get shipping rate code title and its price or error message
215
     *
216
     * @param DataObject $rate
217
     * @param string $format
218
     * @param string $inclTaxFormat
219
     * @return string
220
     */
221
    public function renderShippingRateOption(DataObject $rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)')
222
    {
223
        $renderedInclTax = '';
224
        if ($rate->getErrorMessage()) {
225
            $price = $rate->getErrorMessage();
226
        } else {
227
            $price = $this->_getShippingPrice(
228
                $rate->getPrice(),
229
                $this->_taxHelper->displayShippingPriceIncludingTax()
230
            );
231
232
            $incl = $this->_getShippingPrice($rate->getPrice(), true);
233
            if ($incl != $price && $this->_taxHelper->displayShippingBothPrices()) {
234
                $renderedInclTax = sprintf($inclTaxFormat, $this->escapeHtml(__('Incl. Tax')), $incl);
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

234
                $renderedInclTax = sprintf($inclTaxFormat, $this->escapeHtml(/** @scrutinizer ignore-call */ __('Incl. Tax')), $incl);
Loading history...
235
            }
236
        }
237
        return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax);
238
    }
239
240
    /**
241
     * Getter for current shipping rate
242
     *
243
     * @return Rate
244
     */
245
    public function getCurrentShippingRate()
246
    {
247
        return $this->_currentShippingRate;
248
    }
249
250
    /**
251
     * Get quote email
252
     *
253
     * @return string
254
     */
255
    public function getEmail()
256
    {
257
        $billingAddress = $this->getBillingAddress();
258
        return $billingAddress ? $billingAddress->getEmail() : '';
0 ignored issues
show
introduced by
$billingAddress is of type Magento\Quote\Model\Quote\Address, thus it always evaluated to true.
Loading history...
259
    }
260
261
    /**
262
     * Return formatted shipping price
263
     *
264
     * @param float $price
265
     * @param bool $isInclTax
266
     * @return string
267
     */
268
    protected function _getShippingPrice($price, $isInclTax)
269
    {
270
        return $this->_formatPrice($this->_taxHelper->getShippingPrice($price, $isInclTax, $this->_address));
271
    }
272
273
    /**
274
     * Format price base on store convert price method
275
     *
276
     * @param float $price
277
     * @return string
278
     */
279
    protected function _formatPrice($price)
280
    {
281
        return $this->priceCurrency->convertAndFormat(
282
            $price,
283
            true,
284
            PriceCurrencyInterface::DEFAULT_PRECISION,
285
            $this->_quote->getStore()
286
        );
287
    }
288
289
    /**
290
     * Returns payment method display title
291
     *
292
     * @return string
293
     */
294
    public function getPaymentMethodTitle()
295
    {
296
        return $this->shopHelper->getConfigParam('title', $this->_quote->getPayment()->getMethod(), 'payment');
297
    }
298
299
    /**
300
     * Check if paypal express is used
301
     *
302
     * @return bool
303
     */
304
    public function isPayPalExpress()
305
    {
306
        if ($this->_quote->getPayment()->getMethod() == PayoneConfig::METHOD_PAYPAL) {
307
            return true;
308
        }
309
        return false;
310
    }
311
312
    /**
313
     * Check if paypal express is used
314
     *
315
     * @return bool
316
     */
317
    public function isPaydirekt()
318
    {
319
        if ($this->_quote->getPayment()->getMethod() == PayoneConfig::METHOD_PAYDIREKT) {
320
            return true;
321
        }
322
        return false;
323
    }
324
325
    /**
326
     * Generate URL to the fingerprint.js Javascript file
327
     *
328
     * @return string
329
     */
330
    public function getFingerprintJsUrl()
331
    {
332
        $params = [
333
            'theme' => 'Magento/luma',
334
            'area' => 'frontend',
335
        ];
336
        $asset = $this->_assetRepo->createAsset('Payone_Core::js/fingerprint2.min.js', $params);
337
        return $asset->getUrl();
338
    }
339
340
    /**
341
     * Check if paydirekt email message has to be shown
342
     *
343
     * @return bool
344
     */
345
    public function showPaydirektEmailMessage()
346
    {
347
        if ($this->_quote->getPayment()->getMethod() == PayoneConfig::METHOD_PAYDIREKT && $this->databaseHelper->getPaydirektOneklickOrderCount($this->_quote->getCustomerId()) == 0) {
348
            return true;
349
        }
350
        return false;
351
    }
352
353
    /**
354
     * Retrieve payment method and assign additional template values
355
     *
356
     * @return $this
357
     */
358
    protected function _beforeToHtml()
359
    {
360
        $this->setShippingRateRequired(true);
361
        if ($this->_quote->getIsVirtual()) {
362
            $this->setShippingRateRequired(false);
363
        } else {
364
            // prepare shipping rates
365
            $this->_address = $this->_quote->getShippingAddress();
366
            $this->_address->setCollectShippingRates(true);
367
            $groups = $this->_address->getGroupedAllShippingRates();
368
            if ($groups && $this->_address) {
369
                $this->setShippingRateGroups($groups);
370
                // determine current selected code & name
371
                foreach ($groups as $code => $rates) {
372
                    foreach ($rates as $rate) {
373
                        if ($this->_address->getShippingMethod() == $rate->getCode()) {
374
                            $this->_currentShippingRate = $rate;
375
                            break 2;
376
                        }
377
                    }
378
                }
379
            }
380
381
            // misc shipping parameters
382
            $this->setShippingMethodSubmitUrl(
383
                $this->getUrl("{$this->_controllerPath}/review", ['_secure' => true])
384
            );
385
        }
386
387
        $this->setEditUrl(
388
            $this->getUrl("{$this->_controllerPath}/edit")
389
        )->setPlaceOrderUrl(
390
            $this->getUrl("{$this->_controllerPath}/placeOrder", ['_secure' => true])
391
        );
392
393
        return parent::_beforeToHtml();
394
    }
395
}
396