FormCc::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 16
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Copyright © Wirecard Brasil. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace Moip\Magento2\Block;
10
11
use Magento\Backend\Model\Session\Quote;
0 ignored issues
show
Bug introduced by
The type Magento\Backend\Model\Session\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...
12
use Magento\Framework\Pricing\Helper\Data as PriceHelper;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Pricing\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...
13
use Magento\Framework\View\Element\Template\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...
14
use Magento\Payment\Block\Form\Cc;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Block\Form\Cc 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...
15
use Magento\Payment\Helper\Data;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\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...
16
use Magento\Payment\Model\Config;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\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...
17
use Moip\Magento2\Gateway\Config\Config as ConfigBase;
18
use Moip\Magento2\Gateway\Config\ConfigCc;
19
20
/**
21
 * Class FormCc - Form for payment by cc.
22
 */
23
class FormCc extends Cc
24
{
25
    /**
26
     * Cc template.
27
     *
28
     * @var string
29
     */
30
    protected $_template = 'Moip_Magento2::form/cc.phtml';
31
32
    /**
33
     * @var Quote
34
     */
35
    protected $session;
36
37
    /**
38
     * @var configCc
39
     */
40
    protected $configCc;
41
42
    /**
43
     * @var configProvider
0 ignored issues
show
Bug introduced by
The type Moip\Magento2\Block\configProvider 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 $configProvider;
46
47
    /**
48
     * @var paymentDataHelper
0 ignored issues
show
Bug introduced by
The type Moip\Magento2\Block\paymentDataHelper 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...
49
     */
50
    private $paymentDataHelper;
51
52
    /**
53
     * @var configBase
54
     */
55
    private $configBase;
56
57
    /**
58
     * @var priceHelper
59
     */
60
    private $priceHelper;
61
62
    /**
63
     * @param Context    $context
64
     * @param Config     $paymentConfig
65
     * @param Quote      $session
66
     * @param ConfigCc   $configCc
67
     * @param configBase $configBase
68
     * @param Data       $paymentDataHelper
69
     * @param array      $data
70
     */
71
    public function __construct(
72
        Context $context,
73
        Config $paymentConfig,
74
        Quote $session,
75
        ConfigCc $configCc,
76
        ConfigBase $configBase,
77
        Data $paymentDataHelper,
78
        PriceHelper $priceHelper,
79
        array $data = []
80
    ) {
81
        parent::__construct($context, $paymentConfig, $data);
82
        $this->session = $session;
83
        $this->configBase = $configBase;
84
        $this->configCc = $configCc;
85
        $this->priceHelper = $priceHelper;
86
        $this->paymentDataHelper = $paymentDataHelper;
87
    }
88
89
    /**
90
     * Title - Cc.
91
     *
92
     * @var string
93
     */
94
    public function getTitle()
95
    {
96
        return $this->configCc->getTitle();
97
    }
98
99
    /**
100
     * Select Installment - Cc.
101
     *
102
     * @var string
103
     */
104
    public function getSelectInstallments()
105
    {
106
        $total = $this->session->getQuote()->getGrandTotal();
107
        $installments = $this->getInstallments($total);
108
109
        return $installments;
110
    }
111
112
    /**
113
     * Key Public - Cc.
114
     *
115
     * @var string
116
     */
117
    public function getKeyPublic()
118
    {
119
        return $this->configBase->getMerchantGatewayKeyPublic();
120
    }
121
122
    /**
123
     * Installments - Cc.
124
     *
125
     * @param float $amount
126
     *
127
     * @var string
128
     */
129
    public function getInstallments($amount)
130
    {
131
        $typeInstallment = $this->configCc->getTypeInstallment();
132
        $limitByInstallment = $this->configCc->getMaxInstallment();
0 ignored issues
show
Unused Code introduced by
The assignment to $limitByInstallment is dead and can be removed.
Loading history...
133
        $limitInstallmentValue = $this->configCc->getMinInstallment();
0 ignored issues
show
Unused Code introduced by
The assignment to $limitInstallmentValue is dead and can be removed.
Loading history...
134
        $interestByInstallment = $this->configCc->getInfoInterest();
135
        $plotlist = [];
136
        foreach ($interestByInstallment as $key => $_interest) {
137
            if ($key > 0) {
138
                $plotValue = $this->getInterestCompound($amount, $_interest, $key);
139
                if ($typeInstallment === 'simple') {
140
                    $plotValue = $this->getInterestSimple($amount, $_interest, $key);
141
                }
142
                $plotValue = number_format((float) $plotValue, 2, '.', '');
143
                $installmentPrice = $this->priceHelper->currency($plotValue, true, false);
144
                $plotlist[$key] = $key.__('x of ').$installmentPrice;
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

144
                $plotlist[$key] = $key./** @scrutinizer ignore-call */ __('x of ').$installmentPrice;
Loading history...
145
            }
146
        }
147
148
        return $plotlist;
149
    }
150
151
    /**
152
     * Interest Simple - Cc.
153
     *
154
     * @var float
155
     */
156
    public function getInterestSimple($total, $interest, $portion)
157
    {
158
        if ($interest) {
159
            $taxa = $interest / 100;
160
            $valinterest = $total * $taxa;
161
162
            return ($total + $valinterest) / $portion;
163
        }
164
165
        return $total / $portion;
166
    }
167
168
    /**
169
     * Interest Compound - Cc.
170
     *
171
     * @var float
172
     */
173
    public function getInterestCompound($total, $interest, $portion)
174
    {
175
        if ($interest) {
176
            $taxa = $interest / 100;
177
178
            return (($total * $taxa) * 1) / (1 - (pow(1 / (1 + $taxa), $portion)));
179
        }
180
181
        return 0;
182
    }
183
184
    /**
185
     * Use birth date capture - Cc.
186
     *
187
     * @var bool
188
     */
189
    public function getBirthDateCapture()
190
    {
191
        return $this->configCc->getUseBirthDateCapture();
192
    }
193
194
    /**
195
     * Use tax document capture - Cc.
196
     *
197
     * @var bool
198
     */
199
    public function getTaxDocumentCapture()
200
    {
201
        return $this->configCc->getUseTaxDocumentCapture();
202
    }
203
204
    /**
205
     * Use phone capture - Cc.
206
     *
207
     * @var bool
208
     */
209
    public function getPhoneCapture()
210
    {
211
        return $this->configCc->getUsePhoneCapture();
212
    }
213
}
214