Passed
Pull Request — master (#251)
by Roberto
02:39
created

DacteOS::seguro()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 51
ccs 0
cts 45
cp 0
crap 6
rs 9.069
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\CTe;
4
5
/**
6
 * Classe para ageração do PDF da CTe, conforme regras e estruturas
7
 * estabelecidas pela SEFAZ.
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @name      Dacte .php
12
 * @copyright 2009-2019 NFePHP
13
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
14
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
15
 * @author    Roberto L. Machado <linux dot rlm at gmail dot com>
16
 */
17
18
use Com\Tecnick\Barcode\Barcode;
19
use Exception;
20
use NFePHP\DA\Legacy\Dom;
21
use NFePHP\DA\Legacy\Pdf;
22
use NFePHP\DA\Legacy\Common;
23
24
class DacteOS extends Common
25
{
26
    const NFEPHP_SITUACAO_EXTERNA_CANCELADA = 1;
27
    const NFEPHP_SITUACAO_EXTERNA_DENEGADA = 2;
28
    const SIT_DPEC = 3;
29
30
    protected $logoAlign = 'C';
31
    protected $yDados = 0;
32
    protected $situacao_externa = 0;
33
    protected $numero_registro_dpec = '';
34
    protected $pdf;
35
    protected $xml;
36
    protected $logomarca = '';
37
    protected $errMsg = '';
38
    protected $errStatus = false;
39
    protected $orientacao = 'P';
40
    protected $papel = 'A4';
41
    protected $destino = 'I';
42
    protected $pdfDir = '';
43
    protected $fontePadrao = 'Times';
44
    protected $version = '1.3.0';
45
    protected $wPrint;
46
    protected $hPrint;
47
    protected $dom;
48
    protected $infCte;
49
    protected $infPercurso;
50
    protected $infCteComp;
51
    protected $chaveCTeRef;
52
    protected $tpCTe;
53
    protected $ide;
54
    protected $emit;
55
    protected $enderEmit;
56
    protected $infCarga;
57
    protected $infQ;
58
    protected $seg;
59
    protected $modal;
60
    protected $rodo;
61
    protected $moto;
62
    protected $veic;
63
    protected $ferrov;
64
    protected $Comp;
65
    protected $infNF;
66
    protected $infNFe;
67
    protected $compl;
68
    protected $ICMS;
69
    protected $imp;
70
    protected $toma4;
71
    protected $toma03;
72
    protected $tpEmis;
73
    protected $tpImp;
74
    protected $tpAmb;
75
    protected $vPrest;
76
    protected $infServico;
77
    protected $wAdic = 150;
78
    protected $textoAdic = '';
79
    protected $debugMode = 2;
80
    protected $formatPadrao;
81
    protected $formatNegrito;
82
    protected $aquav;
83
    protected $preVisualizar;
84
    protected $flagDocOrigContinuacao;
85
    protected $arrayNFe = array();
86
    protected $siteDesenvolvedor;
87
    protected $nomeDesenvolvedor;
88
    protected $totPag;
89
    protected $idDocAntEle = [];
90
    protected $lota;
91
92
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
93
    protected $margemInterna = 0;
94
95
    /**
96
     * __construct
97
     *
98
     * @param string $docXML Arquivo XML da CTe
99
     * @param string $sOrientacao (Opcional) Orientação da impressão P ou L
100
     * @param string $sPapel Tamanho do papel (Ex. A4)
101
     * @param string $sPathLogo Caminho para o arquivo do logo
102
     * @param string $sDestino Estabelece a direção do envio do documento PDF
103
     * @param string $sDirPDF Caminho para o diretorio de armaz. dos PDF
104
     * @param string $fonteDACTE Nome da fonte a ser utilizada
105
     * @param number $mododebug 0-Não 1-Sim e 2-nada (2 default)
106
     * @param string $preVisualizar 0-Não 1-Sim
107
     */
108
    public function __construct(
109
        $docXML = '',
110
        $sOrientacao = '',
111
        $sPapel = '',
112
        $sPathLogo = '',
113
        $sDestino = 'I',
114
        $sDirPDF = '',
115
        $fonteDACTE = '',
116
        $mododebug = 2,
117
        $preVisualizar = false,
118
        $nomeDesenvolvedor = 'Powered by NFePHP (GNU/GPLv3 GNU/LGPLv3) © www.nfephp.org',
119
        $siteDesenvolvedor = 'http://www.nfephp.org'
120
    ) {
121
122
        if (is_numeric($mododebug)) {
123
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
124
        }
125
        if ($mododebug == 1) {
126
            //ativar modo debug
127
            error_reporting(E_ALL);
128
            ini_set('display_errors', 'On');
129
        } elseif ($mododebug == 0) {
130
            //desativar modo debug
131
            error_reporting(0);
132
            ini_set('display_errors', 'Off');
133
        }
134
        $this->orientacao = $sOrientacao;
135
        $this->papel = $sPapel;
136
        $this->pdf = '';
137
        $this->xml = $docXML;
138
        $this->logomarca = $sPathLogo;
139
        $this->destino = $sDestino;
140
        $this->pdfDir = $sDirPDF;
141
        $this->preVisualizar = $preVisualizar;
142
        $this->siteDesenvolvedor = $siteDesenvolvedor;
143
        $this->nomeDesenvolvedor = $nomeDesenvolvedor;
144
        // verifica se foi passa a fonte a ser usada
145
        if (!empty($fonteDACTE)) {
146
            $this->fontePadrao = $fonteDACTE;
147
        }
148
        $this->formatPadrao = array(
149
            'font' => $this->fontePadrao,
150
            'size' => 6,
151
            'style' => '');
152
        $this->formatNegrito = array(
153
            'font' => $this->fontePadrao,
154
            'size' => 7,
155
            'style' => 'B');
156
        //se for passado o xml
157
        if (!empty($this->xml)) {
158
            $this->dom = new Dom();
159
            $this->dom->loadXML($this->xml);
160
            $this->cteProc = $this->dom->getElementsByTagName("cteOSProc")->item(0);
0 ignored issues
show
Bug introduced by
The property cteProc does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
161
            $this->infCte = $this->dom->getElementsByTagName("infCte")->item(0);
162
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
163
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
164
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
165
166
            $this->infPercurso = $this->dom->getElementsByTagName("infPercurso");
167
            $this->infCarga = $this->dom->getElementsByTagName("infCarga")->item(0);
168
            $this->infQ = $this->dom->getElementsByTagName("infQ");
169
            $this->seg = $this->dom->getElementsByTagName("seg")->item(0);
170
            $this->rodo = $this->dom->getElementsByTagName("rodoOS")->item(0);
171
172
173
            $this->veic = $this->dom->getElementsByTagName("veic");
174
            $this->ferrov = $this->dom->getElementsByTagName("ferrov")->item(0);
175
            // adicionar outros modais
176
            $this->infCteComp = $this->dom->getElementsByTagName("infCteComp")->item(0);
177
            $this->chaveCTeRef = $this->getTagValue($this->infCteComp, "chave");
178
            $this->vPrest = $this->dom->getElementsByTagName("vPrest")->item(0);
179
            $this->Comp = $this->dom->getElementsByTagName("Comp");
180
            $this->infNF = $this->dom->getElementsByTagName("infNF");
181
            $this->infNFe = $this->dom->getElementsByTagName("infNFe");
182
            $this->infOutros = $this->dom->getElementsByTagName("infOutros");
0 ignored issues
show
Bug introduced by
The property infOutros does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
183
            $this->infServico = $this->dom->getElementsByTagName("infServico");
184
            $this->compl = $this->dom->getElementsByTagName("compl");
185
            $this->ICMS = $this->dom->getElementsByTagName("ICMS")->item(0);
186
            $this->ICMSSN = $this->dom->getElementsByTagName("ICMSSN")->item(0);
0 ignored issues
show
Bug introduced by
The property ICMSSN does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
187
            $this->imp = $this->dom->getElementsByTagName("imp")->item(0);
188
189
            $vTrib = $this->getTagValue($this->imp, "vTotTrib");
190
            if (!is_numeric($vTrib)) {
191
                $vTrib = 0;
192
            }
193
            $textoAdic = number_format($vTrib, 2, ",", ".");
194
195
            $this->textoAdic = "o valor aproximado de tributos incidentes sobre o preço deste serviço é de R$"
196
                    .$textoAdic;
197
            $this->toma = $this->dom->getElementsByTagName("toma")->item(0);
0 ignored issues
show
Bug introduced by
The property toma does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
199
            //modal aquaviário
200
            $this->aquav = $this->dom->getElementsByTagName("aquav")->item(0);
201
202
            $seguro = $this->getTagValue($this->seg, "respSeg");
203
            switch ($seguro) {
204
                case '4':
205
                    $this->respSeg = 'Emitente';
0 ignored issues
show
Bug introduced by
The property respSeg does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
206
                    break;
207
                case '5':
208
                    $this->respSeg = 'Tomador do Serviço';
209
                    break;
210
                default:
211
                    $this->respSeg = '';
212
                    break;
213
            }
214
            $this->tpEmis = $this->getTagValue($this->ide, "tpEmis");
215
            $this->tpImp = $this->getTagValue($this->ide, "tpImp");
216
            $this->tpAmb = $this->getTagValue($this->ide, "tpAmb");
217
            $this->tpCTe = $this->getTagValue($this->ide, "tpCTe");
218
            $this->protCTe = $this->dom->getElementsByTagName("protCTe")->item(0);
0 ignored issues
show
Bug introduced by
The property protCTe does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
219
            $this->qrCodMDFe = $this->dom->getElementsByTagName('qrCodCTe')->item(0) ?
0 ignored issues
show
Bug introduced by
The property qrCodMDFe does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
220
                $this->dom->getElementsByTagName('qrCodCTe')->item(0)->nodeValue : 'SEM INFORMAÇÃO DE QRCODE';
221
            //01-Rodoviário; //02-Aéreo; //03-Aquaviário; //04-Ferroviário;//05-Dutoviário
222
            $this->modal = $this->getTagValue($this->ide, "modal");
223
        }
224
    }
225
226
    /**
227
     * monta
228
     * @param string $orientacao L ou P
229
     * @param string $papel A4
230
     * @param string $logoAlign C, L ou R
231
     * @param Pdf $classPDF
232
     * @return string montagem
233
     */
234
    public function monta(
235
        $orientacao = '',
236
        $papel = 'A4',
237
        $logoAlign = 'C',
238
        $classPDF = false
239
    ) {
240
241
        return $this->montaDACTE($orientacao, $papel, $logoAlign, $classPDF);
0 ignored issues
show
Bug introduced by
It seems like $classPDF defined by parameter $classPDF on line 238 can also be of type object<NFePHP\DA\Legacy\Pdf>; however, NFePHP\DA\CTe\DacteOS::montaDACTE() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
242
    }
243
244
    /**
245
     * printDocument
246
     * @param string $nome
247
     * @param string $destino
248
     * @param string $printer
249
     * @return
250
     */
251
    public function printDocument($nome = '', $destino = 'I', $printer = '')
252
    {
253
        return $this->printDACTE($nome, $destino, $printer);
254
    }
255
256
    /**
257
     * Dados brutos do PDF
258
     * @return string
259
     */
260
    public function render()
261
    {
262
        return $this->pdf->getPdf();
263
    }
264
265
266
    protected function cteDPEC()
267
    {
268
        return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != '';
269
    }
270
271
272
    /**
273
     * montaDACTE
274
     * Esta função monta a DACTE conforme as informações fornecidas para a classe
275
     * durante sua construção.
276
     * A definição de margens e posições iniciais para a impressão são estabelecidas no
277
     * pelo conteúdo da funçao e podem ser modificados.
278
     *
279
     * @param  string $orientacao (Opcional) Estabelece a orientação da
280
     *                impressão (ex. P-retrato), se nada for fornecido será
281
     *                usado o padrão da NFe
282
     * @param  string $papel (Opcional) Estabelece o tamanho do papel (ex. A4)
283
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
284
     */
285
    public function montaDACTE(
286
        $orientacao = '',
287
        $papel = 'A4',
288
        $logoAlign = 'C',
289
        $classPDF = false
290
    ) {
291
292
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
293
        if ($orientacao == '') {
294
            if ($this->tpImp == '1') {
295
                $orientacao = 'P';
296
            } else {
297
                $orientacao = 'P';
298
            }
299
        }
300
        $this->orientacao = $orientacao;
301
        $this->papel = $papel;
302
        $this->logoAlign = $logoAlign;
303
304
        //$this->situacao_externa = $situacao_externa;
305
        //instancia a classe pdf
306
        if ($classPDF !== false) {
307
            $this->pdf = $classPDF;
308
        } else {
309
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
310
        }
311
        if ($this->orientacao == 'P') {
312
            // margens do PDF
313
            $margSup = 2;
314
            $margEsq = 2;
315
            $margDir = 2;
316
            // posição inicial do relatorio
317
            $xInic = 1;
318
            $yInic = 1;
319
            if ($papel == 'A4') {
320
                //A4 210x297mm
321
                $maxW = 210;
322
                $maxH = 297;
323
            }
324
        } else {
325
            // margens do PDF
326
            $margSup = 3;
327
            $margEsq = 3;
328
            $margDir = 3;
329
            // posição inicial do relatorio
330
            $xInic = 5;
331
            $yInic = 5;
332
            if ($papel == 'A4') {
333
                //A4 210x297mm
334
                $maxH = 210;
335
                $maxW = 297;
336
                $this->wCanhoto = 25;
0 ignored issues
show
Bug introduced by
The property wCanhoto does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
337
            }
338
        }
339
        //total inicial de paginas
340
        $totPag = 1;
0 ignored issues
show
Unused Code introduced by
$totPag 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...
341
        //largura imprimivel em mm
342
        $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...
343
        //comprimento imprimivel em mm
344
        $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...
345
        // estabelece contagem de paginas
346
        $this->pdf->aliasNbPages();
347
        // fixa as margens
348
        $this->pdf->setMargins($margEsq, $margSup, $margDir);
349
        $this->pdf->setDrawColor(0, 0, 0);
350
        $this->pdf->setFillColor(255, 255, 255);
351
        // inicia o documento
352
        $this->pdf->open();
353
        // adiciona a primeira página
354
        $this->pdf->addPage($this->orientacao, $this->papel);
355
        $this->pdf->setLineWidth(0.1);
356
        $this->pdf->setTextColor(0, 0, 0);
357
        //calculo do numero de páginas ???
358
        $totPag = 1;
359
        //montagem da primeira página
360
        $pag = 1;
361
        $x = $xInic;
362
        $y = $yInic;
363
        //coloca o cabeçalho
364
        //$r = $this->cabecalho($x, $y, $pag, $totPag);
365
        $y += 70;
366
        $r = $this->tomador($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
367
        if ($this->tpCTe == '0') {
368
            //Normal
369
            $y += 10;
370
            $x = $xInic;
371
            //$r = $this->zDocOrig($x, $y);
372
            $r = $this->infPrestacaoServico($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
373
            $y += 53;
374
            $x = $xInic;
375
            $r = $this->compValorServ($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
376
            $y += 25;
377
            $x = $xInic;
378
            $r = $this->impostos($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
379
            $y += 13;
380
            $x = $xInic;
381
            $r = $this->observacoes($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
382
            $y += 19;
383
            $x = $xInic;
384
            $r = $this->seguro($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
385
            $y = $y-12;
386
387
388
            switch ($this->modal) {
389
                case '1':
390
                    $y += 24.9;
391
                    $x = $xInic;
392
                    $r = $this->modalRod($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
393
                    break;
394
                case '2':
395
                    $y += 17.9;
396
                    $x = $xInic;
397
                    // TODO fmertins 31/10/14: este método não existe...
398
                    $r = $this->modalAereo($x, $y);
0 ignored issues
show
Bug introduced by
The method modalAereo() does not seem to exist on object<NFePHP\DA\CTe\DacteOS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
$r 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...
399
                    break;
400
                case '3':
401
                    $y += 17.9;
402
                    $x = $xInic;
403
                    $r = $this->modalAquaviario($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
404
                    break;
405
                case '4':
406
                    $y += 17.9;
407
                    $x = $xInic;
408
                    $r = $this->modalFerr($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
409
                    break;
410
                case '5':
411
                    $y += 17.9;
412
                    $x = $xInic;
413
                    // TODO fmertins 31/10/14: este método não existe...
414
                    $r = $this->modalDutoviario($x, $y);
0 ignored issues
show
Bug introduced by
The method modalDutoviario() does not seem to exist on object<NFePHP\DA\CTe\DacteOS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
$r 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...
415
                    break;
416
            }
417
            if ($this->modal == '1') {
418
                if ($this->lota == 1) {
419
                    $y += 37;
420
                } else {
421
                    $y += 8.9;
422
                }
423
            } elseif ($this->modal == '3') {
424
                $y += 24.15;
425
            } else {
426
                $y += 37;
427
            }
428
        } else {
429
            $r = $this->cabecalho(1, 1, $pag, $totPag);
0 ignored issues
show
Unused Code introduced by
$r 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...
430
            //Complementado
431
            $y += 10;
432
            $x = $xInic;
433
            $r = $this->docCompl($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
434
            $y += 80;
435
            $x = $xInic;
436
            $r = $this->compValorServ($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
437
            $y += 25;
438
            $x = $xInic;
439
            $r = $this->impostos($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
440
            $y += 13;
441
            $x = $xInic;
442
            $r = $this->observacoes($x, $y);
0 ignored issues
show
Unused Code introduced by
$r 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...
443
            $y += 15;
444
        }
445
        $x = $xInic;
446
        $y += 1;
447
        $r = $this->dadosAdic($x, $y, $pag, $totPag);
0 ignored issues
show
Unused Code introduced by
$r 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...
448
449
        $y += 21;
450
        //$y += 11;
451
        $y = $this->canhoto($x, $y);
0 ignored issues
show
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...
452
453
        //coloca o rodapé da página
454
        if ($this->orientacao == 'P') {
455
            $this->rodape(2, $this->hPrint - 2);
456
        } else {
457
            $this->rodape($xInic, $this->hPrint + 2.3);
458
        }
459
        if ($this->flagDocOrigContinuacao == 1) {
460
            $this->docOrigContinuacao(1, 71);
0 ignored issues
show
Bug introduced by
The method docOrigContinuacao() does not seem to exist on object<NFePHP\DA\CTe\DacteOS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
461
        }
462
        //retorna o ID na CTe
463
        if ($classPDF !== false) {
464
            $aR = array('id' => str_replace('CTe', '', $this->infCte->getAttribute("Id")), 'classe_PDF' => $this->pdf);
465
            return $aR;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $aR; (array) is incompatible with the return type documented by NFePHP\DA\CTe\DacteOS::montaDACTE of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
466
        } else {
467
            return str_replace('CTe', '', $this->infCte->getAttribute("Id"));
468
        }
469
    } //fim da função montaDACTE
470
471
    /**
472
     * printDACTE
473
     * Esta função envia a DACTE em PDF criada para o dispositivo informado.
474
     * O destino da impressão pode ser :
475
     * I-browser
476
     * D-browser com download
477
     * F-salva em um arquivo local com o nome informado
478
     * S-retorna o documento como uma string e o nome é ignorado.
479
     * Para enviar o pdf diretamente para uma impressora indique o
480
     * nome da impressora e o destino deve ser 'S'.
481
     *
482
     * @param  string $nome Path completo com o nome do arquivo pdf
483
     * @param  string $destino Direção do envio do PDF
484
     * @param  string $printer Identificação da impressora no sistema
485
     * @return string Caso o destino seja S o pdf é retornado como uma string
486
     * @todo Rotina de impressão direta do arquivo pdf criado
487
     */
488
    public function printDACTE($nome = '', $destino = 'I', $printer = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer 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...
489
    {
490
        $arq = $this->pdf->Output($nome, $destino);
491
        if ($destino == 'S') {
492
            //aqui pode entrar a rotina de impressão direta
493
        }
494
        return $arq;
495
    } //fim função printDACTE
496
497
    /**
498
     * cabecalho
499
     * Monta o cabelhalho da DACTE ( retrato e paisagem )
500
     *
501
     * @param  number $x Posição horizontal inicial, canto esquerdo
502
     * @param  number $y Posição vertical inicial, canto superior
503
     * @param  number $pag Número da Página
504
     * @param  number $totPag Total de páginas
505
     * @return number Posição vertical final
506
     */
507
    protected function cabecalho($x = 0, $y = 0, $pag = '1', $totPag = '1')
0 ignored issues
show
Unused Code introduced by
The parameter $totPag 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...
508
    {
509
        $oldX = $x;
510
        $oldY = $y;
511
        if ($this->orientacao == 'P') {
512
            $maxW = $this->wPrint;
513
        } else {
514
            if ($pag == 1) {
515
                // primeira página
516
                $maxW = $this->wPrint - $this->wCanhoto;
517
            } else {
518
                // páginas seguintes
519
                $maxW = $this->wPrint;
520
            }
521
        }
522
        //##################################################################
523
        //coluna esquerda identificação do emitente
524
        $w = round($maxW * 0.42);
525
        if ($this->orientacao == 'P') {
526
            $aFont = array(
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
527
                'font' => $this->fontePadrao,
528
                'size' => 6,
529
                'style' => '');
530
        } else {
531
            $aFont = $this->formatNegrito;
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
532
        }
533
        $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...
534
        $h = 35;
535
        $oldY += $h;
536
        //desenha a caixa
537
        $this->pdf->textBox($x, $y, $w + 2, $h + 1);
538
        // coloca o logo
539
        if (is_file($this->logomarca)) {
540
            $logoInfo = getimagesize($this->logomarca);
541
            //largura da imagem em mm
542
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
543
            //altura da imagem em mm
544
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
545
            if ($this->logoAlign == 'L') {
546
                $nImgW = round($w / 3, 0);
547
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
548
                $xImg = $x + 1;
549
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
550
                //estabelecer posições do texto
551
                $x1 = round($xImg + $nImgW + 1, 0);
552
                $y1 = round($h / 3 + $y, 0);
553
                $tw = round(2 * $w / 3, 0);
554
            } elseif ($this->logoAlign == 'C') {
555
                $nImgH = round($h / 3, 0);
556
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
557
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
558
                $yImg = $y + 3;
559
                $x1 = $x;
560
                $y1 = round($yImg + $nImgH + 1, 0);
561
                $tw = $w;
562
            } elseif ($this->logoAlign == 'R') {
563
                $nImgW = round($w / 3, 0);
564
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
565
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
566
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
567
                $x1 = $x;
568
                $y1 = round($h / 3 + $y, 0);
569
                $tw = round(2 * $w / 3, 0);
570
            }
571
            $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...
572
        } else {
573
            $x1 = $x;
574
            $y1 = round($h / 3 + $y, 0);
575
            $tw = $w;
576
        }
577
        //Nome emitente
578
        $aFont = array(
579
            'font' => $this->fontePadrao,
580
            'size' => 9,
581
            'style' => 'B');
582
        $texto = $this->getTagValue($this->emit, "xNome");
583
        $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...
584
        //endereço
585
        $y1 = $y1 + 3;
586
        $aFont = array(
587
            'font' => $this->fontePadrao,
588
            'size' => 7,
589
            'style' => '');
590
        $fone = $this->getTagValue($this->enderEmit, "fone")!=""? $this->formatFone($this->enderEmit):'';
0 ignored issues
show
Documentation introduced by
$this->enderEmit is of type object<DOMNode>, but the function expects a string.

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...
591
        $lgr = $this->getTagValue($this->enderEmit, "xLgr");
592
        $nro = $this->getTagValue($this->enderEmit, "nro");
593
        $cpl = $this->getTagValue($this->enderEmit, "xCpl");
0 ignored issues
show
Unused Code introduced by
$cpl 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...
594
        $bairro = $this->getTagValue($this->enderEmit, "xBairro");
595
        $CEP = $this->getTagValue($this->enderEmit, "CEP");
596
        $CEP = $this->formatField($CEP, "#####-###");
597
        $mun = $this->getTagValue($this->enderEmit, "xMun");
598
        $UF = $this->getTagValue($this->enderEmit, "UF");
599
        $xPais = $this->getTagValue($this->enderEmit, "xPais");
600
        $texto = $lgr . "," . $nro . "\n" . $bairro . " - "
601
            . $CEP . " - " . $mun . " - " . $UF . " " . $xPais
602
            . "\n  Fone/Fax: " . $fone;
603
        $this->pdf->textBox($x1 - 5, $y1 + 2, $tw + 5, 8, $texto, $aFont, 'T', 'C', 0, '');
604
        //CNPJ/CPF IE
605
        $cpfCnpj = $this->formatCNPJCPF($this->emit);
0 ignored issues
show
Documentation introduced by
$this->emit is of type object<DOMNode>, but the function expects a string.

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...
606
        $ie = $this->getTagValue($this->emit, "IE");
607
        $texto = 'CNPJ/CPF:  ' . $cpfCnpj . '     Insc.Estadual: ' . $ie;
608
        $this->pdf->textBox($x1 - 1, $y1 + 12, $tw + 5, 8, $texto, $aFont, 'T', 'C', 0, '');
609
        //outra caixa
610
        $h1 = 17.5;
611
        $y1 = $y + $h + 1;
612
        $this->pdf->textBox($x, $y1, $w + 2, $h1);
613
        //TIPO DO CT-E
614
        $texto = 'TIPO DO CTE';
615
        $wa = 37;
616
        $aFont = array(
617
            'font' => $this->fontePadrao,
618
            'size' => 8,
619
            'style' => '');
620
        $this->pdf->textBox($x, $y1, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '');
621
        $tpCTe = $this->getTagValue($this->ide, "tpCTe");
622
        //0 - CT-e Normal,1 - CT-e de Complemento de Valores,
623
        //2 - CT-e de Anulação de Valores,3 - CT-e Substituto
624
        switch ($tpCTe) {
625
            case '0':
626
                $texto = 'Normal';
627
                break;
628
            case '1':
629
                $texto = 'Complemento de Valores';
630
                break;
631
            case '2':
632
                $texto = 'Anulação de Valores';
633
                break;
634
            case '3':
635
                $texto = 'Substituto';
636
                break;
637
            default:
638
                $texto = 'ERRO' . $tpCTe . $tpServ;
0 ignored issues
show
Bug introduced by
The variable $tpServ seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
639
        }
640
        $aFont = $this->formatNegrito;
641
        $this->pdf->textBox($x, $y1 + 3, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '', false);
642
        //TIPO DO SERVIÇO
643
        $texto = 'TIPO DO SERVIÇO';
644
        $wb = 36;
0 ignored issues
show
Unused Code introduced by
$wb 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...
645
        $aFont = array(
646
            'font' => $this->fontePadrao,
647
            'size' => 8,
648
            'style' => '');
649
        $this->pdf->textBox($x + $wa + 4.5, $y1, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '');
650
        $tpServ = $this->getTagValue($this->ide, "tpServ");
651
        //'6' => 'Transporte de Pessoas', '7' => 'Transporte de Valores', '8' => 'Transporte de Bagagem'
652
        switch ($tpServ) {
653
            case '6':
654
                $texto = 'Transporte de Pessoas';
655
                break;
656
            case '7':
657
                $texto = 'Transporte de Valores';
658
                break;
659
            case '8':
660
                $texto = 'Transporte de Bagagem';
661
                break;
662
            default:
663
                $texto = 'ERRO' . $tpServ;
664
        }
665
        $aFont = $this->formatNegrito;
666
        $this->pdf->textBox($x + $wa + 4.5, $y1 + 3, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '', false);
667
        $this->pdf->line($w * 0.5, $y1, $w * 0.5, $y1 + $h1);
668
        //TOMADOR DO SERVIÇO
669
        $aFont = $this->formatNegrito;
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
670
671
        //##################################################################
672
        //coluna direita
673
        $x += $w + 2;
674
        $w = round($maxW * 0.335);
675
        $w1 = $w;
676
        $h = 11;
677
        $this->pdf->textBox($x, $y, $w + 10, $h + 1);
678
        $texto = "DACTE OS";
679
        $aFont = array(
680
            'font' => $this->fontePadrao,
681
            'size' => 10,
682
            'style' => 'B');
683
        $this->pdf->textBox($x, $y + 1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
684
        $aFont = array(
685
            'font' => $this->fontePadrao,
686
            'size' => 9,
687
            'style' => '');
688
        $texto = "Documento Auxiliar do Conhecimento\nde Transporte Eletrônico para Outros Serviços";
689
        $h = 10;
690
        $this->pdf->textBox($x, $y + 4, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
691
        $x1 = $x + $w + 2;
692
        $w = round($maxW * 0.22, 0);
693
        $w2 = $w;
0 ignored issues
show
Unused Code introduced by
$w2 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...
694
        $h = 11;
695
        $this->pdf->textBox($x1 + 8, $y, $w - 7.5, $h + 1);
696
        $texto = "MODAL";
697
        $aFont = array(
698
            'font' => $this->fontePadrao,
699
            'size' => 10,
700
            'style' => '');
701
        $this->pdf->textBox($x1, $y + 1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
702
        switch ($this->modal) {
703
            case '1':
704
                $texto = 'Rodoviário';
705
                break;
706
            case '2':
707
                $texto = 'Aéreo';
708
                break;
709
            case '3':
710
                $texto = 'Aquaviário';
711
                break;
712
            case '4':
713
                $texto = 'Ferroviário';
714
                break;
715
            case '5':
716
                $texto = 'Dutoviário';
717
                break;
718
        }
719
        $aFont = array(
720
            'font' => $this->fontePadrao,
721
            'size' => 10,
722
            'style' => 'B');
723
        $this->pdf->textBox($x1, $y + 5, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
724
        //outra caixa
725
        $y += 12;
726
        $h = 9;
727
        $w = $w1 + 10;
728
        $this->pdf->textBox($x, $y, $w, $h + 1);
729
        //modelo
730
        $wa = 12;
731
        $xa = $x;
732
        $texto = 'MODELO';
733
        $aFont = array(
734
            'font' => $this->fontePadrao,
735
            'size' => 8,
736
            'style' => '');
737
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
738
        $texto = $this->getTagValue($this->ide, "mod");
739
        $aFont = $this->formatNegrito;
740
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
741
        $this->pdf->line($x + $wa, $y, $x + $wa, $y + $h + 1);
742
        //serie
743
        $xa += $wa;
744
        $texto = 'SÉRIE';
745
        $aFont = array(
746
            'font' => $this->fontePadrao,
747
            'size' => 8,
748
            'style' => '');
749
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
750
        $texto = $this->getTagValue($this->ide, "serie");
751
        $aFont = $this->formatNegrito;
752
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
753
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
754
        //numero
755
        $xa += $wa;
756
        $wa = 20;
757
        $texto = 'NÚMERO';
758
        $aFont = array(
759
            'font' => $this->fontePadrao,
760
            'size' => 8,
761
            'style' => '');
762
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
763
        $texto = $this->getTagValue($this->ide, "nCT");
764
        $aFont = $this->formatNegrito;
765
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
766
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
767
        //data  hora de emissão
768
        $xa += $wa;
769
        $wa = 35;
770
        $texto = 'DATA E HORA DE EMISSÃO';
771
        $aFont = array(
772
            'font' => $this->fontePadrao,
773
            'size' => 8,
774
            'style' => '');
775
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
776
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
777
        $texto = !empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
778
            date('d/m/Y H:i:s', $this->convertTime($this->getTagValue($this->ide, "dhEmi"))) : '';
779
        $aFont = $this->formatNegrito;
780
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
781
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
782
        //outra caixa
783
        $y += $h + 1;
784
        $h = 23;
785
        $h1 = 14;
786
        //$this->pdf->textBox($x, $y, $w + 0.5, $h1);
787
        //CODIGO DE BARRAS
788
        $chave_acesso = str_replace('CTe', '', $this->infCte->getAttribute("Id"));
789
        $bW = 75;
790
        $bH = 10;
791
        //codigo de barras
792
        $this->pdf->setFillColor(0, 0, 0);
793
        $this->pdf->code128($x + 2, $y + 2, $chave_acesso, $bW, $bH);
794
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h - 1);
795
        $this->pdf->textBox($x, $y + $h1, $w + 0.5, $h1 - 6);
796
        $texto = 'CHAVE DE ACESSO';
797
        $aFont = $this->formatPadrao;
798
        $this->pdf->textBox($x + 1, $y + $h1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
799
        $aFont = $this->formatNegrito;
800
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
801
        $this->pdf->textBox($x + 1, $y + $h1 + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
802
        $this->pdf->textBox($x, $y + $h1 + 8, $w + 0.5, $h1 - 4.5);
803
        $texto = "Consulta de autenticidade no portal nacional do CT-e, ";
804
        $texto .= "no site da Sefaz Autorizadora, \r\n ou em http://www.cte.fazenda.gov.br";
805
        if ($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) {
806
            $texto = "";
807
            $this->pdf->setFillColor(0, 0, 0);
808
            if ($this->tpEmis == 5) {
809
                $chaveContingencia = $this->geraChaveAdicCont();
810
                $this->pdf->code128($x + 20, $y1 + 10, $chaveContingencia, $bW * .9, $bH / 2);
811
            } else {
812
                $chaveContingencia = $this->getTagValue($this->protCTe, "nProt");
813
                $this->pdf->code128($x + 40, $y1 + 10, $chaveContingencia, $bW * .4, $bH / 2);
814
            }
815
            //codigo de barras
816
        }
817
        $aFont = array(
818
            'font' => $this->fontePadrao,
819
            'size' => 8,
820
            'style' => '');
821
        $this->pdf->textBox($x, $y + $h1 + 9, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
822
        //outra caixa
823
        $y += $h + 1;
824
        $h = 8.5;
825
        $wa = $w;
826
        $this->pdf->textBox($x, $y + 7.5, $w + 0.5, $h);
827
        if ($this->cteDPEC()) {
828
            $texto = 'NÚMERO DE REGISTRO DPEC';
829
        } elseif ($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) {
830
            $texto = "DADOS DO CT-E";
831
        } else {
832
            $texto = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
833
        }
834
        $aFont = $this->formatPadrao;
835
        $this->pdf->textBox($x, $y + 7.5, $wa, $h, $texto, $aFont, 'T', 'L', 0, '');
836
        if ($this->cteDPEC()) {
837
            $texto = $this->numero_registro_dpec;
838
        } elseif ($this->tpEmis == 5) {
839
            $chaveContingencia = $this->geraChaveAdicCont();
840
            $aFont = array(
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
841
                'font' => $this->fontePadrao,
842
                'size' => 8,
843
                'style' => 'B');
844
            $texto = $this->formatField($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
845
            $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat 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...
846
        } else {
847
            $texto = $this->getTagValue($this->protCTe, "nProt") . " - ";
848
            // empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue)
849
            if (!empty($this->protCTe)
850
                && !empty($this->protCTe->getElementsByTagName("dhRecbto")->item(0)->nodeValue)
851
            ) {
852
                $texto .= date(
853
                    'd/m/Y   H:i:s',
854
                    $this->convertTime($this->getTagValue($this->protCTe, "dhRecbto"))
855
                );
856
            }
857
            $texto = $this->getTagValue($this->protCTe, "nProt") == '' ? '' : $texto;
858
        }
859
        $aFont = $this->formatNegrito;
860
        $this->pdf->textBox($x, $y + 12, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
861
862
        if ($this->qrCodMDFe !== null) {
863
            $this->qrCodeDacteOs($y-25);
864
            $w = 38;
865
            $x += 79;
866
            $this->pdf->textBox($x, $y - 34, $w + 0.5, $h + 41.5);
867
        }
868
        //CFOP
869
        $x = $oldX;
870
        $h = 8.5;
871
        $w = round($maxW * 0.42);
872
        $y1 = $y + 7.5;
873
        $this->pdf->textBox($x, $y1, $w + 2, $h);
874
        $texto = 'CFOP - NATUREZA DA PRESTAÇÃO';
875
        $aFont = array(
876
            'font' => $this->fontePadrao,
877
            'size' => 8,
878
            'style' => '');
879
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
880
        $texto = $this->getTagValue($this->ide, "CFOP") . ' - ' . $this->getTagValue($this->ide, "natOp");
881
        $aFont = $this->formatNegrito;
882
        $this->pdf->textBox($x, $y1 + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
883
        //ORIGEM DA PRESTAÇÃO
884
        $y += $h + 7.5;
885
        $x = $oldX;
886
        $h = 8;
887
        $w = ($maxW * 0.33);
888
        $this->pdf->textBox($x, $y, $w + 0.5, $h);
889
        $texto = 'INÍCIO DA PRESTAÇÃO';
890
        $aFont = array(
891
            'font' => $this->fontePadrao,
892
            'size' => 8,
893
            'style' => '');
894
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
895
        $texto = $this->getTagValue($this->ide, "xMunIni") . ' - ' . $this->getTagValue($this->ide, "UFIni");
896
        $aFont = $this->formatNegrito;
897
        $this->pdf->textBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
898
        //PERCURSO DO VEÍCULO
899
        $x = $oldX + 69;
900
        $oldX = $x;
901
        $h = 8;
902
        $w = ($maxW * 0.334);
903
        $this->pdf->textBox($x, $y, $w + 0.5, $h);
904
        $texto = 'PERCURSO DO VEÍCULO';
905
        $aFont = array(
906
            'font' => $this->fontePadrao,
907
            'size' => 8,
908
            'style' => '');
909
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
910
        $texto = '';
911
        $first = true;
912
        if (!empty($this->infPercurso)) {
913
            foreach ($this->infPercurso as $k => $d) {
914
                if (!$first) {
915
                    $texto .= ' - ';
916
                } else {
917
                    $first = false;
918
                }
919
                $texto .= $this->infPercurso->item($k)->getElementsByTagName('UFPer')->item(0)->nodeValue;
920
            }
921
        }
922
        $aFont = $this->formatNegrito;
923
        $this->pdf->textBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
924
        //DESTINO DA PRESTAÇÃO
925
        $x = $oldX + $w + 1;
926
        $h = 8;
927
        $w = $w - 1.3;
928
        $this->pdf->textBox($x - 0.5, $y, $w + 0.5, $h);
929
        $texto = 'TÉRMINO DA PRESTAÇÃO';
930
        $aFont = array(
931
            'font' => $this->fontePadrao,
932
            'size' => 8,
933
            'style' => '');
934
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
935
        $texto = $this->getTagValue($this->ide, "xMunFim") . ' - ' . $this->getTagValue($this->ide, "UFFim");
936
        $aFont = $this->formatNegrito;
937
        $this->pdf->textBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
938
        //#########################################################################
939
        //Indicação de CTe Homologação, cancelamento e falta de protocolo
940
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
941
        //indicar cancelamento
942
        $cStat = $this->getTagValue($this->cteProc, "cStat");
943
        if ($cStat == '101' || $cStat == '135' || $this->situacao_externa == self::NFEPHP_SITUACAO_EXTERNA_CANCELADA) {
944
            //101 Cancelamento
945
            $x = 10;
946
            $y = $this->hPrint - 130;
947
            $h = 25;
948
            $w = $maxW - (2 * $x);
949
            $this->pdf->setTextColor(90, 90, 90);
950
            $texto = "CTe CANCELADO";
951
            $aFont = array(
952
                'font' => $this->fontePadrao,
953
                'size' => 48,
954
                'style' => 'B');
955
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
956
            $this->pdf->setTextColor(0, 0, 0);
957
        }
958
        $cStat = $this->getTagValue($this->cteProc, "cStat");
959
        if ($cStat == '110' ||
960
            $cStat == '301' ||
961
            $cStat == '302' ||
962
            $this->situacao_externa == self::NFEPHP_SITUACAO_EXTERNA_DENEGADA
963
        ) {
964
            //110 Denegada
965
            $x = 10;
966
            $y = $this->hPrint - 130;
967
            $h = 25;
968
            $w = $maxW - (2 * $x);
969
            $this->pdf->setTextColor(90, 90, 90);
970
            $texto = "CTe USO DENEGADO";
971
            $aFont = array(
972
                'font' => $this->fontePadrao,
973
                'size' => 48,
974
                'style' => 'B');
975
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
976
            $y += $h;
977
            $h = 5;
978
            $w = $maxW - (2 * $x);
979
            $texto = "SEM VALOR FISCAL";
980
            $aFont = array(
981
                'font' => $this->fontePadrao,
982
                'size' => 48,
983
                'style' => 'B');
984
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
985
            $this->pdf->setTextColor(0, 0, 0);
986
        }
987
        //indicar sem valor
988
        if ($tpAmb != 1 && $this->preVisualizar=='0') { // caso não seja uma DA de produção
989
            $x = 10;
990
            if ($this->orientacao == 'P') {
991
                $y = round($this->hPrint / 2, 0);
992
            } else {
993
                $y = round($this->hPrint / 2, 0);
994
            }
995
            $h = 5;
996
            $w = $maxW - (2 * $x);
997
            $this->pdf->setTextColor(90, 90, 90);
998
            $texto = "SEM VALOR FISCAL";
999
            $aFont = array(
1000
                'font' => $this->fontePadrao,
1001
                'size' => 48,
1002
                'style' => 'B');
1003
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1004
            $aFont = array(
1005
                'font' => $this->fontePadrao,
1006
                'size' => 30,
1007
                'style' => 'B');
1008
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1009
            $this->pdf->textBox($x, $y + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1010
            $this->pdf->setTextColor(0, 0, 0);
1011
        } elseif ($this->preVisualizar=='1') { // caso seja uma DA de Pré-Visualização
1012
            $h = 5;
1013
            $w = $maxW - (2 * 10);
1014
            $x = 55;
1015
            $y = 240;
1016
            $this->pdf->setTextColor(255, 100, 100);
1017
            $aFont = array(
1018
                'font' => $this->fontePadrao,
1019
                'size' => 40,
1020
                'style' => 'B');
1021
            $texto = "Pré-visualização";
1022
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1023
            $this->pdf->setTextColor(255, 100, 100);
1024
            $aFont = array(
1025
                'font' => $this->fontePadrao,
1026
                'size' => 41,
1027
                'style' => 'B');
1028
            $texto = "Sem Validade Jurídica";
1029
            $this->pdf->textBox90($x+20, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1030
            $this->pdf->setTextColor(90, 90, 90);
1031
            $texto = "SEM VALOR FISCAL";
1032
            $aFont = array(
1033
                'font' => $this->fontePadrao,
1034
                'size' => 48,
1035
                'style' => 'B');
1036
            $this->pdf->textBox90($x+40, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1037
            $this->pdf->setTextColor(0, 0, 0); // voltar a cor default
1038
        } else {
1039
            $x = 10;
1040
            if ($this->orientacao == 'P') {
1041
                $y = round($this->hPrint * 2 / 3, 0);
1042
            } else {
1043
                $y = round($this->hPrint / 2, 0);
1044
            } //fim orientacao
1045
            $h = 5;
1046
            $w = $maxW - (2 * $x);
1047
            $this->pdf->setTextColor(90, 90, 90);
1048
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1049
            if (($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) && !$this->cteDPEC()) {
1050
                //Contingência
1051
                $texto = "DACTE Emitido em Contingência";
1052
                $aFont = array(
1053
                    'font' => $this->fontePadrao,
1054
                    'size' => 48,
1055
                    'style' => 'B');
1056
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1057
                $aFont = array(
1058
                    'font' => $this->fontePadrao,
1059
                    'size' => 30,
1060
                    'style' => 'B');
1061
                $texto = "devido à problemas técnicos";
1062
                $this->pdf->textBox($x, $y + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1063
            } else {
1064
                if (!isset($this->protCTe)) {
1065
                    if (!$this->cteDPEC()) {
1066
                        $texto = "SEM VALOR FISCAL";
1067
                        $aFont = array(
1068
                            'font' => $this->fontePadrao,
1069
                            'size' => 48,
1070
                            'style' => 'B');
1071
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1072
                    }
1073
                    $aFont = array(
1074
                        'font' => $this->fontePadrao,
1075
                        'size' => 30,
1076
                        'style' => 'B');
1077
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1078
                    if (!$this->cteDPEC()) {
1079
                        $this->pdf->textBox($x, $y + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1080
                    } else {
1081
                        $this->pdf->textBox($x, $y + 25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1082
                    }
1083
                } //fim cteProc
1084
                if ($this->tpEmis == 4) {
1085
                    //DPEC
1086
                    $x = 10;
1087
                    $y = $this->hPrint - 130;
1088
                    $h = 25;
1089
                    $w = $maxW - (2 * $x);
1090
                    $this->pdf->setTextColor(200, 200, 200); // 90,90,90 é muito escuro
1091
                    $texto = "DACTE impresso em contingência -\n"
1092
                        . "DPEC regularmente recebido pela Receita\n"
1093
                        . "Federal do Brasil";
1094
                    $aFont = array(
1095
                        'font' => $this->fontePadrao,
1096
                        'size' => 48,
1097
                        'style' => 'B');
1098
                    $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1099
                    $this->pdf->setTextColor(0, 0, 0);
1100
                }
1101
            } //fim tpEmis
1102
            $this->pdf->setTextColor(0, 0, 0);
1103
        }
1104
        return $oldY;
1105
    }
1106
1107
    /**
1108
     * rodapeDACTE
1109
     * Monta o rodape no final da DACTE ( retrato e paisagem )
1110
     *
1111
     * @param number $xInic Posição horizontal canto esquerdo
0 ignored issues
show
Bug introduced by
There is no parameter named $xInic. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1112
     * @param number $yFinal Posição vertical final para impressão
0 ignored issues
show
Bug introduced by
There is no parameter named $yFinal. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1113
     */
1114
    protected function rodape($x, $y)
1115
    {
1116
        $texto = "Impresso em  " . date('d/m/Y   H:i:s');
1117
        $w = $this->wPrint - 4;
1118
        $aFont = array(
1119
            'font' => $this->fontePadrao,
1120
            'size' => 6,
1121
            'style' => '');
1122
        $this->pdf->textBox($x-1, $y+2, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
1123
        $texto = $this->nomeDesenvolvedor . ' - '. $this->siteDesenvolvedor;
1124
        $aFont = array(
1125
            'font' => $this->fontePadrao,
1126
            'size' => 6,
1127
            'style' => '');
1128
        $this->pdf->textBox($x-50, $y+2, $w, 4, $texto, $aFont, 'T', 'R', 0, $this->siteDesenvolvedor);
1129
    }
1130
1131
    /**
1132
     * tomador
1133
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1134
     *
1135
     * @param  number $x Posição horizontal canto esquerdo
1136
     * @param  number $y Posição vertical canto superior
1137
     * @return number Posição vertical final
1138
     */
1139
    protected function tomador($x = 0, $y = 0)
1140
    {
1141
        $oldX = $x;
1142
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1143
        if ($this->orientacao == 'P') {
1144
            $maxW = $this->wPrint;
1145
        } else {
1146
            $maxW = $this->wPrint - $this->wCanhoto;
1147
        }
1148
        $w = $maxW;
1149
        $h = 10;
1150
        $texto = 'TOMADOR DO SERVIÇO';
1151
        $aFont = $this->formatPadrao;
1152
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1153
        $aFont = $this->formatNegrito;
1154
        $texto = $this->getTagValue($this->toma, "xNome");
1155
        $this->pdf->textBox($x + 29, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1156
        $x = $maxW * 0.60;
1157
        $texto = 'MUNICÍPIO';
1158
        $aFont = $this->formatPadrao;
1159
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1160
        $texto = $this->getTagValue($this->toma, "xMun");
1161
        $aFont = $this->formatNegrito;
1162
        $this->pdf->textBox($x + 15, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1163
        $x = $maxW * 0.85;
1164
        $texto = 'UF';
1165
        $aFont = $this->formatPadrao;
1166
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1167
        $texto = $this->getTagValue($this->toma, "UF");
1168
        $aFont = $this->formatNegrito;
1169
        $this->pdf->textBox($x + 4, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1170
        $x = $w - 18;
1171
        $texto = 'CEP';
1172
        $aFont = $this->formatPadrao;
1173
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1174
        $texto = $this->formatField($this->getTagValue($this->toma, "CEP"), "#####-###");
1175
        $aFont = $this->formatNegrito;
1176
        $this->pdf->textBox($x + 6, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1177
        $y += 3;
1178
        $x = $oldX;
1179
        $texto = 'ENDEREÇO';
1180
        $aFont = $this->formatPadrao;
1181
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1182
        $aFont = $this->formatNegrito;
1183
        $texto = $this->getTagValue($this->toma, "xLgr") . ',';
1184
        $texto .= $this->getTagValue($this->toma, "nro");
1185
        $texto .= ($this->getTagValue($this->toma, "xCpl") != "") ?
1186
            ' - ' . $this->getTagValue($this->toma, "xCpl") : '';
1187
        $texto .= ' - ' . $this->getTagValue($this->toma, "xBairro");
1188
        $this->pdf->textBox($x + 16, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1189
        $y += 3;
1190
        $texto = 'CNPJ/CPF';
1191
        $aFont = $this->formatPadrao;
1192
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1193
        $texto = $this->formatCNPJCPF($this->toma);
1194
        $aFont = $this->formatNegrito;
1195
        $this->pdf->textBox($x + 13, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1196
        $x = $x + 65;
1197
        $texto = 'INSCRIÇÃO ESTADUAL';
1198
        $aFont = $this->formatPadrao;
1199
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1200
        $texto = $this->getTagValue($this->toma, "IE");
1201
        $aFont = $this->formatNegrito;
1202
        $this->pdf->textBox($x + 28, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1203
        $x = $w * 0.75;
1204
        $texto = 'PAÍS';
1205
        $aFont = $this->formatPadrao;
1206
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1207
        $texto = $this->getTagValue($this->toma, "xPais") != "" ?
1208
            $this->getTagValue($this->toma, "xPais") : 'BRASIL';
1209
        $aFont = $this->formatNegrito;
1210
        $this->pdf->textBox($x + 6, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1211
        $x = $w - 27;
1212
        $texto = 'FONE';
1213
        $aFont = $this->formatPadrao;
1214
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1215
        $texto = $this->getTagValue($this->toma, "fone")!=""? $this->formatFone($this->toma):'';
1216
        $aFont = $this->formatNegrito;
1217
        $this->pdf->textBox($x + 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1218
    }
1219
1220
    /**
1221
     * compValorServ
1222
     * Monta o campo com os componentes da prestação de serviços.
1223
     *
1224
     * @param  number $x Posição horizontal canto esquerdo
1225
     * @param  number $y Posição vertical canto superior
1226
     * @return number Posição vertical final
1227
     */
1228
    protected function compValorServ($x = 0, $y = 0)
1229
    {
1230
        $oldX = $x;
1231
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1232
        if ($this->orientacao == 'P') {
1233
            $maxW = $this->wPrint;
1234
        } else {
1235
            $maxW = $this->wPrint - $this->wCanhoto;
1236
        }
1237
        $w = $maxW;
1238
        $h = 25;
1239
        $texto = 'COMPONENTES DO VALOR DA PRESTAÇÃO DO SERVIÇO';
1240
        $aFont = $this->formatPadrao;
1241
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1242
        $y += 3.4;
1243
        $this->pdf->line($x, $y, $w + 1, $y);
1244
        $texto = 'NOME';
1245
        $aFont = $this->formatPadrao;
1246
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1247
        $yIniDados = $y;
1248
        $x = $w * 0.14;
1249
        $texto = 'VALOR';
1250
        $aFont = $this->formatPadrao;
1251
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1252
        $x = $w * 0.28;
1253
        $this->pdf->line($x, $y, $x, $y + 21.5);
1254
        $texto = 'NOME';
1255
        $aFont = $this->formatPadrao;
1256
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1257
        $x = $w * 0.42;
1258
        $texto = 'VALOR';
1259
        $aFont = $this->formatPadrao;
1260
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1261
        $x = $w * 0.56;
1262
        $this->pdf->line($x, $y, $x, $y + 21.5);
1263
        $texto = 'NOME';
1264
        $aFont = $this->formatPadrao;
1265
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1266
        $x = $w * 0.70;
1267
        $texto = 'VALOR';
1268
        $aFont = $this->formatPadrao;
1269
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1270
        $x = $w * 0.86;
1271
        $this->pdf->line($x, $y, $x, $y + 21.5);
1272
        $y += 1;
1273
        $texto = 'VALOR TOTAL DO SERVIÇO';
1274
        $aFont = $this->formatPadrao;
1275
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1276
        $texto = number_format($this->getTagValue($this->vPrest, "vTPrest"), 2, ",", ".");
1277
        $aFont = array(
1278
            'font' => $this->fontePadrao,
1279
            'size' => 9,
1280
            'style' => 'B');
1281
        $this->pdf->textBox($x, $y + 4, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1282
        $y += 10;
1283
        $this->pdf->line($x, $y, $w + 1, $y);
1284
        $y += 1;
1285
        $texto = 'VALOR A RECEBER';
1286
        $aFont = $this->formatPadrao;
1287
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1288
        $texto = number_format($this->getTagValue($this->vPrest, "vRec"), 2, ",", ".");
1289
        $aFont = array(
1290
            'font' => $this->fontePadrao,
1291
            'size' => 9,
1292
            'style' => 'B');
1293
        $this->pdf->textBox($x, $y + 4, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1294
        $auxX = $oldX;
1295
        $yIniDados += 4;
1296
1297
        foreach ($this->Comp as $k => $d) {
1298
            $nome = $this->Comp->item($k)->getElementsByTagName('xNome')->item(0)->nodeValue;
1299
            $valor = number_format(
1300
                $this->Comp->item($k)->getElementsByTagName('vComp')->item(0)->nodeValue,
1301
                2,
1302
                ",",
1303
                "."
1304
            );
1305
            if ($auxX > $w * 0.60) {
1306
                $yIniDados = $yIniDados + 4;
1307
                $auxX = $oldX;
1308
            }
1309
            $texto = $nome;
1310
            $aFont = $this->formatPadrao;
1311
            $this->pdf->textBox($auxX, $yIniDados, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1312
            $auxX += $w * 0.14;
1313
            $texto = $valor;
1314
            $aFont = $this->formatPadrao;
1315
            $this->pdf->textBox($auxX, $yIniDados, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1316
            $auxX += $w * 0.14;
1317
        }
1318
    } //fim da função compValorDACTE
1319
1320
    /**
1321
     * impostos
1322
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1323
     *
1324
     * @param  number $x Posição horizontal canto esquerdo
1325
     * @param  number $y Posição vertical canto superior
1326
     * @return number Posição vertical final
1327
     */
1328
    protected function impostos($x = 0, $y = 0)
1329
    {
1330
        $oldX = $x;
1331
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1332
        if ($this->orientacao == 'P') {
1333
            $maxW = $this->wPrint;
1334
        } else {
1335
            $maxW = $this->wPrint - $this->wCanhoto;
1336
        }
1337
        $w = $maxW;
1338
        $h = 13;
1339
        $texto = 'INFORMAÇÕES RELATIVAS AO IMPOSTO';
1340
        $aFont = $this->formatPadrao;
1341
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1342
1343
        $y += 3.4;
1344
        $this->pdf->line($x, $y, $w + 1, $y);
1345
        $texto = 'SITUAÇÃO TRIBUTÁRIA';
1346
        $aFont = $this->formatPadrao;
1347
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1348
1349
        $x += $w * 0.26;
1350
        $this->pdf->line($x, $y, $x, $y + 9.5);
1351
        $texto = 'BASE DE CALCULO';
1352
        $aFont = $this->formatPadrao;
1353
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1354
1355
        $wCol02=0.18;
1356
        $x += $w * $wCol02;
1357
        $this->pdf->line($x, $y, $x, $y + 9.5);
1358
        $texto = 'ALÍQ ICMS';
1359
        $aFont = $this->formatPadrao;
1360
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1361
1362
        $x += $w * $wCol02;
1363
        $this->pdf->line($x, $y, $x, $y + 9.5);
1364
        $texto = 'VALOR ICMS';
1365
        $aFont = $this->formatPadrao;
1366
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1367
1368
        $x += $w * $wCol02;
1369
        $this->pdf->line($x, $y, $x, $y + 9.5);
1370
        $texto = '% RED. BC ICMS';
1371
        $aFont = $this->formatPadrao;
1372
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1373
1374
        /*$x += $w * 0.14;
1375
        $this->pdf->line($x, $y, $x, $y + 9.5);
1376
        $texto = 'ICMS ST';
1377
        $aFont = $this->formatPadrao;
1378
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1379
         * */
1380
1381
        $x = $oldX;
1382
        $y = $y + 4;
1383
        $texto = $this->getTagValue($this->ICMS, "CST");
1384
        switch ($texto) {
1385
            case '00':
1386
                $texto = "00 - Tributação normal ICMS";
1387
                break;
1388
            case '20':
1389
                $texto = "20 - Tributação com BC reduzida do ICMS";
1390
                break;
1391
            case '40':
1392
                $texto = "40 - ICMS isenção";
1393
                break;
1394
            case '41':
1395
                $texto = "41 - ICMS não tributada";
1396
                break;
1397
            case '51':
1398
                $texto = "51 - ICMS diferido";
1399
                break;
1400
            case '60':
1401
                $texto = "60 - ICMS cobrado anteriormente por substituição tributária";
1402
                break;
1403
            case '90':
1404
                $texto = "90 - ICMS outros";
1405
                break;
1406
        }
1407
        $texto = $this->getTagValue($this->ICMSSN, "indSN") == 1 ? 'Simples Nacional' : $texto;
1408
        $aFont = $this->formatNegrito;
1409
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1410
        $x += $w * 0.26;
1411
1412
        $texto = !empty($this->ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
1413
            number_format($this->getTagValue($this->ICMS, "vBC"), 2, ",", ".") : '';
1414
        $aFont = $this->formatNegrito;
1415
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1416
        $x += $w * $wCol02;
1417
1418
        $texto = !empty($this->ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
1419
            number_format($this->getTagValue($this->ICMS, "pICMS"), 2, ",", ".") : '';
1420
        $aFont = $this->formatNegrito;
1421
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1422
        $x += $w * $wCol02;
1423
1424
        $texto = !empty($this->ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
1425
            number_format($this->getTagValue($this->ICMS, "vICMS"), 2, ",", ".") : '';
1426
        $aFont = $this->formatNegrito;
1427
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1428
        $x += $w * $wCol02;
1429
1430
        $texto = !empty($this->ICMS->getElementsByTagName("pRedBC")->item(0)->nodeValue) ?
1431
            number_format($this->getTagValue($this->ICMS, "pRedBC"), 2, ",", ".").'%' :'';
1432
        $aFont = $this->formatNegrito;
1433
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1434
1435
        /*$x += $w * 0.14;
1436
        $texto = '';
1437
        $aFont = $this->formatNegrito;
1438
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');*/
1439
    } //fim da função compValorDACTE
1440
1441
    /**
1442
     * geraChaveAdicCont
1443
     *
1444
     * @return string chave
1445
     */
1446
    protected function geraChaveAdicCont()
1447
    {
1448
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
1449
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
1450
        $forma = "%02d%d%s%014d%01d%01d%02d";
1451
        $cUF = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
1452
        $CNPJ = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
1453
        $CNPJ = substr($CNPJ, -14);
1454
        $vCT = number_format($this->getTagValue($this->vPrest, "vRec"), 2, "", "") * 100;
1455
        $ICMS_CST = $this->getTagValue($this->ICMS, "CST");
1456
        switch ($ICMS_CST) {
1457
            case '00':
1458
            case '20':
1459
                $ICMSp = '1';
1460
                $ICMSs = '2';
1461
                break;
1462
            case '40':
1463
            case '41':
1464
            case '51':
1465
            case '90':
1466
                $ICMSp = '2';
1467
                $ICMSs = '2';
1468
                break;
1469
            case '60':
1470
                $ICMSp = '2';
1471
                $ICMSs = '1';
1472
                break;
1473
        }
1474
        $dd = $this->ide->getElementsByTagName('dEmi')->item(0)->nodeValue;
1475
        $rpos = strrpos($dd, '-');
1476
        $dd = substr($dd, $rpos + 1);
1477
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vCT, $ICMSp, $ICMSs, $dd);
0 ignored issues
show
Bug introduced by
The variable $ICMSp 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 $ICMSs 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...
1478
        $chave = $chave . $this->pModulo11($chave);
0 ignored issues
show
Bug introduced by
The method pModulo11() does not exist on NFePHP\DA\CTe\DacteOS. Did you maybe mean modulo11()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1479
        return $chave;
1480
    } //fim geraChaveAdicCont
1481
1482
    /**
1483
     * infPrestacaoServico
1484
     * Monta o campo com das informações da prestação do serviço
1485
     *
1486
     * @param  number $x Posição horizontal canto esquerdo
1487
     * @param  number $y Posição vertical canto superior
1488
     * @return number Posição vertical final
1489
     */
1490
    protected function infPrestacaoServico($x = 0, $y = 0)
1491
    {
1492
        $oldX = $x;
1493
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1494
        if ($this->orientacao == 'P') {
1495
            $maxW = $this->wPrint;
1496
        } else {
1497
            $maxW = $this->wPrint - $this->wCanhoto;
1498
        }
1499
        $w = $maxW;
1500
1501
        // SE FOR RODOVIARIO ( BTR-SEMPRE SERÁ )
1502
        if ($this->modal == '1') {
1503
            // 0 - Não; 1 - Sim Será lotação quando houver um único conhecimento de transporte por veículo,
1504
            // ou combinação veicular, e por viagem
1505
            $h = $this->lota == 1 ? 35 : 53;
1506
        } elseif ($this->modal == '3') {
1507
            $h = 37.6;
1508
        } else {
1509
            $h = 35;
1510
        }
1511
        $texto = 'INFORMAÇÕES DA PRESTAÇÃO DO SERVIÇO';
1512
        $aFont = $this->formatPadrao;
1513
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1514
        $descr1 = 'QUANTIDADE';
1515
        $descr2 = 'DESCRIÇÃO DO SERVIÇO PRESTADO';
1516
1517
        $y += 3.4;
1518
        $this->pdf->line($x, $y, $w + 1, $y); // LINHA ABAIXO DO TEXTO: "DOCUMENTOS ORIGINÁRIOS
1519
        $texto = $descr1;
1520
        $aFont = $this->formatPadrao;
1521
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1522
        $yIniDados = $y;
0 ignored issues
show
Unused Code introduced by
$yIniDados 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...
1523
1524
        $x += $w * 0.14;
1525
        if ($this->modal == '1') {
1526
            if ($this->lota == 1) {
1527
                $this->pdf->line($x, $y, $x, $y + 31.5); // TESTE
1528
            } else {
1529
                $this->pdf->line($x, $y, $x, $y + 49.5); // TESTE
1530
            }
1531
        } elseif ($this->modal == '3') {
1532
            $this->pdf->line($x, $y, $x, $y + 34.1);
1533
        } else {
1534
            $this->pdf->line($x, $y, $x, $y + 21.5);
1535
        }
1536
1537
        $x += $w * 0.08;
1538
        $texto = $descr2;
1539
        $aFont = $this->formatPadrao;
1540
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1541
1542
        //$auxX = $oldX;
1543
        //$yIniDados += 3;
1544
1545
        $x = $oldX;
1546
        $y = $y + 4;
1547
        $texto = number_format($this->getTagValue($this->infQ->item(0), "qCarga"), 3, ",", ".");
1548
        $aFont = $this->formatNegrito;
1549
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1550
        $x += $w * 0.26;
1551
1552
        $x = $oldX + 35;
1553
        $texto = $this->getTagValue($this->infServico->item(0), "xDescServ");
1554
        $aFont = $this->formatNegrito;
1555
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1556
        $x += $w * 0.26;
1557
1558
1559
        $r = $this->cabecalho(1, 1, '1', $this->totPag);
0 ignored issues
show
Unused Code introduced by
$r 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...
1560
        $contador = 0;
0 ignored issues
show
Unused Code introduced by
$contador 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...
1561
    }
1562
1563
    /**
1564
     * docCompl
1565
     * Monta o campo com os dados do remetente na DACTE.
1566
     *
1567
     * @param number $x Posição horizontal canto esquerdo
1568
     * @param number $y Posição vertical canto superior
1569
     * @return number Posição vertical final
1570
     */
1571
    protected function docCompl($x = 0, $y = 0)
1572
    {
1573
        $oldX = $x;
1574
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1575
        if ($this->orientacao == 'P') {
1576
            $maxW = $this->wPrint;
1577
        } else {
1578
            $maxW = $this->wPrint - $this->wCanhoto;
1579
        }
1580
        $w = $maxW;
1581
        $h = 80;
1582
        $texto = 'DETALHAMENTO DO CT-E COMPLEMENTADO';
1583
        $aFont = $this->formatPadrao;
1584
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1585
        $descr1 = 'CHAVE DO CT-E COMPLEMENTADO';
1586
        $descr2 = 'VALOR COMPLEMENTADO';
1587
        $y += 3.4;
1588
        $this->pdf->line($x, $y, $w + 1, $y);
1589
        $texto = $descr1;
1590
        $aFont = $this->formatPadrao;
1591
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1592
        $yIniDados = $y;
1593
        $x += $w * 0.37;
1594
        $texto = $descr2;
1595
        $aFont = $this->formatPadrao;
1596
        $this->pdf->textBox($x - 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1597
        $x += $w * 0.13;
1598
        $this->pdf->line($x, $y, $x, $y + 76.5);
1599
        $texto = $descr1;
1600
        $aFont = $this->formatPadrao;
1601
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1602
        $x += $w * 0.3;
1603
        $texto = $descr2;
1604
        $aFont = $this->formatPadrao;
1605
        $this->pdf->textBox($x + 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1606
        $auxX = $oldX;
1607
        $yIniDados += 4;
1608
        if ($auxX > $w * 0.90) {
1609
            $yIniDados = $yIniDados + 4;
1610
            $auxX = $oldX;
1611
        }
1612
        $texto = $this->chaveCTeRef;
1613
        $aFont = array(
1614
            'font' => $this->fontePadrao,
1615
            'size' => 8,
1616
            'style' => '');
1617
        $this->pdf->textBox($auxX, $yIniDados, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1618
        $texto = number_format($this->getTagValue($this->vPrest, "vTPrest"), 2, ",", ".");
1619
        $aFont = array(
1620
            'font' => $this->fontePadrao,
1621
            'size' => 8,
1622
            'style' => '');
1623
        $this->pdf->textBox($w * 0.40, $yIniDados, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1624
    }
1625
    
1626
    /**
1627
     * observacoes
1628
     * Monta o campo com os dados do remetente na DACTE.
1629
     *
1630
     * @param  number $x Posição horizontal canto esquerdo
1631
     * @param  number $y Posição vertical canto superior
1632
     * @return number Posição vertical final
1633
     */
1634
    protected function observacoes($x = 0, $y = 0)
1635
    {
1636
        $oldX = $x;
1637
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1638
        if ($this->orientacao == 'P') {
1639
            $maxW = $this->wPrint;
1640
        } else {
1641
            $maxW = $this->wPrint - $this->wCanhoto;
1642
        }
1643
        $w = $maxW;
1644
        //$h = 18;
1645
        $h = 18.8;
1646
        $texto = 'OBSERVAÇÕES GERAIS';
1647
        $aFont = $this->formatPadrao;
1648
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1649
        $y += 3.4;
1650
        $this->pdf->line($x, $y, $w + 1, $y);
1651
        $auxX = $oldX;
0 ignored issues
show
Unused Code introduced by
$auxX 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...
1652
        $yIniDados = $y;
0 ignored issues
show
Unused Code introduced by
$yIniDados 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...
1653
        $texto = '';
1654
        foreach ($this->compl as $k => $d) {
1655
            $xObs = $this->getTagValue($this->compl->item($k), "xObs");
1656
            $texto .= $xObs;
1657
        }
1658
        $textoObs = explode("Motorista:", $texto);
1659
        $textoObs[1] = isset($textoObs[1]) ? "Motorista: ".$textoObs[1]: '';
1660
        $texto .= $this->getTagValue($this->imp, "infAdFisco", "\r\n");
1661
        $aFont = array(
1662
            'font' => $this->fontePadrao,
1663
            'size' => 7.5,
1664
            'style' => '');
1665
        $this->pdf->textBox($x, $y, $w, $h, $textoObs[0], $aFont, 'T', 'L', 0, '', false);
1666
        $this->pdf->textBox($x, $y+11.5, $w, $h, $textoObs[1], $aFont, 'T', 'L', 0, '', false);
1667
    }
1668
1669
    /**
1670
     * seguro
1671
     * Monta o campo com os dados de seguro do CT-e OS.
1672
     *
1673
     * @param  number $x Posição horizontal canto esquerdo
1674
     * @param  number $y Posição vertical canto superior
1675
     * @return number Posição vertical final
1676
     */
1677
    protected function seguro($x = 0, $y = 0)
1678
    {
1679
        $oldX = $x;
1680
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1681
        if ($this->orientacao == 'P') {
1682
            $maxW = $this->wPrint;
1683
        } else {
1684
            $maxW = $this->wPrint - $this->wCanhoto;
1685
        }
1686
        $w = $maxW;
1687
        $h = 13;
1688
        $texto = 'SEGURO DA VIAGEM';
1689
        $aFont = $this->formatPadrao;
1690
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1691
1692
        $y += 3.4;
1693
        $this->pdf->line($x, $y, $w + 1, $y);
1694
        $texto = 'RESPONSÁVEL';
1695
        $aFont = $this->formatPadrao;
1696
        $this->pdf->textBox($x, $y, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
1697
1698
        $x += $w * 0.33;
1699
        $this->pdf->line($x, $y, $x, $y + 9.5);
1700
        $texto = 'NOME DA SEGURADORA';
1701
        $aFont = $this->formatPadrao;
1702
        $this->pdf->textBox($x, $y, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
1703
1704
        $wCol02=0.33;
1705
        $x += $w * $wCol02;
1706
        $this->pdf->line($x, $y, $x, $y + 9.5);
1707
        $texto = 'NÚMERO DA APÓLICE';
1708
        $aFont = $this->formatPadrao;
1709
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1710
1711
        $x = $oldX;
1712
        $y = $y + 4;
1713
        $texto = $this->respSeg;
1714
        $aFont = $this->formatNegrito;
1715
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1716
        $x += $w * 0.26;
1717
1718
        $texto = '';
1719
        $aFont = $this->formatNegrito;
1720
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1721
        $x += $w * $wCol02;
1722
1723
        $texto = '';
1724
        $aFont = $this->formatNegrito;
1725
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1726
        $x += $w * $wCol02;
1727
    }
1728
1729
    /**
1730
     * modalRod
1731
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1732
     *
1733
     * @param  number $x Posição horizontal canto esquerdo
1734
     * @param  number $y Posição vertical canto superior
1735
     * @return number Posição vertical final
1736
     */
1737
    protected function modalRod($x = 0, $y = 0)
1738
    {
1739
        $oldX = $x;
1740
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1741
        if ($this->orientacao == 'P') {
1742
            $maxW = $this->wPrint;
1743
        } else {
1744
            $maxW = $this->wPrint - $this->wCanhoto;
1745
        }
1746
        $w = $maxW;
1747
        $h = 13;
1748
        $texto = 'DADOS ESPECÍFICOS DO MODAL RODOVIÁRIO';
1749
        $aFont = $this->formatPadrao;
1750
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1751
1752
        $y += 3.4;
1753
        $this->pdf->line($x, $y, $w + 1, $y);
1754
        $texto = 'TERMO DE AUTORIZAÇÃO DE FRETAMENTO';
1755
        $aFont = $this->formatPadrao;
1756
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1757
1758
        $x += $w * 0.26;
1759
        $this->pdf->line($x, $y, $x, $y + 9.5);
1760
        $texto = 'Nº DE REGISTRO ESTADUAL';
1761
        $aFont = $this->formatPadrao;
1762
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1763
1764
        $wCol02=0.18;
1765
        $x += $w * $wCol02;
1766
        $this->pdf->line($x, $y, $x, $y + 9.5);
1767
        $texto = 'PLACA DO VEÍCULO';
1768
        $aFont = $this->formatPadrao;
1769
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1770
1771
        $x += $w * $wCol02;
1772
        $this->pdf->line($x, $y, $x, $y + 9.5);
1773
        $texto = 'RENAVAM DO VEÍCULO';
1774
        $aFont = $this->formatPadrao;
1775
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1776
1777
        $x += $w * $wCol02;
1778
        $this->pdf->line($x, $y, $x, $y + 9.5);
1779
        $texto = 'CNPJ/CPF';
1780
        $aFont = $this->formatPadrao;
1781
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1782
1783
        $x = $oldX;
1784
        $y = $y + 4;
1785
        $texto = $this->getTagValue($this->rodo, "TAF");
1786
        $aFont = $this->formatNegrito;
1787
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1788
        $x += $w * 0.26;
1789
1790
        $texto = $this->getTagValue($this->rodo, "NroRegEstadual");
1791
        $aFont = $this->formatNegrito;
1792
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1793
        $x += $w * $wCol02;
1794
1795
        $texto = $this->getTagValue($this->veic->item(0), "placa");
1796
        $aFont = $this->formatNegrito;
1797
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1798
        $x += $w * $wCol02;
1799
1800
        $texto = $this->getTagValue($this->veic->item(0), "RENAVAM");
1801
        $aFont = $this->formatNegrito;
1802
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1803
        $x += $w * $wCol02;
1804
1805
        $texto = !empty($this->getTagValue($this->veic->item(0), "CPF")) ?
1806
            $this->getTagValue($this->veic->item(0), "CPF") :
1807
            (!empty($this->getTagValue($this->veic->item(0), "CNPJ")) ?
1808
            $this->getTagValue($this->veic->item(0), "CNPJ") : '');
1809
        $aFont = $this->formatNegrito;
1810
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1811
1812
        /*$x += $w * 0.14;
1813
        $texto = '';
1814
        $aFont = $this->formatNegrito;
1815
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');*/
1816
    }
1817
1818
    /**
1819
     * modalAquaviario
1820
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1821
     *
1822
     * @param  number $x Posição horizontal canto esquerdo
1823
     * @param  number $y Posição vertical canto superior
1824
     * @return number Posição vertical final
1825
     */
1826
    protected function modalAquaviario($x = 0, $y = 0)
1827
    {
1828
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX 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...
1829
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
1830
        if ($this->orientacao == 'P') {
1831
            $maxW = $this->wPrint;
1832
        } else {
1833
            $maxW = $this->wPrint - $this->wCanhoto;
1834
        }
1835
        $w = $maxW;
1836
        $h = 8.5;
1837
        $texto = 'DADOS ESPECÍFICOS DO MODAL AQUAVIÁRIO';
1838
        $aFont = $this->formatPadrao;
1839
        $this->pdf->textBox($x, $y, $w, $h * 3.2, $texto, $aFont, 'T', 'C', 1, '');
1840
        $y += 3.4;
1841
        $this->pdf->line($x, $y, $w + 1, $y);
1842
        $texto = 'PORTO DE EMBARQUE';
1843
        $aFont = $this->formatPadrao;
1844
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1845
        $texto = $this->getTagValue($this->aquav, "prtEmb");
1846
        $aFont = $this->formatNegrito;
1847
        $this->pdf->textBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1848
        $x += $w * 0.50;
1849
        $this->pdf->line($x, $y, $x, $y + 7.7);
1850
        $texto = 'PORTO DE DESTINO';
1851
        $aFont = $this->formatPadrao;
1852
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1853
        $texto = $this->getTagValue($this->aquav, "prtDest");
1854
        $aFont = $this->formatNegrito;
1855
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1856
        $y += 8;
1857
        $this->pdf->line(208, $y, 1, $y);
1858
        $x = 1;
1859
        $texto = 'IDENTIFICAÇÃO DO NAVIO / REBOCADOR';
1860
        $aFont = $this->formatPadrao;
1861
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1862
        $texto = $this->getTagValue($this->aquav, "xNavio");
1863
        $aFont = $this->formatNegrito;
1864
        $this->pdf->textBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1865
        $x += $w * 0.50;
1866
        $this->pdf->line($x, $y, $x, $y + 7.7);
1867
        $texto = 'VR DA B. DE CALC. AFRMM';
1868
        $aFont = $this->formatPadrao;
1869
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1870
        $texto = $this->getTagValue($this->aquav, "vPrest");
1871
        $aFont = $this->formatNegrito;
1872
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1873
        $x += $w * 0.17;
1874
        $this->pdf->line($x, $y, $x, $y + 7.7);
1875
        $texto = 'VALOR DO AFRMM';
1876
        $aFont = $this->formatPadrao;
1877
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1878
        $texto = $this->getTagValue($this->aquav, "vAFRMM");
1879
        $aFont = $this->formatNegrito;
1880
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1881
        $x += $w * 0.12;
1882
        $this->pdf->line($x, $y, $x, $y + 7.7);
1883
        $texto = 'TIPO DE NAVEGAÇÃO';
1884
        $aFont = $this->formatPadrao;
1885
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1886
        $texto = $this->getTagValue($this->aquav, "tpNav");
1887
        switch ($texto) {
1888
            case '0':
1889
                $texto = 'INTERIOR';
1890
                break;
1891
            case '1':
1892
                $texto = 'CABOTAGEM';
1893
                break;
1894
        }
1895
        $aFont = $this->formatNegrito;
1896
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1897
        $x += $w * 0.14;
1898
        $this->pdf->line($x, $y, $x, $y + 7.7);
1899
        $texto = 'DIREÇÃO';
1900
        $aFont = $this->formatPadrao;
1901
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1902
        $texto = $this->getTagValue($this->aquav, "direc");
1903
        switch ($texto) {
1904
            case 'N':
1905
                $texto = 'NORTE';
1906
                break;
1907
            case 'L':
1908
                $texto = 'LESTE';
1909
                break;
1910
            case 'S':
1911
                $texto = 'SUL';
1912
                break;
1913
            case 'O':
1914
                $texto = 'OESTE';
1915
                break;
1916
        }
1917
        $aFont = $this->formatNegrito;
1918
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1919
        $y += 8;
1920
        $this->pdf->line(208, $y, 1, $y);
1921
        $x = 1;
1922
        $texto = 'IDENTIFICAÇÃO DOS CONTEINERS';
1923
        $aFont = $this->formatPadrao;
1924
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1925
        if ($this->infNF->item(0) !== null && $this->infNF->item(0)->getElementsByTagName('infUnidCarga') !== null) {
1926
            $texto = $this->infNF
1927
                ->item(0)
1928
                ->getElementsByTagName('infUnidCarga')
1929
                ->item(0)
1930
                ->getElementsByTagName('idUnidCarga')
1931
                ->item(0)->nodeValue;
1932
        } elseif ($this->infNFe->item(0) !== null
1933
            && $this->infNFe->item(0)->getElementsByTagName('infUnidCarga') !== null
1934
        ) {
1935
            $texto = $this->infNFe
1936
                ->item(0)
1937
                ->getElementsByTagName('infUnidCarga')
1938
                ->item(0)
1939
                ->getElementsByTagName('idUnidCarga')
1940
                ->item(0)
1941
                ->nodeValue;
1942
        } elseif ($this->infOutros->item(0) !== null
1943
            && $this->infOutros->item(0)->getElementsByTagName('infUnidCarga') !== null
1944
        ) {
1945
            $texto = $this->infOutros
1946
                ->item(0)
1947
                ->getElementsByTagName('infUnidCarga')
1948
                ->item(0)
1949
                ->getElementsByTagName('idUnidCarga')
1950
                ->item(0)
1951
                ->nodeValue;
1952
        } else {
1953
            $texto = '';
1954
        }
1955
        $aFont = $this->formatNegrito;
1956
        $this->pdf->textBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1957
        $x += $w * 0.50;
1958
        $this->pdf->line($x, $y, $x, $y + 7.7);
1959
        $texto = 'IDENTIFICAÇÃO DAS BALSAS';
1960
        $aFont = $this->formatPadrao;
1961
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1962
        $texto = '';
1963
        if ($this->getTagValue($this->aquav, "balsa") !== '') {
1964
            foreach ($this->aquav->getElementsByTagName('balsa') as $k => $d) {
1965
                if ($k == 0) {
1966
                    $texto = $this->aquav
1967
                        ->getElementsByTagName('balsa')
1968
                        ->item($k)
1969
                        ->getElementsByTagName('xBalsa')
1970
                        ->item(0)
1971
                        ->nodeValue;
1972
                } else {
1973
                    $texto = $texto
1974
                        . ' / '
1975
                        . $this->aquav
1976
                            ->getElementsByTagName('balsa')
1977
                            ->item($k)
1978
                            ->getElementsByTagName('xBalsa')
1979
                            ->item(0)
1980
                            ->nodeValue;
1981
                }
1982
            }
1983
        }
1984
        $aFont = $this->formatNegrito;
1985
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1986
    }
1987
1988
    /**
1989
     * modalFerr
1990
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1991
     *
1992
     * @param  number $x Posição horizontal canto esquerdo
1993
     * @param  number $y Posição vertical canto superior
1994
     * @return number Posição vertical final
1995
     */
1996
    protected function modalFerr($x = 0, $y = 0)
1997
    {
1998
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX 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...
1999
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
2000
        if ($this->orientacao == 'P') {
2001
            $maxW = $this->wPrint;
2002
        } else {
2003
            $maxW = $this->wPrint - $this->wCanhoto;
2004
        }
2005
        $w = $maxW;
2006
        $h = 19.6;
2007
        $texto = 'DADOS ESPECÍFICOS DO MODAL FERROVIÁRIO';
2008
        $aFont = $this->formatPadrao;
2009
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2010
        $y += 3.4;
2011
        $this->pdf->line($x, $y, $w + 1, $y);
2012
        $texto = 'DCL';
2013
        $aFont = array(
2014
            'font' => $this->fontePadrao,
2015
            'size' => 7,
2016
            'style' => 'B');
2017
        $this->pdf->textBox($x, $y, $w * 0.25, $h, $texto, $aFont, 'T', 'C', 0, '');
2018
        $this->pdf->line($x + 49.6, $y, $x + 49.6, $y + 3.5);
2019
        $texto = 'VAGÕES';
2020
        $aFont = array(
2021
            'font' => $this->fontePadrao,
2022
            'size' => 7,
2023
            'style' => 'B');
2024
        $this->pdf->textBox($x + 50, $y, $w * 0.5, $h, $texto, $aFont, 'T', 'C', 0, '');
2025
        $y += 3.4;
2026
        $this->pdf->line($x, $y, $w + 1, $y);
2027
        // DCL
2028
        $texto = 'ID TREM';
2029
        $aFont = array(
2030
            'font' => $this->fontePadrao,
2031
            'size' => 6,
2032
            'style' => '');
2033
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2034
        $texto = $this->getTagValue($this->ferrov, "idTrem");
2035
        $aFont = array(
2036
            'font' => $this->fontePadrao,
2037
            'size' => 6,
2038
            'style' => 'B');
2039
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2040
        $x += $w * 0.06;
2041
        $y1 = $y + 12.5;
2042
        $this->pdf->line($x, $y, $x, $y1);
2043
        $texto = 'NUM';
2044
        $aFont = array(
2045
            'font' => $this->fontePadrao,
2046
            'size' => 6,
2047
            'style' => '');
2048
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2049
        $texto = $this->getTagValue($this->rem, "nDoc");
0 ignored issues
show
Bug introduced by
The property rem does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
2050
        $aFont = array(
2051
            'font' => $this->fontePadrao,
2052
            'size' => 6,
2053
            'style' => 'B');
2054
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2055
        $x += $w * 0.06;
2056
        $this->pdf->line($x, $y, $x, $y1);
2057
        $texto = 'SÉRIE';
2058
        $aFont = array(
2059
            'font' => $this->fontePadrao,
2060
            'size' => 6,
2061
            'style' => '');
2062
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2063
        $texto = $this->getTagValue($this->rem, "serie");
2064
        $aFont = array(
2065
            'font' => $this->fontePadrao,
2066
            'size' => 6,
2067
            'style' => 'B');
2068
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2069
        $x += $w * 0.06;
2070
        $this->pdf->line($x, $y, $x, $y1);
2071
        $texto = 'EMISSÃO';
2072
        $aFont = array(
2073
            'font' => $this->fontePadrao,
2074
            'size' => 6,
2075
            'style' => '');
2076
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2077
        $texto = $this->pYmd2dmy($this->getTagValue($this->rem, "dEmi"));
0 ignored issues
show
Bug introduced by
The method pYmd2dmy() does not seem to exist on object<NFePHP\DA\CTe\DacteOS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2078
        $aFont = array(
2079
            'font' => $this->fontePadrao,
2080
            'size' => 6,
2081
            'style' => 'B');
2082
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2083
        // VAGOES
2084
        $x += $w * 0.06;
2085
        $this->pdf->line($x, $y, $x, $y1);
2086
        $texto = 'NUM';
2087
        $aFont = array(
2088
            'font' => $this->fontePadrao,
2089
            'size' => 6,
2090
            'style' => '');
2091
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2092
        $texto = $this->getTagValue($this->ferrov, "nVag");
2093
        $aFont = array(
2094
            'font' => $this->fontePadrao,
2095
            'size' => 6,
2096
            'style' => 'B');
2097
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2098
        $x += $w * 0.06;
2099
        $this->pdf->line($x, $y, $x, $y1);
2100
        $texto = 'TIPO';
2101
        $aFont = array(
2102
            'font' => $this->fontePadrao,
2103
            'size' => 6,
2104
            'style' => '');
2105
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2106
        $texto = $this->getTagValue($this->ferrov, "tpVag");
2107
        $aFont = array(
2108
            'font' => $this->fontePadrao,
2109
            'size' => 6,
2110
            'style' => 'B');
2111
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2112
        $x += $w * 0.06;
2113
        $this->pdf->line($x, $y, $x, $y1);
2114
        $texto = 'CAPACIDADE';
2115
        $aFont = array(
2116
            'font' => $this->fontePadrao,
2117
            'size' => 6,
2118
            'style' => '');
2119
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2120
        $texto = $this->getTagValue($this->ferrov, "cap");
2121
        $aFont = array(
2122
            'font' => $this->fontePadrao,
2123
            'size' => 6,
2124
            'style' => 'B');
2125
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2126
        $x += $w * 0.08;
2127
        $this->pdf->line($x, $y, $x, $y1);
2128
        $texto = 'PESO REAL/TON';
2129
        $aFont = array(
2130
            'font' => $this->fontePadrao,
2131
            'size' => 6,
2132
            'style' => '');
2133
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2134
        $texto = $this->getTagValue($this->ferrov, "pesoR");
2135
        $aFont = array(
2136
            'font' => $this->fontePadrao,
2137
            'size' => 6,
2138
            'style' => 'B');
2139
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2140
        $x += $w * 0.09;
2141
        $this->pdf->line($x, $y, $x, $y1);
2142
        $texto = 'PESO BRUTO/TON';
2143
        $aFont = array(
2144
            'font' => $this->fontePadrao,
2145
            'size' => 6,
2146
            'style' => '');
2147
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2148
        $texto = $this->getTagValue($this->ferrov, "pesoBC");
2149
        $aFont = array(
2150
            'font' => $this->fontePadrao,
2151
            'size' => 6,
2152
            'style' => 'B');
2153
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2154
        $x += $w * 0.1;
2155
        $this->pdf->line($x, $y, $x, $y1);
2156
        $texto = 'IDENTIFICAÇÃO DOS CONTÊINERES';
2157
        $aFont = array(
2158
            'font' => $this->fontePadrao,
2159
            'size' => 6,
2160
            'style' => '');
2161
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2162
        $texto = $this->getTagValue($this->ferrov, "nCont");
2163
        $aFont = array(
2164
            'font' => $this->fontePadrao,
2165
            'size' => 6,
2166
            'style' => 'B');
2167
        $this->pdf->textBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2168
        // FLUXO
2169
        $x = 1;
2170
        $y += 12.9;
2171
        $h1 = $h * 0.5 + 0.27;
2172
        $wa = round($w * 0.103) + 0.5;
2173
        $texto = 'FLUXO FERROVIARIO';
2174
        $aFont = $this->formatPadrao;
2175
        $this->pdf->textBox($x, $y, $wa, $h1, $texto, $aFont, 'T', 'C', 1, '');
2176
        $texto = $this->getTagValue($this->ferrov, "fluxo");
2177
        $aFont = array(
2178
            'font' => $this->fontePadrao,
2179
            'size' => 7,
2180
            'style' => 'B');
2181
        $this->pdf->textBox($x, $y + 3, $wa, $h1, $texto, $aFont, 'T', 'C', 0, '');
2182
        $y += 10;
2183
        $texto = 'TIPO DE TRÁFEGO';
2184
        $aFont = $this->formatPadrao;
2185
        $this->pdf->textBox($x, $y, $wa, $h1, $texto, $aFont, 'T', 'C', 1, '');
2186
        $texto = $this->convertUnidTrafego($this->getTagValue($this->ferrov, "tpTraf"));
2187
        $aFont = array(
2188
            'font' => $this->fontePadrao,
2189
            'size' => 7,
2190
            'style' => 'B');
2191
        $this->pdf->textBox($x, $y + 3, $wa, $h1, $texto, $aFont, 'T', 'C', 0, '');
2192
        // Novo Box Relativo a Modal Ferroviário
2193
        $x = 22.5;
2194
        $y += -10.2;
2195
        $texto = 'INFORMAÇÕES DAS FERROVIAS ENVOLVIDAS';
2196
        $aFont = $this->formatPadrao;
2197
        $this->pdf->textBox($x, $y, $w - 21.5, $h1 * 2.019, $texto, $aFont, 'T', 'C', 1, '');
2198
        $y += 3.4;
2199
        $this->pdf->line($x, $y, $w + 1, $y);
2200
        $w = $w * 0.2;
2201
        $h = $h * 1.04;
2202
        $texto = 'CÓDIGO INTERNO';
2203
        $aFont = array(
2204
            'font' => $this->fontePadrao,
2205
            'size' => 6,
2206
            'style' => '');
2207
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2208
        $texto = $this->getTagValue($this->ferrov, "cInt");
2209
        $aFont = array(
2210
            'font' => $this->fontePadrao,
2211
            'size' => 6,
2212
            'style' => 'B');
2213
        $this->pdf->textBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2214
        $texto = 'CNPJ';
2215
        $aFont = array(
2216
            'font' => $this->fontePadrao,
2217
            'size' => 6,
2218
            'style' => '');
2219
        $this->pdf->textBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2220
        $texto = $this->getTagValue($this->ferrov, "CNPJ");
2221
        $aFont = array(
2222
            'font' => $this->fontePadrao,
2223
            'size' => 6,
2224
            'style' => 'B');
2225
        $this->pdf->textBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2226
        $x += 50;
2227
        $texto = 'NOME';
2228
        $aFont = array(
2229
            'font' => $this->fontePadrao,
2230
            'size' => 6,
2231
            'style' => '');
2232
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2233
        $texto = $this->getTagValue($this->ferrov, "xNome");
2234
        $aFont = array(
2235
            'font' => $this->fontePadrao,
2236
            'size' => 6,
2237
            'style' => 'B');
2238
        $this->pdf->textBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2239
        $texto = 'INSCRICAO ESTADUAL';
2240
        $aFont = array(
2241
            'font' => $this->fontePadrao,
2242
            'size' => 6,
2243
            'style' => '');
2244
        $this->pdf->textBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2245
        $texto = $this->getTagValue($this->ferrov, "IE");
2246
        $aFont = array(
2247
            'font' => $this->fontePadrao,
2248
            'size' => 6,
2249
            'style' => 'B');
2250
        $this->pdf->textBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2251
        $x += 50;
2252
        $texto = 'PARTICIPAÇÃO OUTRA FERROVIA';
2253
        $aFont = array(
2254
            'font' => $this->fontePadrao,
2255
            'size' => 6,
2256
            'style' => '');
2257
        $this->pdf->textBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2258
        $texto = '';
2259
        $aFont = array(
2260
            'font' => $this->fontePadrao,
2261
            'size' => 6,
2262
            'style' => 'B');
2263
        $this->pdf->textBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2264
    }
2265
2266
    /**
2267
     * canhoto
2268
     * Monta o campo com os dados do remetente na DACTE.
2269
     *
2270
     * @param  number $x Posição horizontal canto esquerdo
2271
     * @param  number $y Posição vertical canto superior
2272
     * @return number Posição vertical final
2273
     */
2274
    protected function canhoto($x = 0, $y = 0)
2275
    {
2276
        $this->pdf->dashedHLine($x, $y+2, $this->wPrint, 0.1, 80);
2277
        $y = $y + 2;
2278
        $oldX = $x;
2279
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY 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...
2280
        if ($this->orientacao == 'P') {
2281
            $maxW = $this->wPrint;
2282
        } else {
2283
            $maxW = $this->wPrint - $this->wCanhoto;
2284
        }
2285
        $w = $maxW - 1;
2286
        $h = 20;
2287
        $y = $y + 1;
2288
        $texto = 'DECLARO QUE RECEBI OS VOLUMES DESTE CONHECIMENTO EM PERFEITO ESTADO ';
2289
        $texto .= 'PELO QUE DOU POR CUMPRIDO O PRESENTE CONTRATO DE TRANSPORTE';
2290
        $aFont = $this->formatPadrao;
2291
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2292
        $y += 3.4;
2293
        $this->pdf->line($x, $y, $w + 1, $y); // LINHA ABAICO DO TEXTO DECLARO QUE RECEBI...
2294
2295
        $texto = 'NOME';
2296
        $aFont = array(
2297
            'font' => $this->fontePadrao,
2298
            'size' => 6,
2299
            'style' => '');
2300
        $this->pdf->textBox($x, $y, $w * 0.25, $h, $texto, $aFont, 'T', 'L', 0, '');
2301
        $x += $w * 0.25;
2302
2303
        $this->pdf->line($x, $y, $x, $y + 16.5);
2304
2305
        $texto = 'ASSINATURA / CARIMBO';
2306
        $aFont = array(
2307
            'font' => $this->fontePadrao,
2308
            'size' => 6,
2309
            'style' => '');
2310
        $this->pdf->textBox($x, $y, $w * 0.25, $h - 3.4, $texto, $aFont, 'B', 'C', 0, '');
2311
        $x += $w * 0.25;
2312
2313
        $this->pdf->line($x, $y, $x, $y + 16.5);
2314
2315
        $texto = 'TÉRMINO DA PRESTAÇÃO - DATA/HORA' . "\r\n" . "\r\n" . "\r\n". "\r\n";
2316
        $texto .= ' INÍCIO DA PRESTAÇÃO - DATA/HORA';
2317
        $aFont = array(
2318
            'font' => $this->fontePadrao,
2319
            'size' => 6,
2320
            'style' => '');
2321
        $this->pdf->textBox($x + 10, $y, $w * 0.25, $h - 3.4, $texto, $aFont, 'T', 'C', 0, '');
2322
        $x = $oldX;
2323
        $y = $y + 5;
2324
2325
        $this->pdf->line($x, $y+3, $w * 0.255, $y+3); // LINHA HORIZONTAL ACIMA DO RG ABAIXO DO NOME
2326
2327
        $texto = 'RG';
2328
        $aFont = array(
2329
            'font' => $this->fontePadrao,
2330
            'size' => 6,
2331
            'style' => '');
2332
        $this->pdf->textBox($x, $y+3, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
2333
        $x += $w * 0.85;
2334
2335
        $this->pdf->line($x, $y + 11.5, $x, $y - 5); // LINHA VERTICAL PROXIMO AO CT-E
2336
2337
        $texto = "CT-E OS";
2338
        $aFont = $this->formatNegrito;
2339
        $this->pdf->textBox($x, $y - 5, $w * 0.15, $h, $texto, $aFont, 'T', 'C', 0, '');
2340
        $texto = "\r\n Nº. DOCUMENTO  " . $this->getTagValue($this->ide, "nCT") . " \n";
2341
        $texto .= "\r\n SÉRIE  " . $this->getTagValue($this->ide, "serie");
2342
        $aFont = array(
2343
            'font' => $this->fontePadrao,
2344
            'size' => 6,
2345
            'style' => '');
2346
        $this->pdf->textBox($x, $y - 8, $w * 0.15, $h, $texto, $aFont, 'C', 'C', 0, '');
2347
        $x = $oldX;
0 ignored issues
show
Unused Code introduced by
$x 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...
2348
    }
2349
2350
    /**
2351
     * dadosAdic
2352
     * Coloca o grupo de dados adicionais da DACTE.
2353
     *
2354
     * @param  number $x Posição horizontal canto esquerdo
2355
     * @param  number $y Posição vertical canto superior
2356
     * @param  number $h altura do campo
2357
     * @return number Posição vertical final
2358
     */
2359
    protected function dadosAdic($x, $y, $pag, $h)
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...
Unused Code introduced by
The parameter $h 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...
2360
    {
2361
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX 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...
2362
        //###########################################################################
2363
        //DADOS ADICIONAIS DACTE
2364
        if ($this->orientacao == 'P') {
2365
            $w = $this->wPrint;
0 ignored issues
show
Unused Code introduced by
$w 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...
2366
        } else {
2367
            $w = $this->wPrint - $this->wCanhoto;
0 ignored issues
show
Unused Code introduced by
$w 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...
2368
        }
2369
        //INFORMAÇÕES COMPLEMENTARES
2370
        $texto = "USO EXCLUSIVO DO EMISSOR DO CT-E";
2371
        $y += 3;
2372
        $w = $this->wAdic;
2373
        $h = 20; //mudar
2374
        $aFont = array(
2375
            'font' => $this->fontePadrao,
2376
            'size' => 6,
2377
            'style' => '');
2378
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2379
        //$this->pdf->line($x, $y + 3, $w * 1.385, $y + 3);
2380
        $this->pdf->line($x, $y + 3, $w * 1.385, $y + 3);
2381
        //o texto com os dados adicionais foi obtido na função xxxxxx
2382
        //e carregado em uma propriedade privada da classe
2383
        //$this->wAdic com a largura do campo
2384
        //$this->textoAdic com o texto completo do campo
2385
        $y += 1;
2386
        $aFont = $this->formatPadrao;
2387
        $this->pdf->textBox($x, $y + 3, $w - 2, $h - 3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2388
        //RESERVADO AO FISCO
2389
        $texto = "RESERVADO AO FISCO";
2390
        $x += $w;
2391
        $y -= 1;
2392
        if ($this->orientacao == 'P') {
2393
            $w = $this->wPrint - $w;
2394
        } else {
2395
            $w = $this->wPrint - $w - $this->wCanhoto;
2396
        }
2397
        $aFont = array(
2398
            'font' => $this->fontePadrao,
2399
            'size' => 6,
2400
            'style' => '');
2401
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2402
        //inserir texto informando caso de contingência
2403
        //1 – Normal – emissão normal;
2404
        //2 – Contingência FS – emissão em contingência com impressão do DACTE em Formulário de Segurança;
2405
        //3 – Contingência SCAN – emissão em contingência  – SCAN;
2406
        //4 – Contingência DPEC - emissão em contingência com envio da Declaração Prévia de
2407
        //Emissão em Contingência – DPEC;
2408
        //5 – Contingência FS-DA - emissão em contingência com impressão do DACTE em Formulário de
2409
        //Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA).
2410
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
2411
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2412
        $texto = '';
2413
        switch ($this->tpEmis) {
2414
            case 2:
2415
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2416
                break;
2417
            case 3:
2418
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2419
                break;
2420
            case 4:
2421
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2422
                break;
2423
            case 5:
2424
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2425
                break;
2426
        }
2427
        $y += 2;
2428
        $aFont = $this->formatPadrao;
2429
        $this->pdf->textBox($x, $y + 2, $w - 2, $h - 3, $texto, $aFont, 'T', 'L', 0, '', false);
2430
        return $y + $h;
2431
    }
2432
2433
    /**
2434
     * formatCNPJCPF
2435
     * Formata campo CnpjCpf contida na CTe
2436
     *
2437
     * @param  string $field campo cnpjCpf da CT-e
2438
     * @return string
2439
     */
2440
    protected function formatCNPJCPF($field)
2441
    {
2442
        if (!isset($field)) {
2443
            return '';
2444
        }
2445
        $cnpj = !empty($field->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
0 ignored issues
show
Bug introduced by
The method getElementsByTagName cannot be called on $field (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
2446
            $field->getElementsByTagName("CNPJ")->item(0)->nodeValue : "";
0 ignored issues
show
Bug introduced by
The method getElementsByTagName cannot be called on $field (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
2447
        if ($cnpj != "" && $cnpj != "00000000000000") {
2448
            $cnpj = $this->formatField($cnpj, '###.###.###/####-##');
2449
        } else {
2450
            $cnpj = !empty($field->getElementsByTagName("CPF")->item(0)->nodeValue) ?
0 ignored issues
show
Bug introduced by
The method getElementsByTagName cannot be called on $field (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
2451
                $this->formatField($field->getElementsByTagName("CPF")->item(0)->nodeValue, '###.###.###.###-##') : '';
0 ignored issues
show
Bug introduced by
The method getElementsByTagName cannot be called on $field (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
2452
        }
2453
        return $cnpj;
2454
    }
2455
2456
    /**
2457
     * formatFone
2458
     * Formata campo fone contida na CTe
2459
     *
2460
     * @param  string $field campo fone da CT-e
2461
     * @return string
2462
     */
2463
    protected function formatFone($field)
2464
    {
2465
        try {
2466
            $fone = !empty($field->getElementsByTagName("fone")->item(0)->nodeValue) ?
0 ignored issues
show
Bug introduced by
The method getElementsByTagName cannot be called on $field (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
2467
            $field->getElementsByTagName("fone")->item(0)->nodeValue : '';
0 ignored issues
show
Bug introduced by
The method getElementsByTagName cannot be called on $field (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
2468
            $foneLen = strlen($fone);
2469
            if ($foneLen > 0) {
2470
                $fone2 = substr($fone, 0, $foneLen - 4);
2471
                $fone1 = substr($fone, 0, $foneLen - 8);
2472
                $fone = '(' . $fone1 . ') ' . substr($fone2, -4) . '-' . substr($fone, -4);
2473
            } else {
2474
                $fone = '';
2475
            }
2476
            return $fone;
2477
        } catch (Exception $exc) {
2478
            return '';
2479
        }
2480
    }
2481
2482
    /**
2483
     * unidade
2484
     * Converte a imformação de peso contida na CTe
2485
     *
2486
     * @param  string $c unidade de trafego extraida da CTe
2487
     * @return string
2488
     */
2489
    protected function unidade($c = '')
2490
    {
2491
        switch ($c) {
2492
            case '00':
2493
                $r = 'M3';
2494
                break;
2495
            case '01':
2496
                $r = 'KG';
2497
                break;
2498
            case '02':
2499
                $r = 'TON';
2500
                break;
2501
            case '03':
2502
                $r = 'UN';
2503
                break;
2504
            case '04':
2505
                $r = 'LT';
2506
                break;
2507
            case '05':
2508
                $r = 'MMBTU';
2509
                break;
2510
            default:
2511
                $r = '';
2512
        }
2513
        return $r;
2514
    }
2515
2516
    /**
2517
     * convertUnidTrafego
2518
     * Converte a imformação de peso contida na CTe
2519
     *
2520
     * @param  string $U Informação de trafego extraida da CTe
2521
     * @return string
2522
     */
2523
    protected function convertUnidTrafego($U = '')
2524
    {
2525
        if ($U) {
2526
            switch ($U) {
2527
                case '0':
2528
                    $stringU = 'Próprio';
2529
                    break;
2530
                case '1':
2531
                    $stringU = 'Mútuo';
2532
                    break;
2533
                case '2':
2534
                    $stringU = 'Rodoferroviário';
2535
                    break;
2536
                case '3':
2537
                    $stringU = 'Rodoviário';
2538
                    break;
2539
            }
2540
            return $stringU;
0 ignored issues
show
Bug introduced by
The variable $stringU 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...
2541
        }
2542
    }
2543
2544
    /**
2545
     * multiUniPeso
2546
     * Fornece a imformação multiplicação de peso contida na CTe
2547
     *
2548
     * @param  interger $U Informação de peso extraida da CTe
2549
     * @return interger
2550
     */
2551
    protected function multiUniPeso($U = '')
2552
    {
2553
        if ($U === "01") {
2554
            // tonelada
2555
            //return 1000;
2556
            return 1;
2557
        }
2558
        return 1; // M3, KG, Unidade, litros, mmbtu
2559
    }
2560
2561
    protected function qrCodeDacteOs($y = 0)
2562
    {
2563
        $margemInterna = $this->margemInterna;
2564
        $barcode = new Barcode();
2565
        $bobj = $barcode->getBarcodeObj(
2566
            'QRCODE,M',
2567
            $this->qrCodMDFe,
2568
            -4,
2569
            -4,
2570
            'black',
2571
            array(-1, -1, -1, -1)
2572
        )->setBackgroundColor('white');
2573
        $qrcode = $bobj->getPngData();
2574
        $wQr = 36;
2575
        $hQr = 36;
2576
        $yQr = ($y + $margemInterna);
2577
        if ($this->orientacao == 'P') {
2578
            $xQr = 170;
2579
        } else {
2580
            $xQr = 250;
2581
        }
2582
        // prepare a base64 encoded "data url"
2583
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
2584
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
2585
    }
2586
}
2587