Passed
Push — master ( d65fb2...07d9b9 )
by Roberto
05:56 queued 03:13
created

TraitBlocoIV::blocoIV()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 135

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 135
ccs 0
cts 127
cp 0
crap 6
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe\Traits;
4
5
/**
6
 * Bloco totais da NFCe
7
 */
8
trait TraitBlocoIV
9
{
10
    protected function blocoIV($y)
11
    {
12
        $this->bloco4H = 13;
0 ignored issues
show
Bug introduced by
The property bloco4H does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
        
14
        //$aFont = ['font'=> $this->fontePadrao, 'size' => 7, 'style' => ''];
15
        //$this->pdf->textBox($this->margem, $y, $this->wPrint, $this->bloco4H, '', $aFont, 'T', 'C', true, '', false);
16
        
17
        $qtd = $this->det->length;
0 ignored issues
show
Bug introduced by
The property det does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
        $valor = $this->getTagValue($this->ICMSTot, 'vNF');
0 ignored issues
show
Bug introduced by
The property ICMSTot does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
It seems like getTagValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19
        $desconto = $this->getTagValue($this->ICMSTot, 'vDesc');
0 ignored issues
show
Bug introduced by
It seems like getTagValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
20
        $bruto = $valor + $desconto;
21
        
22
        $aFont = ['font'=> $this->fontePadrao, 'size' => 8, 'style' => ''];
0 ignored issues
show
Bug introduced by
The property fontePadrao does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
        $texto = "Qtde total de itens";
24
        $this->pdf->textBox(
0 ignored issues
show
Bug introduced by
The property pdf does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
            $this->margem,
0 ignored issues
show
Bug introduced by
The property margem does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
            $y,
27
            $this->wPrint/2,
0 ignored issues
show
Bug introduced by
The property wPrint does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
            3,
29
            $texto,
30
            $aFont,
31
            'T',
32
            'L',
33
            false,
34
            '',
35
            false
36
        );
37
        $y1 = $this->pdf->textBox(
38
            $this->margem+$this->wPrint/2,
39
            $y,
40
            $this->wPrint/2,
41
            3,
42
            $qtd,
43
            $aFont,
44
            'T',
45
            'R',
46
            false,
47
            '',
48
            false
49
        );
50
        
51
        $texto = "Valor Total R$";
52
        $this->pdf->textBox(
53
            $this->margem,
54
            $y+$y1,
55
            $this->wPrint/2,
56
            3,
57
            $texto,
58
            $aFont,
59
            'T',
60
            'L',
61
            false,
62
            '',
63
            false
64
        );
65
        $texto = number_format((float) $bruto, 2, ',', '.');
66
        $y2 = $this->pdf->textBox(
67
            $this->margem+$this->wPrint/2,
68
            $y+$y1,
69
            $this->wPrint/2,
70
            3,
71
            $texto,
72
            $aFont,
73
            'T',
74
            'R',
75
            false,
76
            '',
77
            false
78
        );
79
        
80
        $texto = "Desconto R$";
81
        $this->pdf->textBox(
82
            $this->margem,
83
            $y+$y1+$y2,
84
            $this->wPrint/2,
85
            3,
86
            $texto,
87
            $aFont,
88
            'T',
89
            'L',
90
            false,
91
            '',
92
            false
93
        );
94
        $texto = number_format((float) $desconto, 2, ',', '.');
95
        $y3 = $this->pdf->textBox(
96
            $this->margem+$this->wPrint/2,
97
            $y+$y1+$y2,
98
            $this->wPrint/2,
99
            3,
100
            $texto,
101
            $aFont,
102
            'T',
103
            'R',
104
            false,
105
            '',
106
            false
107
        );
108
        $fsize = 10;
109
        if ($this->paperwidth < 70) {
0 ignored issues
show
Bug introduced by
The property paperwidth does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
110
            $fsize = 8;
111
        }
112
        $aFont = ['font'=> $this->fontePadrao, 'size' => $fsize, 'style' => 'B'];
113
        $texto = "Valor a Pagar R$";
114
        $this->pdf->textBox(
115
            $this->margem,
116
            $y+$y1+$y2+$y3,
117
            $this->wPrint/2,
118
            3,
119
            $texto,
120
            $aFont,
121
            'T',
122
            'L',
123
            false,
124
            '',
125
            false
126
        );
127
        $texto = number_format((float) $valor, 2, ',', '.');
128
        $y4 = $this->pdf->textBox(
0 ignored issues
show
Unused Code introduced by
$y4 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
129
            $this->margem+$this->wPrint/2,
130
            $y+$y1+$y2+$y3,
131
            $this->wPrint/2,
132
            3,
133
            $texto,
134
            $aFont,
135
            'T',
136
            'R',
137
            false,
138
            '',
139
            false
140
        );
141
        
142
        $this->pdf->dashedHLine($this->margem, $this->bloco4H+$y, $this->wPrint, 0.1, 30);
143
        return $this->bloco4H + $y;
144
    }
145
}
146