Completed
Push — master ( e40ab2...2d4eb1 )
by Roberto
05:08 queued 12s
created

Daevento::header()   F

Complexity

Conditions 44
Paths > 20000

Size

Total Lines 199

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1980

Importance

Changes 0
Metric Value
cc 44
nc 4294967295
nop 3
dl 0
loc 199
ccs 0
cts 189
cp 0
crap 1980
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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\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 $xCorrecao;
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 ' . $tpEvento . ' !!';
0 ignored issues
show
Bug introduced by
The variable $tpEvento 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...
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->xCorrecao = $this->infEvento->getElementsByTagName("xCorrecao")->item(0);
94
        $this->xCorrecao = (empty($this->xCorrecao) ? '' : $this->xCorrecao->nodeValue);
95
        $this->xCondUso = $this->infEvento->getElementsByTagName("xCondUso")->item(0);
96
        $this->xCondUso = (empty($this->xCondUso) ? '' : $this->xCondUso->nodeValue);
97
        $this->xJust = $this->infEvento->getElementsByTagName("xJust")->item(0);
98
        $this->xJust = (empty($this->xJust) ? '' : $this->xJust->nodeValue);
99
        $this->dhEvento = $this->infEvento->getElementsByTagName("dhEvento")->item(0)->nodeValue;
100
        $this->cStat = $this->rinfEvento->getElementsByTagName("cStat")->item(0)->nodeValue;
101
        $this->xMotivo = $this->rinfEvento->getElementsByTagName("xMotivo")->item(0)->nodeValue;
102
        $this->CNPJDest = !empty($this->rinfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue) ?
103
            $this->rinfEvento->getElementsByTagName("CNPJDest")->item(0)->nodeValue : '';
104
        $this->CPFDest = !empty($this->rinfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue) ?
105
            $this->rinfEvento->getElementsByTagName("CPFDest")->item(0)->nodeValue : '';
106
        $this->dhRegEvento = $this->rinfEvento->getElementsByTagName("dhRegEvento")->item(0)->nodeValue;
107
        $this->nProt = $this->rinfEvento->getElementsByTagName("nProt")->item(0)->nodeValue;
108
    }
109
110
111
    /**
112
     * monta
113
     * Esta função monta a DAEventoCTe conforme as informações fornecidas para a classe
114
     * durante sua construção.
115
     * A definição de margens e posições iniciais para a impressão são estabelecidas no
116
     * pelo conteúdo da funçao e podem ser modificados.
117
     *
118
     * @param string $logo base64 da logomarca
119
     * @return string O ID do evento extraido do arquivo XML
120
     */
121
    protected function monta(
122
        $logo = ''
123
    ) {
124
        if (!empty($logo)) {
125
            $this->logomarca = $this->adjustImage($logo);
126
        }
127
        if (empty($this->orientacao)) {
128
            $this->orientacao = 'P';
129
        }
130
        // margens do PDF
131
        $margSup = $this->margsup;
132
        $margEsq = $this->margesq;
133
        $margDir = $this->margesq;
134
        $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...
135
        if ($this->orientacao == 'P') {
136
            // posição inicial do relatorio
137
            $xInic = 1;
138
            $yInic = 1;
139
            if ($this->papel == 'A4') { //A4 210x297mm
140
                $maxW = 210;
141
                $maxH = 297;
142
            }
143
        } else {
144
            // posição inicial do relatorio
145
            $xInic = 5;
146
            $yInic = 5;
147
            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...
148
                //A4 210x297mm
149
                $maxH = 210;
150
                $maxW = 297;
151
            }
152
        }
153
        //largura imprimivel em mm
154
        $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...
155
        //comprimento imprimivel em mm
156
        $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...
157
        // estabelece contagem de paginas
158
        $this->pdf->aliasNbPages();
159
        // fixa as margens
160
        $this->pdf->setMargins($margEsq, $margSup, $margDir);
161
        $this->pdf->setDrawColor(0, 0, 0);
