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 18
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 1
dl 0
loc 18
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\Order\Total\Invoice;
12
13
use Magento\Sales\Model\Order\Invoice;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Order\Invoice 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\Sales\Model\Order\Invoice\Total\AbstractTotal;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Orde...ice\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...
15
16
/**
17
 * Class MoipInterest - Model data Total Invoice.
18
 */
19
class MoipInterest extends AbstractTotal
20
{
21
    /**
22
     * Collect invoice subtotal.
23
     *
24
     * @param Invoice $invoice
25
     *
26
     * @return $this
27
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
28
     */
29
    public function collect(Invoice $invoice)
30
    {
31
        $order = $invoice->getOrder();
32
        $moipInterest = $order->getMoipInterestAmount();
33
        $baseMoipInterestAmount = $order->getBaseMoipInterestAmount();
34
35
        if ((int) $moipInterest === 0) {
36
            return $this;
37
        }
38
39
        $invoice->setMoipInterestAmount($moipInterest);
40
        $invoice->setBaseMoipInterestAmount($baseMoipInterestAmount);
41
        $invoice->setGrandTotal($invoice->getGrandTotal() + $moipInterest);
42
        $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseMoipInterestAmount);
43
        $order->setMoipInterestAmountInvoiced($moipInterest);
44
        $order->setBaseMoipInterestAmountInvoiced($baseMoipInterestAmount);
45
46
        return $this;
47
    }
48
}
49