BoletoInfo   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 128
Duplicated Lines 32.81 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 8
Bugs 3 Features 0
Metric Value
wmc 19
c 8
b 3
f 0
lcom 1
cbo 3
dl 42
loc 128
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
B getValorFinal() 0 22 4
A getDataVencimentoCalculada() 0 16 3
A getValorTaxa() 10 10 2
A getValorMulta() 10 10 2
A getDataVencimentoRecebida() 9 9 2
A getDataDocumento() 9 9 2
A getDataProcessamento() 0 16 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
namespace CbCaio\Boletos\Models\BoletoInfo;
3
4
use Carbon\Carbon;
5
use CbCaio\Boletos\Calculators\Calculator;
6
use CbCaio\Boletos\Models\BoletoInfo\Base\Boleto;
7
8
class BoletoInfo extends Boleto
9
{
10
    protected $date_format = 'Y-m-d';
11
12
    /**
13
     * @param bool|FALSE $formatado10digitos
14
     * @param bool|FALSE $inteiro
15
     * @return int|null|string
16
     */
17
    public function getValorFinal($formatado10digitos = false, $inteiro = false)
18
    {
19
        $data_processamento = $this->getDataProcessamento();
20
        $data_vencimento    = $this->getDataVencimentoRecebida();
21
        $vencido            = ($data_processamento->toDateString() > $data_vencimento->toDateString());
22
23
        $valor_cobrado = $this->getValorBase();
24
        if ($vencido) {
25
            $diferenca_dias = $data_processamento->diffInDays($data_vencimento);
26
            $valor_cobrado += $this->getValorTaxa(true) * $diferenca_dias + $this->getValorMulta(true);
27
        }
28
29
        if ($formatado10digitos === true) {
30
            return Calculator::formataNumero($valor_cobrado, 10, 0);
31
        }
32
33
        if ($inteiro === true) {
34
            return $valor_cobrado;
35
        }
36
        
37
        return Calculator::formataValor($valor_cobrado);
38
    }
39
40
    /**
41
     * @return Carbon
42
     */
43
    public function getDataVencimentoCalculada()
44
    {
45
        $data_hoje = Carbon::now()->setTime(0, 0, 0);
46
        if ($data_hoje->timestamp > $this->getDataVencimentoRecebida()->timestamp) {
47
            $dias_para_pagar = $this->getDiasParaPagar();
48
            if ($dias_para_pagar == null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $dias_para_pagar of type null|integer against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
49
                return $data_hoje;
50
            } else {
51
                $data_vencimento = $data_hoje->addDay($dias_para_pagar);
52
53
                return $data_vencimento;
54
            }
55
        } else {
56
            return $this->getDataVencimentoRecebida();
57
        }
58
    }
59
60
    /**
61
     * @param bool|FALSE $valor_inteiro
62
     * @return int|string
63
     */
64 View Code Duplication
    public function getValorTaxa($valor_inteiro = false)
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...
65
    {
66
        $valor_taxa = intval(($this->getTaxaPercentual() / 3000) * $this->getValorBase());
67
68
        if ($valor_inteiro) {
69
            return $valor_taxa;
70
        } else {
71
            return Calculator::formataValor($valor_taxa);
72
        }
73
    }
74
75
    /**
76
     * @param bool|FALSE $valor_inteiro
77
     * @return int|string
78
     */
79 View Code Duplication
    public function getValorMulta($valor_inteiro = false)
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...
80
    {
81
        $valor_multa = intval(($this->getMultaPercentual() / 100) * $this->getValorBase());
82
83
        if ($valor_inteiro) {
84
            return $valor_multa;
85
        } else {
86
            return Calculator::formataValor($valor_multa);
87
        }
88
    }
89
90
    /**
91
     * @return Carbon
92
     */
93 View Code Duplication
    public function getDataVencimentoRecebida()
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...
94
    {
95
        if ($this->attributes['data_vencimento'] instanceof Carbon) {
96
            return $this->attributes['data_vencimento']->setTime(0, 0, 0);
97
        } else {
98
            return Carbon::createFromFormat($this->date_format, $this->attributes['data_vencimento'])
99
                         ->setTime(0, 0, 0);
100
        }
101
    }
102
103
    /**
104
     * @return Carbon
105
     */
106 View Code Duplication
    public function getDataDocumento()
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...
107
    {
108
        if ($this->attributes['data_documento'] instanceof Carbon) {
109
            return $this->attributes['data_documento']->setTime(0, 0, 0);
110
        } else {
111
            return Carbon::createFromFormat(
112
                $this->date_format, $this->attributes['data_documento'])->setTime(0, 0, 0);
113
        }
114
    }
115
116
    /**
117
     * @return Carbon
118
     */
119
    public function getDataProcessamento()
120
    {
121
        if (isset($this->attributes['data_processamento'])) {
122
            $data_processamento = $this->attributes['data_processamento'];
123
124
            if (!($data_processamento instanceof Carbon)) {
125
                $data_processamento = Carbon::createFromFormat('Y-m-d', $data_processamento);
126
            }
127
128
            if (!$data_processamento->isPast()) {
129
                return $data_processamento->setTime(0, 0, 0);
130
            }
131
        }
132
133
        return Carbon::now()->setTime(0, 0, 0);
134
    }
135
}