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

TraitBlocoIII::calculateHeightItens()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 5
nop 1
dl 0
loc 49
ccs 0
cts 47
cp 0
crap 42
rs 8.4905
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\NFe\Traits;
4
5
/**
6
 * Bloco itens da NFe
7
 */
8
trait TraitBlocoIII
9
{
10
    protected function blocoIII($y)
11
    {
12
        if ($this->flagResume) {
0 ignored issues
show
Bug introduced by
The property flagResume 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
            return $y;
14
        }
15
        
16
        $matrix = [0.12, $this->descPercent, 0.08, 0.09, 0.156, 0.156];
0 ignored issues
show
Bug introduced by
The property descPercent 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...
17
        
18
        //$aFont = ['font'=> $this->fontePadrao, 'size' => 7, 'style' => ''];
19
        //$this->pdf->textBox($this->margem, $y, $this->wPrint, $this->bloco3H, '', $aFont, 'T', 'C', true, '', false);
20
        
21
        $fsize = 7;
22
        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...
23
            $fsize = 5;
24
        }
25
        $aFont = ['font'=> $this->fontePadrao, 'size' => $fsize, '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...
26
        
27
        $texto = "Código";
28
        $x = $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...
29
        $this->pdf->textBox($x, $y, ($this->wPrint * $matrix[0]), 3, $texto, $aFont, 'T', 'L', false, '', true);
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...
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...
30
        
31
        $texto = "Descrição";
32
        $x1 = $x + ($this->wPrint * $matrix[0]);
33
        $this->pdf->textBox($x1, $y, ($this->wPrint * $matrix[1]), 3, $texto, $aFont, 'T', 'L', false, '', true);
34
        
35
        $texto = "Qtde";
36
        $x2 = $x1 + ($this->wPrint * $matrix[1]);
37
        $this->pdf->textBox($x2, $y, ($this->wPrint * $matrix[2]), 3, $texto, $aFont, 'T', 'C', false, '', true);
38
        
39
        $texto = "UN";
40
        $x3 = $x2 + ($this->wPrint * $matrix[2]);
41
        $this->pdf->textBox($x3, $y, ($this->wPrint * $matrix[3]), 3, $texto, $aFont, 'T', 'C', false, '', true);
42
        
43
        $texto = "Vl Unit";
44
        $x4 = $x3 + ($this->wPrint * $matrix[3]);
45
        $this->pdf->textBox($x4, $y, ($this->wPrint * $matrix[4]), 3, $texto, $aFont, 'T', 'C', false, '', true);
46
        
47
        $texto = "Vl Total";
48
        $x5 = $x4 + ($this->wPrint * $matrix[4]);
49
        $y1 = $this->pdf->textBox($x5, $y, ($this->wPrint * $matrix[5]), 3, $texto, $aFont, 'T', 'R', false, '', true);
50
        
51
        $y2 = $y + $y1;
52
        if ($this->det->length == 0) {
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...
53
        } else {
54
            foreach ($this->itens as $item) {
0 ignored issues
show
Bug introduced by
The property itens 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...
55
                $it = (object) $item;
56
                $this->pdf->textBox(
57
                    $x,
58
                    $y2,
59
                    ($this->wPrint * $matrix[0]),
60
                    $it->height,
61
                    $it->codigo,
62
                    $aFont,
63
                    'T',
64
                    'L',
65
                    false,
66
                    '',
67
                    true
68
                );
69
                $this->pdf->textBox(
70
                    $x1,
71
                    $y2,
72
                    ($this->wPrint * $matrix[1]),
73
                    $it->height,
74
                    $it->desc,
75
                    $aFont,
76
                    'T',
77
                    'L',
78
                    false,
79
                    '',
80
                    false
81
                );
82
                $this->pdf->textBox(
83
                    $x2,
84
                    $y2,
85
                    ($this->wPrint * $matrix[2]),
86
                    $it->height,
87
                    $it->qtd,
88
                    $aFont,
89
                    'T',
90
                    'R',
91
                    false,
92
                    '',
93
                    true
94
                );
95
                $this->pdf->textBox(
96
                    $x3,
97
                    $y2,
98
                    ($this->wPrint * $matrix[3]),
99
                    $it->height,
100
                    $it->un,
101
                    $aFont,
102
                    'T',
103
                    'C',
104
                    false,
105
                    '',
106
                    true
107
                );
108
                $this->pdf->textBox(
109
                    $x4,
110
                    $y2,
111
                    ($this->wPrint * $matrix[4]),
112
                    $it->height,
113
                    $it->vunit,
114
                    $aFont,
115
                    'T',
116
                    'R',
117
                    false,
118
                    '',
119
                    true
120
                );
121
                $this->pdf->textBox(
122
                    $x5,
123
                    $y2,
124
                    ($this->wPrint * $matrix[5]),
125
                    $it->height,
126
                    $it->valor,
127
                    $aFont,
128
                    'T',
129
                    'R',
130
                    false,
131
                    '',
132
                    true
133
                );
134
                $y2 += $it->height;
135
            }
136
        }
137
        $this->pdf->dashedHLine($this->margem, $this->bloco3H+$y, $this->wPrint, 0.1, 30);
0 ignored issues
show
Bug introduced by
The property bloco3H 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...
138
        return $this->bloco3H + $y;
139
    }
140
    
141
    protected function calculateHeightItens($descriptionWidth)
142
    {
143
        if ($this->flagResume) {
144
            return 0;
145
        }
146
        $fsize = 7;
147
        if ($this->paperwidth < 70) {
148
            $fsize = 5;
149
        }
150
        $hfont = (imagefontheight($fsize)/72)*15;
151
        $aFont = ['font'=> $this->fontePadrao, 'size' => $fsize, 'style' => ''];
0 ignored issues
show
Unused Code introduced by
$aFont 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...
152
        $htot = 0;
153
        if ($this->det->length == 0) {
154
        } else {
155
            foreach ($this->det as $item) {
156
                $prod = $item->getElementsByTagName("prod")->item(0);
157
                $cProd      = $this->getTagValue($prod, "cProd");
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...
158
                $xProd      = substr($this->getTagValue($prod, "xProd"), 1, 45);
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...
159
                $qCom       = number_format($this->getTagValue($prod, "qCom"), 2, ",", ".");
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...
160
                $uCom       = $this->getTagValue($prod, "uCom");
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...
161
                $vUnCom     = number_format($this->getTagValue($prod, "vUnCom"), 2, ",", ".");
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...
162
                $vProd      = number_format($this->getTagValue($prod, "vProd"), 2, ",", ".");
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...
163
                
164
                $tempPDF = new \NFePHP\DA\Legacy\Pdf(); // cria uma instancia temporaria da class pdf
165
                $tempPDF->setFont($this->fontePadrao, '', $fsize); // seta a font do PDF
166
                
167
                $n = $tempPDF->wordWrap($xProd, $descriptionWidth);
0 ignored issues
show
Documentation introduced by
$xProd is of type string, but the function expects a object<NFePHP\DA\Legacy\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
168
                $limit = 45;
169
                while ($n > 2) {
170
                    $limit -= 1;
171
                    $xProd = substr($this->getTagValue($prod, "xProd"), 0, $limit);
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...
172
                    $p = $xProd;
173
                    $n = $tempPDF->wordWrap($p, $descriptionWidth);
0 ignored issues
show
Documentation introduced by
$p is of type string, but the function expects a object<NFePHP\DA\Legacy\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
174
                }
175
                $h = ($hfont * $n);
176
                $this->itens[] = [
177
                    "codigo" => $cProd,
178
                    "desc" => $xProd,
179
                    "qtd" => $qCom,
180
                    "un" => $uCom,
181
                    "vunit" => $vUnCom,
182
                    "valor" => $vProd,
183
                    "height" => $h
184
                ];
185
                $htot += $h;
186
            }
187
        }
188
        return $htot+2;
189
    }
190
}
191