162
        $this->pdf->setFillColor(255, 255, 255);
163
        // inicia o documento
164
        $this->pdf->open();
165
        // adiciona a primeira página
166
        $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...
167
        $this->pdf->setLineWidth(0.1);
168
        $this->pdf->setTextColor(0, 0, 0);
169
        //montagem da página
170
        $pag = 1;
171
        $x = $xInic;
172
        $y = $yInic;
173
        //coloca o cabeçalho
174
        $y = $this->header($x, $y, $pag);
175
        //coloca os dados da CCe
176
        $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...
177
        //coloca os dados da CCe
178
        $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...
179
        //retorna o ID do evento
180
        return $this->id;
181
    }
182
183
    /**
184
     * header
185
     * @param integer $x
186
     * @param integer $y
187
     * @param integer $pag
188
     * @return integer
189
     */
190
    private function header(
191
        $x,
192
        $y,
193
        $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...
194
    ) {
195
        $oldX = $x;
196
        $oldY = $y;
197
        $maxW = $this->wPrint;
198
        //####################################################################################
199
        //coluna esquerda identificação do emitente
200
        $w = round($maxW * 0.41, 0);// 80;
201
        if ($this->orientacao == 'P') {
202
            $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
203
        } else {
204
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
205
        }
206
        $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...
207
        $h = 32;
208
        $oldY += $h;
209
        $this->pdf->textBox($x, $y, $w, $h);
210
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
211
        $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...
212
        if (!empty($this->logomarca)) {
213
            $logoInfo = getimagesize($this->logomarca);
214
            //largura da imagem em mm
215
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
216
            //altura da imagem em mm
217
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
218
            if ($this->logoAlign == 'L') {
219
                $nImgW = round($w / 3, 0);
220
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
221
                $xImg = $x + 1;
222
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
223
                //estabelecer posições do texto
224
                $x1 = round($xImg + $nImgW + 1, 0);
225
                $y1 = round($h / 3 + $y, 0);
226
                $tw = round(2 * $w / 3, 0);
227
            }
228
            if ($this->logoAlign == 'C') {
229
                $nImgH = round($h / 3, 0);
230
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
231
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
232
                $yImg = $y + 3;
233
                $x1 = $x;
234
                $y1 = round($yImg + $nImgH + 1, 0);
235
                $tw = $w;
236
            }
237
            if ($this->logoAlign == 'R') {
238
                $nImgW = round($w / 3, 0);
239
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
240
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
241
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
242
                $x1 = $x;
243
                $y1 = round($h / 3 + $y, 0);
244
                $tw = round(2 * $w / 3, 0);
245
            }
246
            $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...
247
        } else {
248
            $x1 = $x;
249
            $y1 = round($h / 3 + $y, 0);
250
            $tw = $w;
251
        }
252
        //Nome emitente
253
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
254
        $texto = (isset($this->dadosEmitente['razao']) ? $this->dadosEmitente['razao'] : '');
255
        $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...
256
        //endereço
257
        $y1 = $y1 + 6;
258
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
259
        $lgr = (isset($this->dadosEmitente['logradouro']) ? $this->dadosEmitente['logradouro'] : '');
260
        $nro = (isset($this->dadosEmitente['numero']) ? $this->dadosEmitente['numero'] : '');
261
        $cpl = (isset($this->dadosEmitente['complemento']) ? $this->dadosEmitente['complemento'] : '');
262
        $bairro = (isset($this->dadosEmitente['bairro']) ? $this->dadosEmitente['bairro'] : '');
263
        $CEP = (isset($this->dadosEmitente['CEP']) ? $this->dadosEmitente['CEP'] : '');
264
        $CEP = $this->formatField($CEP, "#####-###");
265
        $mun = (isset($this->dadosEmitente['municipio']) ? $this->dadosEmitente['municipio'] : '');
266
        $UF = (isset($this->dadosEmitente['UF']) ? $this->dadosEmitente['UF'] : '');
267
        $fone = (isset($this->dadosEmitente['telefone']) ? $this->dadosEmitente['telefone'] : '');
268
        $email = (isset($this->dadosEmitente['email']) ? $this->dadosEmitente['email'] : '');
269
        $foneLen = strlen($fone);
270
        if ($foneLen > 0) {
271
            $fone2 = substr($fone, 0, $foneLen - 4);
272
            $fone1 = substr($fone, 0, $foneLen - 8);
273
            $fone = '(' . $fone1 . ') ' . substr($fone2, -4) . '-' . substr($fone, -4);
274
        } else {
275
            $fone = '';
276
        }
277
        if ($email != '') {
278
            $email = 'Email: ' . $email;
279
        }
280
        $texto = "";
281
        $tmp_txt = trim(($lgr != '' ? "$lgr, " : '') . ($nro != 0 ? $nro : "SN") . ($cpl != '' ? " - $cpl" : ''));
282
        $tmp_txt = ($tmp_txt == 'SN' ? '' : $tmp_txt);
283
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
284
        $tmp_txt = trim($bairro . ($bairro != '' && $CEP != '' ? " - " : '') . $CEP);
285
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
286
        $tmp_txt = $mun;
287
        $tmp_txt .= ($tmp_txt != '' && $UF != '' ? " - " : '') . $UF;
288
        $tmp_txt .= ($tmp_txt != '' && $fone != '' ? " - " : '') . $fone;
289
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
290
        $tmp_txt = $email;
291
        $texto .= ($texto != '' && $tmp_txt != '' ? "\n" : '') . $tmp_txt;
292
        $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...
293
        //##################################################
294
        $w2 = round($maxW - $w, 0);
295
        $x += $w;
296
        $this->pdf->textBox($x, $y, $w2, $h);
297
        $y1 = $y + $h;
298
        $aFont = array('font' => $this->fontePadrao, 'size' => 16, 'style' => 'B');
299
        if ($this->tpEvento == '110110') {
300
            $texto = 'Representação Gráfica de CCe';
301
        } else {
302
            $texto = 'Representação Gráfica de Evento';
303
        }
304
        $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...
305
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'I');
306
        if ($this->tpEvento == '110110') {
307
            $texto = '(Carta de Correção Eletrônica)';
308
        } elseif ($this->tpEvento == '110111') {
309
            $texto = '(Cancelamento de CTe)';
310
        }
