Managemandate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 13.75 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 11
loc 80
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
B sendRequest() 0 41 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 - 2016 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\Model\Api\Request;
28
29
use Payone\Core\Model\Methods\PayoneMethod;
30
use Magento\Quote\Model\Quote;
31
32
/**
33
 * Class for the PAYONE Server API request "managemandate"
34
 */
35
class Managemandate extends AddressRequest
36
{
37
    /**
38
     * PAYONE database helper
39
     *
40
     * @var \Payone\Core\Helper\Database
41
     */
42
    protected $databaseHelper;
43
44
    /**
45
     * Constructor
46
     *
47
     * @param \Payone\Core\Helper\Shop                $shopHelper
48
     * @param \Payone\Core\Helper\Environment         $environmentHelper
49
     * @param \Payone\Core\Helper\Api                 $apiHelper
50
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
51
     * @param \Payone\Core\Helper\Customer            $customerHelper
52
     * @param \Payone\Core\Helper\Database            $databaseHelper
53
     */
54 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
        \Payone\Core\Helper\Shop $shopHelper,
56
        \Payone\Core\Helper\Environment $environmentHelper,
57
        \Payone\Core\Helper\Api $apiHelper,
58
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
59
        \Payone\Core\Helper\Customer $customerHelper,
60
        \Payone\Core\Helper\Database $databaseHelper
61
    ) {
62
        parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog, $customerHelper);
63
        $this->databaseHelper = $databaseHelper;
64
    }
65
66
    /**
67
     * Send request "managemandate" to PAYONE server API
68
     *
69
     * @param  PayoneMethod $oPayment
70
     * @param  Quote        $oQuote
71
     * @return array
72
     */
73
    public function sendRequest(PayoneMethod $oPayment, Quote $oQuote)
74
    {
75
        $oCustomer = $oQuote->getCustomer();
76
77
        $this->addParameter('request', 'managemandate'); // Request method
78
        $this->addParameter('mode', $oPayment->getOperationMode()); // PayOne Portal Operation Mode (live or test)
79
        $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); // ID of PayOne Sub-Account
80
        $this->addParameter('clearingtype', 'elv');
81
82
        $this->addParameter('customerid', $oCustomer->getId());
83
        $sPayOneUserId = $this->databaseHelper->getPayoneUserIdByCustNr($oCustomer->getId());
84
        if ($sPayOneUserId) {
85
            $this->addParameter('userid', $sPayOneUserId);
86
        }
87
88
        $oBilling = $oQuote->getBillingAddress();
89
        $this->addUserDataParameters(
90
            $oBilling,
91
            $oPayment,
92
            $oCustomer->getGender(),
93
            $oCustomer->getEmail(),
94
            $oCustomer->getDob()
95
        );
96
97
        $this->addParameter('language', $this->shopHelper->getLocale());
98
99
        $oInfoInstance = $oPayment->getInfoInstance();
100
        $this->addParameter('bankcountry', $oInfoInstance->getAdditionalInformation('bank_country'));
101
        $this->addParameter('iban', $oInfoInstance->getAdditionalInformation('iban'));
102
        if ($oInfoInstance->getAdditionalInformation('bic')) {
103
            $this->addParameter('bic', $oInfoInstance->getAdditionalInformation('bic'));
104
        }
105
        $this->addParameter('currency', $oQuote->getQuoteCurrencyCode());
106
107
        $aResponse = $this->send($oPayment);
108
        if (is_array($aResponse)) {
109
            $aResponse['mode'] = $oPayment->getOperationMode();
110
        }
111
112
        return $aResponse;
113
    }
114
}
115