Completed
Push — master ( 32113b...7fe95f )
by Roberto
03:20 queued 11s
created

Daevento::body()   B

Complexity

Conditions 7
Paths 14

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
nc 14
nop 2
dl 0
loc 45
ccs 0
cts 43
cp 0
crap 56
rs 8.2666
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\CTe;
4
5
/**
6
 * Classe para geração do envento do CTe em PDF
7
 * NOTA: Este documento não está NORMALIZADO, nem é requerido pela SEFAZ
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @name      Daevento.php
12
 * @copyright 2009-2019 NFePHP
13
 * @license   http://www.gnu.org/licenses/lgpl.html GNU/LGPL v.3
14
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
15
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
16
 */
17
18
use Exception;
19
use NFePHP\DA\Legacy\Dom;
20
use NFePHP\DA\Legacy\Pdf;
21
use NFePHP\DA\Common\DaCommon;
22
23
class Daevento extends DaCommon
24
{
25
    public $chCTe;
26
    protected $yDados = 0;
27
28
    protected $xml;
29
    protected $errMsg = '';
30
    protected $errStatus = false;
31
    protected $destino = 'I';
32
    protected $pdfDir = '';
33
    protected $version = '0.1.1';
34
    protected $wCanhoto;
35
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
36
37
    protected $id;
38
    protected $dadosEmitente = array();
39
    private $dom;
40
    private $procEventoCTe;
41
    private $evento;
42
    private $infEvento;
43
    private $retEvento;
44
    private $rinfEvento;
45
    protected $tpAmb;
46
    protected $cOrgao;
47
    protected $infCorrecao;
48
    protected $xCondUso;
49
    protected $dhEvento;
50
    protected $cStat;
51
    protected $xMotivo;
52
    protected $xJust;
53
    protected $CNPJDest = '';
54
    protected $CPFDest = '';
55
    protected $dhRegEvento;
56
    protected $nProt;
57
    protected $tpEvento;
58
    protected $creditos;
59
60
61
    /**
62
     * __construct
63
     *
64
     * @param string $xml Arquivo XML (diretório ou string)
65
     * @param array $dadosEmitente Dados do endereço do emitente
66
     */
67
    public function __construct($xml, $dadosEmitente)
68
    {
69
        $this->dadosEmitente = $dadosEmitente;
70
        $this->loadDoc($xml);
71
    }
72
73
    protected function loadDoc($xml)
74
    {
75
        $this->dom = new \DomDocument;
76
        $this->dom->loadXML($xml);
77
        $this->procEventoCTe = $this->dom->getElementsByTagName("procEventoCTe")->item(0);
78
        $this->evento = $this->dom->getElementsByTagName("eventoCTe")->item(0);
79
        $this->infEvento = $this->evento->getElementsByTagName("infEvento")->item(0);
80
        $this->retEvento = $this->dom->getElementsByTagName("retEventoCTe")->item(0);
81
        $this->rinfEvento = $this->retEvento->getElementsByTagName("infEvento")->item(0);
82
        $this->tpEvento = $this->infEvento->getElementsByTagName("tpEvento")->item(0)->nodeValue;
83
        if (!in_array($this->tpEvento, array('110110', '110111'))) {
84
            $this->errMsg = 'Evento não implementado ' . $this->tpEvento . ' !!';
85
            $this->errStatus = true;
86
            return false;
87
        }
88
        $this->id = str_replace('ID', '', $this->infEvento->getAttribute("Id"));
89
        $this->chCTe = $this->infEvento->getElementsByTagName("chCTe")->item(0)->nodeValue;
90
        $this->dadosEmitente['CNPJ'] = substr($this->chCTe, 6, 14);
91
        $this->tpAmb = $this->infEvento->getElementsByTagName("tpAmb")->item(0)->nodeValue;
92
        $this->cOrgao = $this->infEvento->getElementsByTagName("cOrgao")->item(0)->nodeValue;
93
        $this->infCorrecao = $this->infEvento->getElementsByTagName("infCorrecao");
94
        $this->xCondUso = $this->infEvento->getElementsByTagName("xCondUso")->item(0);
95
        $this->xCondUso = (empty($this->xCondUso) ? '' : $this->xCondUso->nodeValue);
96
        $this->xJust = $this->infEvento->getElementsByTagName("xJust")->item(0);
97
        $this->xJust = (empty($this->xJust) ? '' : $this->xJust->nodeValue);
98
        $this->dhEvento = $this->infEvento->getElementsByTagName("dhEvento")->item(0)->nodeValue;
99
        $this->cStat = $this->rinfEvento->getElementsByTagName("cStat")->item(0)->nodeValue;
100
        $this->xMotivo = $this->rinfEvento->getElementsByTagName("xMotivo")->item(0)->nodeValue;
101
        $this->CNPJDest = !empty($this->rinfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue) ?
102
            $this->rinfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue : '';
103
        $this->CPFDest = !empty($this->rinfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue) ?
104
            $this->rinfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue : '';
105
        $this->dhRegEvento = $this->rinfEvento->getElementsByTagName("dhRegEvento")->item(0)->nodeValue;
106
        $this->nProt = $this->rinfEvento->getElementsByTagName("nProt")->item(0)->nodeValue;
107
    }
108
109
110
    /**
111
     * monta
112
     * Esta função monta a DAEventoCTe conforme as informações fornecidas para a classe
113
     * durante sua construção.
114
     * A definição de margens e posições iniciais para a impressão são estabelecidas no
115
     * pelo conteúdo da funçao e podem ser modificados.
116
     *
117
     * @param string $logo base64 da logomarca
118
     * @return string O ID do evento extraido do arquivo XML
119
     */
120
    protected function monta(
121
        $logo = ''
122
    ) {
123
        if (!empty($logo)) {
124
            $this->logomarca = $this->adjustImage($logo);
125
        }
126
        if (empty($this->orientacao)) {
127
            $this->orientacao = 'P';
128
        }
129
        // margens do PDF
130
        $margSup = $this->margsup;
131
        $margEsq = $this->margesq;
132
        $margDir = $this->margesq;
133
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
0 ignored issues
show
Bug introduced by
It seems like $this->papel can also be of type array; however, NFePHP\DA\Legacy\Pdf::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
134
        if ($this->orientacao == 'P') {
135
            // posição inicial do relatorio
136
            $xInic = 1;
137
            $yInic = 1;
138
            if ($this->papel == 'A4') { //A4 210x297mm
139
                $maxW = 210;
140
                $maxH = 297;
141
            }
142
        } else {
143
            // posição inicial do relatorio
144
            $xInic = 5;
145
            $yInic = 5;
146
            if ($papel == 'A4') {
0 ignored issues
show
Bug introduced by
The variable $papel does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
147
                //A4 210x297mm
148
                $maxH = 210;
149
                $maxW = 297;
150
            }
151
        }
152
        //largura imprimivel em mm
153
        $this->wPrint = $maxW - ($margEsq + $xInic);
0 ignored issues
show
Bug introduced by
The variable $maxW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The property $wPrint was declared of type double, but $maxW - ($margEsq + $xInic) is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
154
        //comprimento imprimivel em mm
155
        $this->hPrint = $maxH - ($margSup + $yInic);
0 ignored issues
show
Bug introduced by
The variable $maxH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The property $hPrint was declared of type double, but $maxH - ($margSup + $yInic) is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
156
        // estabelece contagem de paginas
157
        $this->pdf->aliasNbPages();
158
        // fixa as margens
159
        $this->pdf->setMargins($margEsq, $margSup, $margDir);
160
        $this->pdf->setDrawColor(0, 0, 0);
161
        $this->pdf->setFillColor(255, 255, 255);
162
        // inicia o documento
163
        $this->pdf->open();
164
        // adiciona a primeira página
165
        $this->pdf->addPage($this->orientacao, $this->papel);
0 ignored issues
show
Bug introduced by
It seems like $this->papel can also be of type array; however, NFePHP\DA\Legacy\FPDF\Fpdf::addPage() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
166
        $this->pdf->setLineWidth(0.1);
167
        $this->pdf->setTextColor(0, 0, 0);
168
        //montagem da página
169
        $pag = 1;
170
        $x = $xInic;
171
        $y = $yInic;
172
        //coloca o cabeçalho
173
        $y = $this->header($x, $y, $pag);
174
        //coloca os dados da CCe
175
        $y = $this->body($x, $y + 15);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->body($x, $y + 15) (which targets NFePHP\DA\CTe\Daevento::body()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
176
        //coloca os dados da CCe
177
        $y = $this->footer($x, $y + $this->hPrint - 20);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->footer($x, $y + $this->hPrint - 20) (which targets NFePHP\DA\CTe\Daevento::footer()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y 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...
178
        //retorna o ID do evento
179
        return $this->id;
180
    }
181
182
    /**
183
     * header
184
     * @param integer $x
185
     * @param integer $y
186
     * @param integer $pag
187
     * @return integer
188
     */
189
    private function header(
190
        $x,
191
        $y,
192
        $pag
0 ignored issues
show
Unused Code introduced by
The parameter $pag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
193
    ) {
194
        $oldX = $x;
195
        $oldY = $y;
196
        $maxW = $this->wPrint;
197
        //####################################################################################
198
        //coluna esquerda identificação do emitente
199
        $w = round($maxW * 0.41, 0);// 80;
200
        if ($this->orientacao == 'P') {
201
            $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
202
        } else {
203
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
204
        }
205
        $w1 = $w;
0 ignored issues
show
Unused Code introduced by
$w1 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...
206
        $h = 32;
207
        $oldY += $h;
208
        $this->pdf->textBox($x, $y, $w, $h);
209
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
210
        $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
211
        if (!empty($this->logomarca)) {
212
            $logoInfo = getimagesize($this->logomarca);
213
            //largura da imagem em mm
214
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
215
            //altura da imagem em mm
216
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
217
            if ($this->logoAlign == 'L') {
218
                $nImgW = round($w / 3, 0);
219
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
220
                $xImg = $x + 1;
221
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
222
                //estabelecer posições do texto
223
                $x1 = round($xImg + $nImgW + 1, 0);
224
                $y1 = round($h / 3 + $y, 0);
225
                $tw = round(2 * $w / 3, 0);
226
            }
227
            if ($this->logoAlign == 'C') {
228
                $nImgH = round($h / 3, 0);
229
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
230
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
231
                $yImg = $y + 3;
232
                $x1 = $x;
233
                $y1 = round($yImg + $nImgH + 1, 0);
234
                $tw = $w;
235
            }
236
            if ($this->logoAlign == 'R') {
237
                $nImgW = round($w / 3, 0);
238
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
239
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
240
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
241
                $x1 = $x;
242
                $y1 = round($h / 3 + $y, 0);
243
                $tw = round(2 * $w / 3, 0);
244
            }
245
            $this->pdf->image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, 'jpeg');
0 ignored issues
show
Bug introduced by
The variable $xImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $yImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
246
        } else {
247
            $x1 = $x;
248
            $y1 = round($h / 3 + $y, 0);
249
            $tw = $w;
250
        }
251
        //Nome emitente
252
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
253
        $texto = (isset($this->dadosEmitente['razao']) ? $this->dadosEmitente['razao'] : '');
254
        $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $tw does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
255
        //endereço
256
        $y1 = $y1 + 6;
257
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
258
        $lgr = (isset($this->dadosEmitente['logradouro']) ? $this->dadosEmitente['logradouro'] : '');
259
        $nro = (isset($this->dadosEmitente['numero']) ? $this->dadosEmitente['numero'] : '');
260
        $cpl = (isset($this->dadosEmitente['complemento']) ? $this->dadosEmitente['complemento'] : '');
261
        $bairro = (isset($this->dadosEmitente['bairro']) ? $this->dadosEmitente['bairro'] : '');
262
        $CEP = (isset($this->dadosEmitente['CEP']) ? $this->dadosEmitente['CEP'] : '');
263
        $CEP = $this->formatField($CEP, "#####-###");
264
        $mun = (isset($this->dadosEmitente['municipio']) ? $this->dadosEmitente['municipio'] : '');
265
        $UF = (isset($this->dadosEmitente['UF']) ? $this->dadosEmitente['UF'] : '');
266
        $fone = (isset($this->dadosEmitente['telefone']) ? $this->dadosEmitente['telefone'] : '');
267
        $email = (isset($this->dadosEmitente['email']) ? $this->dadosEmitente['email'] : '');
268
        $foneLen = strlen($fone);
269
        if ($foneLen > 0) {
270
            $fone2 = substr($fone, 0, $foneLen - 4);
271
            $fone1 = substr($fone, 0, $foneLen - 8);
272
            $fone = '(' . $fone1 . ') ' . substr($fone2, -4) . '-' . substr($fone, -4);
273
        } else {
274
            $fone = '';
275
        }
276
        if ($email != '') {
277
            $email = 'Email: ' . $email;
278
        }
279
        $texto = "";
280
        $tmp_txt = trim(($lgr != '' ? "$lgr, " : '') . ($nro != 0 ? $nro : "SN") . ($cpl != '' ? " - $cpl" : ''));
281
        $tmp_txt = ($tmp_txt == 'SN' ? '' : $tmp_txt);
282
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
283
        $tmp_txt = trim($bairro . ($bairro != '' && $CEP != '' ? " - " : '') . $CEP);
284
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
285
        $tmp_txt = $mun;
286
        $tmp_txt .= ($tmp_txt != '' && $UF != '' ? " - " : '') . $UF;
287
        $tmp_txt .= ($tmp_txt != '' && $fone != '' ? " - " : '') . $fone;
288
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
289
        $tmp_txt = $email;
290
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
291
        $this->pdf->textBox($x1, $y1 - 2, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
292
        //##################################################
293
        $w2 = round($maxW - $w, 0);
294
        $x += $w;
295
        $this->pdf->textBox($x, $y, $w2, $h);
296
        $y1 = $y + $h;
297
        $aFont = array('font' => $this->fontePadrao, 'size' => 16, 'style' => 'B');
298
        if ($this->tpEvento == '110110') {
299
            $texto = 'Representação Gráfica de CCe';
300
        } else {
301
            $texto = 'Representação Gráfica de Evento';
302
        }
303
        $this->pdf->textBox($x, $y + 2, $w2, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
304
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'I');
305
        if ($this->tpEvento == '110110') {
306
            $texto = '(Carta de Correção Eletrônica)';
307
        } elseif ($this->tpEvento == '110111') {
308
            $texto = '(Cancelamento de CTe)';
309
        }
310
        $this->pdf->textBox($x, $y + 7, $w2, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
311
        $texto = 'ID do Evento: ' . $this->id;
312
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
313
        $this->pdf->textBox($x, $y + 15, $w2, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
314
        $tsHora = $this->toTimestamp($this->dhEvento);
315
        $texto = 'Criado em : ' . date('d/m/Y   H:i:s', $tsHora);
316
        $this->pdf->textBox($x, $y + 20, $w2, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
317
        $tsHora = $this->toTimestamp($this->dhRegEvento);
318
        $texto = 'Prococolo: ' . $this->nProt . '  -  Registrado na SEFAZ em: ' . date('d/m/Y   H:i:s', $tsHora);
319
        $this->pdf->textBox($x, $y + 25, $w2, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
320
        //####################################################
321
        $x = $oldX;
322
        $this->pdf->textBox($x, $y1, $maxW, 40);
323
        $sY = $y1 + 40;
324
        if ($this->tpEvento == '110110') {
325
            $texto = 'De acordo com as determinações legais vigentes, vimos por meio '
326
                . 'desta comunicar-lhe que o Conhecimento de Transporte, abaixo referenciado, '
327
                . 'contêm irregularidades que estão destacadas e suas respectivas '
328
                . 'correções, solicitamos que sejam aplicadas essas correções ao '
329
                . 'executar seus lançamentos fiscais.';
330
        } elseif ($this->tpEvento == '110111') {
331
            $texto = 'De acordo com as determinações legais vigentes, vimos por meio '
332
                . 'desta comunicar-lhe que o  Conhecimento de Transporte, abaixo referenciado, está '
333
                . 'cancelado, solicitamos que sejam aplicadas essas correções ao '
334
                . 'executar seus lançamentos fiscais.';
335
        }
336
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
337
        $this->pdf->textBox($x + 5, $y1, $maxW - 5, 20, $texto, $aFont, 'T', 'L', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
338
        //############################################
339
        $x = $oldX;
340
        $y = $y1;
341
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
342
        $numNF = substr($this->chCTe, 25, 9);
343
        $serie = substr($this->chCTe, 22, 3);
344
        $numNF = $this->formatField($numNF, "###.###.###");
345
        $texto = "Conhecimento: " . $numNF . '  -   Série: ' . $serie;
346
        $this->pdf->textBox($x + 2, $y + 19, $w2, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
347
        $bW = 87;
348
        $bH = 15;
349
        $x = 55;
350
        $y = $y1 + 13;
351
        $w = $maxW;
352
        $this->pdf->setFillColor(0, 0, 0);
353
        $this->pdf->code128($x + (($w - $bW) / 2), $y + 2, $this->chCTe, $bW, $bH);
354
        $this->pdf->setFillColor(255, 255, 255);
355
        $y1 = $y + 2 + $bH;
356
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
357
        $texto = $this->formatField($this->chCTe, $this->formatoChave);
358
        $this->pdf->textBox($x, $y1, $w - 2, $h, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
359
        $retVal = $sY + 2;
360
        if ($this->tpEvento == '110110') {
361
            $x = $oldX;
362
            $this->pdf->textBox($x, $sY, $maxW, 15);
363
            $texto = $this->xCondUso;
364
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
365
            $this->pdf->textBox($x + 2, $sY + 2, $maxW - 2, 15, $texto, $aFont, 'T', 'L', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
366
            $retVal = $sY + 2;
367
        }
368
        if ($this->tpAmb != 1) {
369
            $x = 10;
370
            if ($this->orientacao == 'P') {
371
                $y = round($this->hPrint * 2 / 3, 0);
372
            } else {
373
                $y = round($this->hPrint / 2, 0);
374
            }
375
            $h = 5;
376
            $w = $maxW - (2 * $x);
377
            $this->pdf->setTextColor(90, 90, 90);
378
            $texto = "SEM VALOR FISCAL";
379
            $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
380
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
381
            $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
382
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
383
            $this->pdf->textBox($x, $y + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
384
            $this->pdf->setTextColor(0, 0, 0);
385
        }
386
        return $retVal;
387
    }
388
389
    /**
390
     * body
391
     * @param integer $x
392
     * @param integer $y
393
     */
394
    private function body($x, $y)
395
    {
396
        $maxW = $this->wPrint;
397
        if ($this->tpEvento == '110110') {
398
            $texto = 'CORREÇÕES A SEREM CONSIDERADAS';
399
        } else {
400
            $texto = 'JUSTIFICATIVA DO CANCELAMENTO';
401
        }
402
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
403
        $this->pdf->textBox($x, $y, $maxW, 5, $texto, $aFont, 'T', 'L', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
404
        $y += 5;
405
        $this->pdf->textBox($x, $y, $maxW, 190);
406
        if ($this->tpEvento == '110110') {
407
            $this->pdf->textBox($x, $y, $maxW = ($maxW / 5), 5, "Grupo", $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
408
            $this->pdf->textBox($x = $maxW, $y, $maxW, 5, "Campo", $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
409
            $this->pdf->textBox($x = ($maxW * 2), $y, $maxW, 5, "Número", $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
410
            $this->pdf->textBox($x = ($maxW * 3), $y, ($this->wPrint - $x), 5, "Valor", $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
411
412
            $aFont = array('font' => $this->fontePadrao, 'size' => 9, 'style' => '');
413
            $i = 0;
414
            $numlinhas = 1;
415
            while ($i < $this->infCorrecao->length) {
416
                $x = 0;
417
                $y = $numlinhas == 1 ? ($y + 5) : ($y + (5 * $numlinhas));
418
                $maxW = $this->wPrint;
419
                $grupo = $this->infCorrecao->item($i)->getElementsByTagName('grupoAlterado')->item(0)->nodeValue;
420
                $campo = $this->infCorrecao->item($i)->getElementsByTagName('campoAlterado')->item(0)->nodeValue;
421
                $numero = 1;
422
                if (!empty($this->infCorrecao->item($i)->getElementsByTagName('nroItemAlterado')->item(0))) {
423
                    $numero =$this->infCorrecao->item($i)->getElementsByTagName('nroItemAlterado')->item(0)->nodeValue;
424
                }
425
                $valor = $this->infCorrecao->item($i)->getElementsByTagName('valorAlterado')->item(0)->nodeValue;
426
427
                $i++;
428
                $this->pdf->textBox($x, $y, $maxW = ($maxW / 5), 5, $grupo, $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
429
                $this->pdf->textBox($x = $maxW, $y, $maxW, 5, $campo, $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
430
                $this->pdf->textBox($x = ($maxW * 2), $y, $maxW, 5, $numero, $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
431
                $this->pdf->textBox($x = ($maxW * 3), $y, ($this->wPrint - $x), 5, $valor, $aFont, 'T', 'C', 0);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
432
            }
433
        } elseif ($this->tpEvento == '110111') {
434
            $texto = $this->xJust;
435
            $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
436
            $this->pdf->textBox($x + 2, $y + 2, $maxW - 2, 150, $texto, $aFont, 'T', 'L', 0, '', false);
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
437
        }
438
    }
439
440
    /**
441
     * footer
442
     * @param integer $x
443
     * @param integer $y
444
     */
445
    private function footer($x, $y)
446
    {
447
        $w = $this->wPrint;
448
        if ($this->tpEvento == '110110') {
449
            $texto = "Este documento é uma representação gráfica da CCe e foi "
450
                . "impresso apenas para sua informação e não possue validade fiscal."
451
                . "\n A CCe deve ser recebida e mantida em arquivo eletrônico XML e "
452
                . "pode ser consultada através dos Portais das SEFAZ.";
453
        } elseif ($this->tpEvento == '110111') {
454
            $texto = "Este documento é uma representação gráfica do evento de CTe e foi "
455
                . "impresso apenas para sua informação e não possue validade fiscal."
456
                . "\n O Evento deve ser recebido e mantido em arquivo eletrônico XML e "
457
                . "pode ser consultada através dos Portais das SEFAZ.";
458
        }
459
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'I');
460
        $this->pdf->textBox($x, $y, $w, 20, $texto, $aFont, 'T', 'C', 0, '', false);
0 ignored issues
show
Bug introduced by
The variable $texto does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
461
        $y = $this->hPrint - 4;
462
        $texto = "Impresso em  " . date('d/m/Y   H:i:s') . ' ' . $this->creditos;
463
        $w = $this->wPrint - 4;
464
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
465
        $this->pdf->textBox($x, $y, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
466
        $texto = $this->powered ? "Powered by NFePHP®" : '';
467
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
468
        $this->pdf->textBox($x, $y, $w, 4, $texto, $aFont, 'T', 'R', 0, 'http://www.nfephp.org');
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a boolean.

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...
469
    }
470
}
471