311
        $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...
312
        $texto = 'ID do Evento: ' . $this->id;
313
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
314
        $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...
315
        $tsHora = $this->toTimestamp($this->dhEvento);
316
        $texto = 'Criado em : ' . date('d/m/Y   H:i:s', $tsHora);
317
        $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...
318
        $tsHora = $this->toTimestamp($this->dhRegEvento);
319
        $texto = 'Prococolo: ' . $this->nProt . '  -  Registrado na SEFAZ em: ' . date('d/m/Y   H:i:s', $tsHora);
320
        $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...
321
        //####################################################
322
        $x = $oldX;
323
        $this->pdf->textBox($x, $y1, $maxW, 40);
324
        $sY = $y1 + 40;
325
        if ($this->tpEvento == '110110') {
326
            $texto = 'De acordo com as determinações legais vigentes, vimos por meio '
327
                . 'desta comunicar-lhe que o Conhecimento de Transporte, abaixo referenciado, '
328
                . 'contêm irregularidades que estão destacadas e suas respectivas '
329
                . 'correções, solicitamos que sejam aplicadas essas correções ao '
330
                . 'executar seus lançamentos fiscais.';
331
        } elseif ($this->tpEvento == '110111') {
332
            $texto = 'De acordo com as determinações legais vigentes, vimos por meio '
333
                . 'desta comunicar-lhe que o  Conhecimento de Transporte, abaixo referenciado, está '
334
                . 'cancelado, solicitamos que sejam aplicadas essas correções ao '
335
                . 'executar seus lançamentos fiscais.';
336
        }
337
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
338
        $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...
339
        //############################################
340
        $x = $oldX;
341
        $y = $y1;
