Passed
Push[email protected] ( 6f4930...6fef5b )
by Bruno
13:24 queued 10:12
created

MoipInterest::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 24
rs 9.8666
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
declare(strict_types=1);
10
11
namespace Moip\Magento2\Model\Quote\Address\Total;
12
13
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...
14
use Magento\Framework\Phrase;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Phrase 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\Quote\Api\Data\PaymentInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Api\Data\PaymentInterface 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\Quote\Api\Data\ShippingAssignmentInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Api\Data\ShippingAssignmentInterface 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 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...
18
use Magento\Quote\Model\Quote\Address\Total;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quote\Address\Total 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...
19
use Magento\Quote\Model\Quote\Address\Total\AbstractTotal;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quot...ess\Total\AbstractTotal 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...
20
use Magento\Quote\Model\QuoteValidator;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\QuoteValidator 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...
21
22
/**
23
 * Class MoipInterest - Model data Total Address.
24
 */
25
class MoipInterest extends AbstractTotal
26
{
27
    /**
28
     * @var string
29
     */
30
    protected $_code = 'moip_interest_amount';
31
32
    /**
33
     * @var Session
34
     */
35
    protected $_checkoutSession;
36
37
    /**
38
     * @var QuoteValidator
39
     */
40
    protected $_quoteValidator = null;
41
42
    /**
43
     * @var PaymentInterface
44
     */
45
    protected $_payment;
46
47
    /**
48
     * Payment MoipInterest constructor.
49
     *
50
     * @param QuoteValidator   $quoteValidator
51
     * @param Session          $checkoutSession
52
     * @param PaymentInterface $payment
53
     */
54
    public function __construct(
55
        QuoteValidator $quoteValidator,
56
        Session $checkoutSession,
57
        PaymentInterface $payment
58
    ) {
59
        $this->_quoteValidator = $quoteValidator;
60
        $this->_checkoutSession = $checkoutSession;
61
        $this->_payment = $payment;
62
    }
63
64
    /**
65
     * Collect totals process.
66
     *
67
     * @param Quote                       $quote
68
     * @param ShippingAssignmentInterface $shippingAssignment
69
     * @param Total                       $total
70
     *
71
     * @return $this
72
     */
73
    public function collect(
74
        Quote $quote,
75
        ShippingAssignmentInterface $shippingAssignment,
76
        Total $total
77
    ) {
78
        parent::collect($quote, $shippingAssignment, $total);
79
80
        if (!count($shippingAssignment->getItems())) {
81
            return $this;
82
        }
83
84
        $moipInterest = $quote->getMoipInterestAmount();
85
        $baseMoipInterest = $quote->getBaseMoipInterestAmount();
86
87
        $total->setMoipInterestAmount($moipInterest);
88
        $total->setBaseMoipInterestAmount($baseMoipInterest);
89
90
        $total->setTotalAmount('moip_interest_amount', $moipInterest);
91
        $total->setBaseTotalAmount('base_moip_interest_amount', $baseMoipInterest);
92
93
        $total->setGrandTotal((float) $total->getGrandTotal());
94
        $total->setBaseGrandTotal((float) $total->getBaseGrandTotal());
95
96
        return $this;
97
    }
98
99
    /**
100
     * Assign subtotal amount and label to address object.
101
     *
102
     * @param Quote $quote
103
     * @param Total $total
104
     *
105
     * @return array
106
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
107
     */
108
    public function fetch(
109
        Quote $quote,
110
        Total $total
111
    ) {
112
        $result = null;
113
        $interest = $total->getMoipInterestAmount();
114
        $labelByInterest = $this->getLabelByInterest($interest);
115
        if ((int) $interest !== 0) {
116
            $result = [
117
                'code'  => $this->getCode(),
118
                'title' => $labelByInterest,
119
                'value' => $interest,
120
            ];
121
        }
122
123
        return $result;
124
    }
125
126
    /**
127
     * Get Subtotal label.
128
     *
129
     * @return Phrase
130
     */
131
    public function getLabel()
132
    {
133
        return __('Installment Interest');
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

133
        return /** @scrutinizer ignore-call */ __('Installment Interest');
Loading history...
134
    }
135
136
    /**
137
     * Get Subtotal label by Interest.
138
     *
139
     * @param $interest | float
0 ignored issues
show
Documentation Bug introduced by
The doc comment | float at position 0 could not be parsed: Unknown type name '|' at position 0 in | float.
Loading history...
140
     *
141
     * @return Phrase
142
     */
143
    public function getLabelByInterest($interest)
144
    {
145
        if ($interest >= 0) {
146
            return __('Installment Interest');
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

146
            return /** @scrutinizer ignore-call */ __('Installment Interest');
Loading history...
147
        }
148
149
        return __('Discount Cash');
150
    }
151
}
152