Completed
Push — master ( 9097d5...0ce82e )
by Florian
06:13
created

Review::getEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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;
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;
34
35
/**
36
 * Paypal Express Onepage checkout block
37
 *
38
 * @author      Magento Core Team <[email protected]>
39
 */
40
class Review extends \Magento\Framework\View\Element\Template
41
{
42
    /**
43
     * @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...
44
     */
45
    protected $_quote;
46
47
    /**
48
     * @var \Magento\Quote\Model\Quote\Address
49
     */
50
    protected $_address;
51
52
    /**
53
     * @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...
54
     */
55
    protected $_addressConfig;
56
57
    /**
58
     * Currently selected shipping rate
59
     *
60
     * @var Rate
61
     */
62
    protected $_currentShippingRate = null;
63
64
    /**
65
     * Paypal controller path
66
     *
67
     * @var string
68
     */
69
    protected $_controllerPath = 'payone/onepage';
70
71
    /**
72
     * @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...
73
     */
74
    protected $_taxHelper;
75
76
    /**
77
     * @var PriceCurrencyInterface
78
     */
79
    protected $priceCurrency;
80
81
    /**
82
     * Checkout session object
83
     *
84
     * @var Session
85
     */
86
    protected $checkoutSession;
87
88
    /**
89
     * @param \Magento\Framework\View\Element\Template\Context $context
90
     * @param \Magento\Tax\Helper\Data $taxHelper
91
     * @param \Magento\Customer\Model\Address\Config $addressConfig
92
     * @param PriceCurrencyInterface $priceCurrency
93
     * @param Session $checkoutSession
94
     * @param array $data
95
     */
96
    public function __construct(
97
        \Magento\Framework\View\Element\Template\Context $context,
98
        \Magento\Tax\Helper\Data $taxHelper,
99
        \Magento\Customer\Model\Address\Config $addressConfig,
100
        PriceCurrencyInterface $priceCurrency,
101
        Session $checkoutSession,
102
        array $data = []
103
    ) {
104
        parent::__construct($context, $data);
105
        $this->priceCurrency = $priceCurrency;
106
        $this->_taxHelper = $taxHelper;
107
        $this->_addressConfig = $addressConfig;
108
        $this->checkoutSession = $checkoutSession;
109
        $this->getQuote(); // fill quote property
110
    }
111
112
    /**
113
     * Return checkout quote object
114
     *
115
     * @return \Magento\Quote\Model\Quote
116
     */
117
    protected function getQuote()
118
    {
119
        if (!$this->_quote) {
120
            $this->_quote = $this->checkoutSession->getQuote();
121
        }
122
        return $this->_quote;
123
    }
124
125
    /**
126
     * Return quote billing address
127
     *
128
     * @return Address
129
     */
130
    public function getBillingAddress()
131
    {
132
        return $this->_quote->getBillingAddress();
133
    }
134
135
    /**
136
     * Return quote shipping address
137
     *
138
     * @return false|Address
139
     */
140
    public function getShippingAddress()
141
    {
142
        if ($this->_quote->getIsVirtual()) {
143
            return false;
144
        }
145
        return $this->_quote->getShippingAddress();
146
    }
147
148
    /**
149
     * Get HTML output for specified address
150
     *
151
     * @param Address $address
152
     * @return string
153
     */
154
    public function renderAddress(Address $address)
155
    {
156
        /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
157
        $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
158
        $addressData = \Magento\Framework\Convert\ConvertArray::toFlatArray($address->getData());
159
        return $renderer->renderArray($addressData);
160
    }
161
162
    /**
163
     * Return carrier name from config, base on carrier code
164
     *
165
     * @param string $carrierCode
166
     * @return string
167
     */
168
    public function getCarrierName($carrierCode)
169
    {
170
        if ($name = $this->_scopeConfig->getValue("carriers/{$carrierCode}/title", \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
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...
171
            return $name;
172
        }
173
        return $carrierCode;
174
    }
175
176
    /**
177
     * Get either shipping rate code or empty value on error
178
     *
179
     * @param DataObject $rate
180
     * @return string
181
     */
182
    public function renderShippingRateValue(DataObject $rate)
183
    {
184
        if ($rate->getErrorMessage()) {
185
            return '';
186
        }
187
        return $rate->getCode();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $rate->getCode() also could return the type Magento\Framework\DataObject|boolean|array which is incompatible with the documented return type string.
Loading history...
188
    }
189
190
    /**
191
     * Get shipping rate code title and its price or error message
192
     *
193
     * @param DataObject $rate
194
     * @param string $format
195
     * @param string $inclTaxFormat
196
     * @return string
197
     */
198
    public function renderShippingRateOption(DataObject $rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)')
199
    {
200
        $renderedInclTax = '';
201
        if ($rate->getErrorMessage()) {
202
            $price = $rate->getErrorMessage();
203
        } else {
204
            $price = $this->_getShippingPrice(
205
                $rate->getPrice(),
206
                $this->_taxHelper->displayShippingPriceIncludingTax()
207
            );
208
209
            $incl = $this->_getShippingPrice($rate->getPrice(), true);
210
            if ($incl != $price && $this->_taxHelper->displayShippingBothPrices()) {
211
                $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

211
                $renderedInclTax = sprintf($inclTaxFormat, $this->escapeHtml(/** @scrutinizer ignore-call */ __('Incl. Tax')), $incl);
Loading history...
212
            }
213
        }
214
        return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax);
0 ignored issues
show
Bug introduced by
It seems like $rate->getMethodTitle() can also be of type Magento\Framework\DataObject; however, parameter $data of Magento\Framework\View\E...ractBlock::escapeHtml() does only seem to accept string|array, maybe add an additional type check? ( Ignorable by Annotation )

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

214
        return sprintf($format, $this->escapeHtml(/** @scrutinizer ignore-type */ $rate->getMethodTitle()), $price, $renderedInclTax);
Loading history...
215
    }
216
217
    /**
218
     * Getter for current shipping rate
219
     *
220
     * @return Rate
221
     */
222
    public function getCurrentShippingRate()
223
    {
224
        return $this->_currentShippingRate;
225
    }
226
227
    /**
228
     * Get quote email
229
     *
230
     * @return string
231
     */
232
    public function getEmail()
233
    {
234
        $billingAddress = $this->getBillingAddress();
235
        return $billingAddress ? $billingAddress->getEmail() : '';
236
    }
237
238
    /**
239
     * Return formatted shipping price
240
     *
241
     * @param float $price
242
     * @param bool $isInclTax
243
     * @return string
244
     */
245
    protected function _getShippingPrice($price, $isInclTax)
246
    {
247
        return $this->_formatPrice($this->_taxHelper->getShippingPrice($price, $isInclTax, $this->_address));
248
    }
249
250
    /**
251
     * Format price base on store convert price method
252
     *
253
     * @param float $price
254
     * @return string
255
     */
256
    protected function _formatPrice($price)
257
    {
258
        return $this->priceCurrency->convertAndFormat(
259
            $price,
260
            true,
261
            PriceCurrencyInterface::DEFAULT_PRECISION,
262
            $this->_quote->getStore()
263
        );
264
    }
265
266
    /**
267
     * Retrieve payment method and assign additional template values
268
     *
269
     * @return $this
270
     */
271
    protected function _beforeToHtml()
272
    {
273
        $methodInstance = $this->_quote->getPayment()->getMethodInstance();
274
        $this->setPaymentMethodTitle($methodInstance->getTitle());
0 ignored issues
show
Bug introduced by
The method setPaymentMethodTitle() does not exist on Payone\Core\Block\Onepage\Review. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

274
        $this->/** @scrutinizer ignore-call */ 
275
               setPaymentMethodTitle($methodInstance->getTitle());
Loading history...
275
276
        $this->setShippingRateRequired(true);
0 ignored issues
show
Bug introduced by
The method setShippingRateRequired() does not exist on Payone\Core\Block\Onepage\Review. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

276
        $this->/** @scrutinizer ignore-call */ 
277
               setShippingRateRequired(true);
Loading history...
277
        if ($this->_quote->getIsVirtual()) {
278
            $this->setShippingRateRequired(false);
279
        } else {
280
            // prepare shipping rates
281
            $this->_address = $this->_quote->getShippingAddress();
282
            $groups = $this->_address->getGroupedAllShippingRates();
283
            if ($groups && $this->_address) {
284
                $this->setShippingRateGroups($groups);
0 ignored issues
show
Bug introduced by
The method setShippingRateGroups() does not exist on Payone\Core\Block\Onepage\Review. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

284
                $this->/** @scrutinizer ignore-call */ 
285
                       setShippingRateGroups($groups);
Loading history...
285
                // determine current selected code & name
286
                foreach ($groups as $code => $rates) {
287
                    foreach ($rates as $rate) {
288
                        if ($this->_address->getShippingMethod() == $rate->getCode()) {
289
                            $this->_currentShippingRate = $rate;
290
                            break 2;
291
                        }
292
                    }
293
                }
294
            }
295
296
            // misc shipping parameters
297
            $this->setShippingMethodSubmitUrl(
0 ignored issues
show
Bug introduced by
The method setShippingMethodSubmitUrl() does not exist on Payone\Core\Block\Onepage\Review. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

297
            $this->/** @scrutinizer ignore-call */ 
298
                   setShippingMethodSubmitUrl(
Loading history...
298
                $this->getUrl("{$this->_controllerPath}/review", ['_secure' => true])
299
            );
300
        }
301
302
        $this->setEditUrl(
0 ignored issues
show
Bug introduced by
The method setEditUrl() does not exist on Payone\Core\Block\Onepage\Review. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

302
        $this->/** @scrutinizer ignore-call */ 
303
               setEditUrl(
Loading history...
303
            $this->getUrl("{$this->_controllerPath}/edit")
304
        )->setPlaceOrderUrl(
0 ignored issues
show
Bug introduced by
The method setPlaceOrderUrl() does not exist on Payone\Core\Block\Onepage\Review. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

304
        )->/** @scrutinizer ignore-call */ setPlaceOrderUrl(
Loading history...
305
            $this->getUrl("{$this->_controllerPath}/placeOrder", ['_secure' => true])
306
        );
307
308
        return parent::_beforeToHtml();
309
    }
310
}
311