Passed
Branch [email protected] (0b3c39)
by Bruno
03:01
created

FormCc::getInstallments()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 26
rs 9.2222
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
     * @var string
126
     */
127
    public function getInstallments($ammount)
128
    {
129
        $typeInstallment = $this->configCc->getTypeInstallment();
130
        $limitByInstallment = $this->configCc->getMaxInstallment();
131
        $limitInstallmentValue = $this->configCc->getMinInstallment();
132
        $interestByInstallment = $this->configCc->getInfoInterest();
133
134
        foreach ($interestByInstallment as $key => $_interest) {
135
            if ($key > 1 && $key <= $limitByInstallment) {
136
                $plotValue = $this->getInterestCompound($ammount, $_interest, $key);
137
138
                if ($typeInstallment === 'simple') {
139
                    $plotValue = $this->getInterestSimple($ammount, $_interest, $key);
140
                }
141
142
                if ($plotValue < $limitInstallmentValue) {
143
                    break;
144
                }
145
146
                $plotValue = number_format((float) $plotValue, 2, '.', '');
147
                $installmentPrice = $this->priceHelper->currency($plotValue, true, false);
148
                $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

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