342
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
343
        $numNF = substr($this->chCTe, 25, 9);
344
        $serie = substr($this->chCTe, 22, 3);
345
        $numNF = $this->formatField($numNF, "###.###.###");
346
        $texto = "Conhecimento: " . $numNF . '  -   Série: ' . $serie;
347
        $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...
348
        $bW = 87;
349
        $bH = 15;
350
        $x = 55;
351
        $y = $y1 + 13;
352
        $w = $maxW;
353
        $this->pdf->setFillColor(0, 0, 0);
354
        $this->pdf->code128($x + (($w - $bW) / 2), $y + 2, $this->chCTe, $bW, $bH);
355
        $this->pdf->setFillColor(255, 255, 255);
356
        $y1 = $y + 2 + $bH;
357
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
358
        $texto = $this->formatField($this->chCTe, $this->formatoChave);
359
        $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...
360
        $retVal = $sY + 2;
361
        if ($this->tpEvento == '110110') {
362
            $x = $oldX;
363
            $this->pdf->textBox($x, $sY, $maxW, 15);
364
            $texto = $this->xCondUso;
365
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
366
            $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...
367
            $retVal = $sY + 2;
368
        }
369
        if ($this->tpAmb != 1) {
370
            $x = 10;
371
            if ($this->orientacao == 'P') {
372
                $y = round($this->hPrint * 2 / 3, 0);
373
            } else {
374
                $y = round($this->hPrint / 2, 0);
375
            }
376
            $h = 5;
377
            $w = $maxW - (2 * $x);
378
            $this->pdf->setTextColor(90, 90, 90);
379
            $texto = "SEM VALOR FISCAL";
380
            $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
381
            $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...
382
            $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
383
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
384
            $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...
385
            $this->pdf->setTextColor(0, 0, 0);
386
        }
387
        return $retVal;
388
    }
389
390
    /**
391
     * body
392
     * @param integer $x
393
     * @param integer $y
394
     */
395
    private function body($x, $y)
396
    {
397
        $maxW = $this->wPrint;
398
        if ($this->tpEvento == '110110') {
399
            $texto = 'CORREÇÕES A SEREM CONSIDERADAS';
400
        } else {
401
            $texto = 'JUSTIFICATIVA DO CANCELAMENTO';
402
        }
403
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
404
        $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...
405
        $y += 5;
406
        $this->pdf->textBox($x, $y, $maxW, 190);
407
        if ($this->tpEvento == '110110') {
408
            $texto = $this->xCorrecao;
409
        } elseif ($this->tpEvento == '110111') {
410
            $texto = $this->xJust;
411
        }
412
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
413
        $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...
414
    }
415
416
    /**
417
     * footer
418
     * @param integer $x
419
     * @param integer $y
420
     */
421
    private function footer($x, $y)
422
    {
423
        $w = $this->wPrint;
424
        if ($this->tpEvento == '110110') {
425
            $texto = "Este documento é uma representação gráfica da CCe e foi "
426
                . "impresso apenas para sua informação e não possue validade fiscal."
427
                . "\n A CCe deve ser recebida e mantida em arquivo eletrônico XML e "
428
                . "pode ser consultada através dos Portais das SEFAZ.";
429
        } elseif ($this->tpEvento == '110111') {
430
            $texto = "Este documento é uma representação gráfica do evento de CTe e foi "
431
                . "impresso apenas para sua informação e não possue validade fiscal."
432
                . "\n O Evento deve ser recebido e mantido em arquivo eletrônico XML e "
433
                . "pode ser consultada através dos Portais das SEFAZ.";
434
        }
435
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'I');
436
        $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...
437
        $y = $this->hPrint - 4;
438
        $texto = "Impresso em  " . date('d/m/Y   H:i:s') . ' ' . $this->creditos;
439
        $w = $this->wPrint - 4;
440
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
441
        $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...
442
        $texto = $this->powered ? "Powered by NFePHP®" : '';
443
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
444
        $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...
445
    }
446
}
447