Passed
Push — master ( 34eb59...4cb500 )
by Roberto
01:30
created

DacteOSV3::zDadosAdic()   C

Complexity

Conditions 7
Paths 20

Size

Total Lines 73
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 51
nc 20
nop 4
dl 0
loc 73
ccs 0
cts 56
cp 0
crap 56
rs 6.6896
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-2016 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 Exception;
19
use NFePHP\Common\Dom\Dom;
20
use NFePHP\DA\Legacy\Pdf;
21
use NFePHP\DA\Legacy\Common;
22
23
class DacteOSV3 extends Common
24
{
25
    const NFEPHP_SITUACAO_EXTERNA_CANCELADA = 1;
26
    const NFEPHP_SITUACAO_EXTERNA_DENEGADA = 2;
27
    const SIT_DPEC = 3;
28
29
    protected $logoAlign = 'C';
30
    protected $yDados = 0;
31
    protected $situacao_externa = 0;
32
    protected $numero_registro_dpec = '';
33
    protected $pdf;
34
    protected $xml;
35
    protected $logomarca = '';
36
    protected $errMsg = '';
37
    protected $errStatus = false;
38
    protected $orientacao = 'P';
39
    protected $papel = 'A4';
40
    protected $destino = 'I';
41
    protected $pdfDir = '';
42
    protected $fontePadrao = 'Times';
43
    protected $version = '1.3.0';
44
    protected $wPrint;
45
    protected $hPrint;
46
    protected $dom;
47
    protected $infCte;
48
    protected $infPercurso;
49
    protected $infCteComp;
50
    protected $chaveCTeRef;
51
    protected $tpCTe;
52
    protected $ide;
53
    protected $emit;
54
    protected $enderEmit;
55
    protected $infCarga;
56
    protected $infQ;
57
    protected $seg;
58
    protected $modal;
59
    protected $rodo;
60
    protected $moto;
61
    protected $veic;
62
    protected $ferrov;
63
    protected $Comp;
64
    protected $infNF;
65
    protected $infNFe;
66
    protected $compl;
67
    protected $ICMS;
68
    protected $imp;
69
    protected $toma4;
70
    protected $toma03;
71
    protected $tpEmis;
72
    protected $tpImp;
73
    protected $tpAmb;
74
    protected $vPrest;
75
    protected $infServico;
76
    protected $wAdic = 150;
77
    protected $textoAdic = '';
78
    protected $debugMode = 2;
79
    protected $formatPadrao;
80
    protected $formatNegrito;
81
    protected $aquav;
82
    protected $preVisualizar;
83
    protected $flagDocOrigContinuacao;
84
    protected $arrayNFe = array();
85
    protected $siteDesenvolvedor;
86
    protected $nomeDesenvolvedor;
87
    protected $totPag;
88
    protected $idDocAntEle = [];
89
90
    /**
91
     * __construct
92
     *
93
     * @param string $docXML Arquivo XML da CTe
94
     * @param string $sOrientacao (Opcional) Orientação da impressão P ou L
95
     * @param string $sPapel Tamanho do papel (Ex. A4)
96
     * @param string $sPathLogo Caminho para o arquivo do logo
97
     * @param string $sDestino Estabelece a direção do envio do documento PDF
98
     * @param string $sDirPDF Caminho para o diretorio de armaz. dos PDF
99
     * @param string $fonteDACTE Nome da fonte a ser utilizada
100
     * @param number $mododebug 0-Não 1-Sim e 2-nada (2 default)
101
     * @param string $preVisualizar 0-Não 1-Sim
102
     */
103
    public function __construct(
104
        $docXML = '',
105
        $sOrientacao = '',
106
        $sPapel = '',
107
        $sPathLogo = '',
108
        $sDestino = 'I',
109
        $sDirPDF = '',
110
        $fonteDACTE = '',
111
        $mododebug = 2,
112
        $preVisualizar = false,
113
        $nomeDesenvolvedor = 'Powered by NFePHP (GNU/GPLv3 GNU/LGPLv3) © www.nfephp.org',
114
        $siteDesenvolvedor = 'http://www.nfephp.org'
115
    ) {
116
117
        if (is_numeric($mododebug)) {
118
            $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...
119
        }
120
        if ($mododebug == 1) {
121
            //ativar modo debug
122
            error_reporting(E_ALL);
123
            ini_set('display_errors', 'On');
124
        } elseif ($mododebug == 0) {
125
            //desativar modo debug
126
            error_reporting(0);
127
            ini_set('display_errors', 'Off');
128
        }
129
        $this->orientacao = $sOrientacao;
130
        $this->papel = $sPapel;
131
        $this->pdf = '';
132
        $this->xml = $docXML;
133
        $this->logomarca = $sPathLogo;
134
        $this->destino = $sDestino;
135
        $this->pdfDir = $sDirPDF;
136
        $this->preVisualizar = $preVisualizar;
137
        $this->siteDesenvolvedor = $siteDesenvolvedor;
138
        $this->nomeDesenvolvedor = $nomeDesenvolvedor;
139
        // verifica se foi passa a fonte a ser usada
140
        if (!empty($fonteDACTE)) {
141
            $this->fontePadrao = $fonteDACTE;
142
        }
143
        $this->formatPadrao = array(
144
            'font' => $this->fontePadrao,
145
            'size' => 6,
146
            'style' => '');
147
        $this->formatNegrito = array(
148
            'font' => $this->fontePadrao,
149
            'size' => 7,
150
            'style' => 'B');
151
        //se for passado o xml
152
        if (!empty($this->xml)) {
153
            $this->dom = new Dom();
154
            $this->dom->loadXML($this->xml);
155
            $this->cteProc = $this->dom->getElementsByTagName("cteProc")->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...
156
            $this->infCte = $this->dom->getElementsByTagName("infCte")->item(0);
157
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
158
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
159
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
160
161
            $this->infPercurso = $this->dom->getElementsByTagName("infPercurso");
162
            $this->infCarga = $this->dom->getElementsByTagName("infCarga")->item(0);
163
            $this->infQ = $this->dom->getElementsByTagName("infQ");
164
            $this->seg = $this->dom->getElementsByTagName("seg")->item(0);
165
            $this->rodo = $this->dom->getElementsByTagName("rodoOS")->item(0);
166
167
168
            $this->veic = $this->dom->getElementsByTagName("veic");
169
            $this->ferrov = $this->dom->getElementsByTagName("ferrov")->item(0);
170
            // adicionar outros modais
171
            $this->infCteComp = $this->dom->getElementsByTagName("infCteComp")->item(0);
172
            $this->chaveCTeRef = $this->pSimpleGetValue($this->infCteComp, "chave");
173
            $this->vPrest = $this->dom->getElementsByTagName("vPrest")->item(0);
174
            $this->Comp = $this->dom->getElementsByTagName("Comp");
175
            $this->infNF = $this->dom->getElementsByTagName("infNF");
176
            $this->infNFe = $this->dom->getElementsByTagName("infNFe");
177
            $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...
178
            $this->infServico = $this->dom->getElementsByTagName("infServico");
179
            $this->compl = $this->dom->getElementsByTagName("compl");
180
            $this->ICMS = $this->dom->getElementsByTagName("ICMS")->item(0);
181
            $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...
182
            $this->imp = $this->dom->getElementsByTagName("imp")->item(0);
183
184
            $vTrib = $this->pSimpleGetValue($this->imp, "vTotTrib");
185
            if (!is_numeric($vTrib)) {
186
                $vTrib = 0;
187
            }
188
            $textoAdic = number_format($vTrib, 2, ",", ".");
189
190
            $this->textoAdic = "o valor aproximado de tributos incidentes sobre o preço deste serviço é de R$"
191
                    .$textoAdic;
192
            $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...
193
            $this->enderToma = $this->pSimpleGetValue($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...
194
            //modal aquaviário
195
            $this->aquav = $this->dom->getElementsByTagName("aquav")->item(0);
196
197
            $seguro = $this->pSimpleGetValue($this->seg, "respSeg");
198
            switch ($seguro) {
199
                case '4':
200
                    $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...
201
                    break;
202
                case '5':
203
                    $this->respSeg = 'Tomador do Serviço';
204
                    break;
205
                default:
206
                    $this->respSeg = '';
207
                    break;
208
            }
209
            $this->tpEmis = $this->pSimpleGetValue($this->ide, "tpEmis");
210
            $this->tpImp = $this->pSimpleGetValue($this->ide, "tpImp");
211
            $this->tpAmb = $this->pSimpleGetValue($this->ide, "tpAmb");
212
            $this->tpCTe = $this->pSimpleGetValue($this->ide, "tpCTe");
213
            $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...
214
            //01-Rodoviário; //02-Aéreo; //03-Aquaviário; //04-Ferroviário;//05-Dutoviário
215
            $this->modal = $this->pSimpleGetValue($this->ide, "modal");
216
        }
217
    }
218
219
    /**
220
     * monta
221
     * @param string $orientacao L ou P
222
     * @param string $papel A4
223
     * @param string $logoAlign C, L ou R
224
     * @param Pdf $classPDF
225
     * @return string montagem
226
     */
227
    public function monta(
228
        $orientacao = '',
229
        $papel = 'A4',
230
        $logoAlign = 'C',
231
        $classPDF = false
232
    ) {
233
234
        return $this->montaDACTE($orientacao, $papel, $logoAlign, $classPDF);
0 ignored issues
show
Bug introduced by
It seems like $classPDF defined by parameter $classPDF on line 231 can also be of type object<NFePHP\DA\Legacy\Pdf>; however, NFePHP\DA\CTe\DacteOSV3::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...
235
    }
236
237
    /**
238
     * printDocument
239
     * @param string $nome
240
     * @param string $destino
241
     * @param string $printer
242
     * @return
243
     */
244
    public function printDocument($nome = '', $destino = 'I', $printer = '')
245
    {
246
        return $this->printDACTE($nome, $destino, $printer);
247
    }
248
249
    /**
250
     * Dados brutos do PDF
251
     * @return string
252
     */
253
    public function render()
254
    {
255
        return $this->pdf->getPdf();
256
    }
257
258
259
    protected function zCteDPEC()
260
    {
261
        return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != '';
262
    }
263
264
265
    /**
266
     * montaDACTE
267
     * Esta função monta a DACTE conforme as informações fornecidas para a classe
268
     * durante sua construção.
269
     * A definição de margens e posições iniciais para a impressão são estabelecidas no
270
     * pelo conteúdo da funçao e podem ser modificados.
271
     *
272
     * @param  string $orientacao (Opcional) Estabelece a orientação da
273
     *                impressão (ex. P-retrato), se nada for fornecido será
274
     *                usado o padrão da NFe
275
     * @param  string $papel (Opcional) Estabelece o tamanho do papel (ex. A4)
276
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
277
     */
278
    public function montaDACTE(
279
        $orientacao = '',
280
        $papel = 'A4',
281
        $logoAlign = 'C',
282
        $classPDF = false
283
    ) {
284
285
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
286
        if ($orientacao == '') {
287
            if ($this->tpImp == '1') {
288
                $orientacao = 'P';
289
            } else {
290
                $orientacao = 'P';
291
            }
292
        }
293
        $this->orientacao = $orientacao;
294
        $this->papel = $papel;
295
        $this->logoAlign = $logoAlign;
296
297
        //$this->situacao_externa = $situacao_externa;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
298
        //instancia a classe pdf
299
        if ($classPDF !== false) {
300
            $this->pdf = $classPDF;
301
        } else {
302
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
303
        }
304
        if ($this->orientacao == 'P') {
305
            // margens do PDF
306
            $margSup = 2;
307
            $margEsq = 2;
308
            $margDir = 2;
309
            // posição inicial do relatorio
310
            $xInic = 1;
311
            $yInic = 1;
312
            if ($papel == 'A4') {
313
                //A4 210x297mm
314
                $maxW = 210;
315
                $maxH = 297;
316
            }
317
        } else {
318
            // margens do PDF
319
            $margSup = 3;
320
            $margEsq = 3;
321
            $margDir = 3;
322
            // posição inicial do relatorio
323
            $xInic = 5;
324
            $yInic = 5;
325
            if ($papel == 'A4') {
326
                //A4 210x297mm
327
                $maxH = 210;
328
                $maxW = 297;
329
                $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...
330
            }
331
        }
332
        //total inicial de paginas
333
        $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...
334
        //largura imprimivel em mm
335
        $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...
336
        //comprimento imprimivel em mm
337
        $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...
338
        // estabelece contagem de paginas
339
        $this->pdf->AliasNbPages();
340
        // fixa as margens
341
        $this->pdf->SetMargins($margEsq, $margSup, $margDir);
342
        $this->pdf->SetDrawColor(0, 0, 0);
343
        $this->pdf->SetFillColor(255, 255, 255);
344
        // inicia o documento
345
        $this->pdf->Open();
346
        // adiciona a primeira página
347
        $this->pdf->AddPage($this->orientacao, $this->papel);
348
        $this->pdf->SetLineWidth(0.1);
349
        $this->pdf->SetTextColor(0, 0, 0);
350
        //calculo do numero de páginas ???
351
        $totPag = 1;
352
        //montagem da primeira página
353
        $pag = 1;
354
        $x = $xInic;
355
        $y = $yInic;
356
        //coloca o cabeçalho
357
        //$r = $this->zCabecalho($x, $y, $pag, $totPag);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
358
        $y += 70;
359
        $r = $this->zTomador($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...
360
        if ($this->tpCTe == '0') {
361
            //Normal
362
            $y += 10;
363
            $x = $xInic;
364
            //$r = $this->zDocOrig($x, $y);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
365
            $r = $this->zInfPrestacaoServico($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...
366
            $y += 53;
367
            $x = $xInic;
368
            $r = $this->zCompValorServ($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...
369
            $y += 25;
370
            $x = $xInic;
371
            $r = $this->zImpostos($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...
372
            $y += 13;
373
            $x = $xInic;
374
            $r = $this->zObs($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...
375
            $y += 19;
376
            $x = $xInic;
377
            $r = $this->zSeguro($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...
378
            $y = $y-12;
379
380
381
            switch ($this->modal) {
382
                case '1':
383
                    $y += 24.9;
384
                    $x = $xInic;
385
                    $r = $this->zModalRod($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...
386
                    break;
387
                case '2':
388
                    $y += 17.9;
389
                    $x = $xInic;
390
                    // TODO fmertins 31/10/14: este método não existe...
391
                    $r = $this->zModalAereo($x, $y);
0 ignored issues
show
Bug introduced by
The method zModalAereo() does not seem to exist on object<NFePHP\DA\CTe\DacteOSV3>.

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...
392
                    break;
393
                case '3':
394
                    $y += 17.9;
395
                    $x = $xInic;
396
                    $r = $this->zModalAquaviario($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...
397
                    break;
398
                case '4':
399
                    $y += 17.9;
400
                    $x = $xInic;
401
                    $r = $this->zModalFerr($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...
402
                    break;
403
                case '5':
404
                    $y += 17.9;
405
                    $x = $xInic;
406
                    // TODO fmertins 31/10/14: este método não existe...
407
                    $r = $this->zModalDutoviario($x, $y);
0 ignored issues
show
Bug introduced by
The method zModalDutoviario() does not seem to exist on object<NFePHP\DA\CTe\DacteOSV3>.

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...
408
                    break;
409
            }
410
            if ($this->modal == '1') {
411
                if ($this->lota == 1) {
0 ignored issues
show
Bug introduced by
The property lota 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...
412
                    $y += 37;
413
                } else {
414
                    $y += 8.9;
415
                }
416
            } elseif ($this->modal == '3') {
417
                $y += 24.15;
418
            } else {
419
                $y += 37;
420
            }
421
        } else {
422
            $r = $this->zCabecalho(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...
423
            //Complementado
424
            $y += 10;
425
            $x = $xInic;
426
            $r = $this->zDocCompl($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...
427
            $y += 80;
428
            $x = $xInic;
429
            $r = $this->zCompValorServ($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...
430
            $y += 25;
431
            $x = $xInic;
432
            $r = $this->zImpostos($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...
433
            $y += 13;
434
            $x = $xInic;
435
            $r = $this->zObs($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...
436
            $y += 15;
437
        }
438
        $x = $xInic;
439
        $y += 1;
440
        $r = $this->zDadosAdic($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...
441
442
        $y += 21;
443
        //$y += 11;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
444
        $y = $this->zCanhoto($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...
445
446
        //coloca o rodapé da página
447
        if ($this->orientacao == 'P') {
448
            $this->zRodape(2, $this->hPrint - 2);
449
        } else {
450
            $this->zRodape($xInic, $this->hPrint + 2.3);
451
        }
452
        if ($this->flagDocOrigContinuacao == 1) {
453
            $this->zdocOrigContinuacao(1, 71);
0 ignored issues
show
Bug introduced by
The method zdocOrigContinuacao() does not seem to exist on object<NFePHP\DA\CTe\DacteOSV3>.

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...
454
        }
455
        //retorna o ID na CTe
456
        if ($classPDF !== false) {
457
            $aR = array('id' => str_replace('CTe', '', $this->infCte->getAttribute("Id")), 'classe_PDF' => $this->pdf);
458
            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\DacteOSV3::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...
459
        } else {
460
            return str_replace('CTe', '', $this->infCte->getAttribute("Id"));
461
        }
462
    } //fim da função montaDACTE
463
464
    /**
465
     * printDACTE
466
     * Esta função envia a DACTE em PDF criada para o dispositivo informado.
467
     * O destino da impressão pode ser :
468
     * I-browser
469
     * D-browser com download
470
     * F-salva em um arquivo local com o nome informado
471
     * S-retorna o documento como uma string e o nome é ignorado.
472
     * Para enviar o pdf diretamente para uma impressora indique o
473
     * nome da impressora e o destino deve ser 'S'.
474
     *
475
     * @param  string $nome Path completo com o nome do arquivo pdf
476
     * @param  string $destino Direção do envio do PDF
477
     * @param  string $printer Identificação da impressora no sistema
478
     * @return string Caso o destino seja S o pdf é retornado como uma string
479
     * @todo Rotina de impressão direta do arquivo pdf criado
480
     */
481
    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...
482
    {
483
        $arq = $this->pdf->Output($nome, $destino);
484
        if ($destino == 'S') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
485
            //aqui pode entrar a rotina de impressão direta
486
        }
487
        return $arq;
488
    } //fim função printDACTE
489
490
    /**
491
     * zCabecalho
492
     * Monta o cabelhalho da DACTE ( retrato e paisagem )
493
     *
494
     * @param  number $x Posição horizontal inicial, canto esquerdo
495
     * @param  number $y Posição vertical inicial, canto superior
496
     * @param  number $pag Número da Página
497
     * @param  number $totPag Total de páginas
498
     * @return number Posição vertical final
499
     */
500
    protected function zCabecalho($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...
501
    {
502
        $oldX = $x;
503
        $oldY = $y;
504
        if ($this->orientacao == 'P') {
505
            $maxW = $this->wPrint;
506
        } else {
507
            if ($pag == 1) {
508
                // primeira página
509
                $maxW = $this->wPrint - $this->wCanhoto;
510
            } else {
511
                // páginas seguintes
512
                $maxW = $this->wPrint;
513
            }
514
        }
515
        //##################################################################
516
        //coluna esquerda identificação do emitente
517
        $w = round($maxW * 0.42);
518
        if ($this->orientacao == 'P') {
519
            $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...
520
                'font' => $this->fontePadrao,
521
                'size' => 6,
522
                'style' => '');
523
        } else {
524
            $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...
525
        }
526
        $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...
527
        $h = 35;
528
        $oldY += $h;
529
        //desenha a caixa
530
        $this->pTextBox($x, $y, $w + 2, $h + 1);
531
        // coloca o logo
532
        if (is_file($this->logomarca)) {
533
            $logoInfo = getimagesize($this->logomarca);
534
            //largura da imagem em mm
535
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
536
            //altura da imagem em mm
537
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
538
            if ($this->logoAlign == 'L') {
539
                $nImgW = round($w / 3, 0);
540
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
541
                $xImg = $x + 1;
542
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
543
                //estabelecer posições do texto
544
                $x1 = round($xImg + $nImgW + 1, 0);
545
                $y1 = round($h / 3 + $y, 0);
546
                $tw = round(2 * $w / 3, 0);
547
            } elseif ($this->logoAlign == 'C') {
548
                $nImgH = round($h / 3, 0);
549
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
550
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
551
                $yImg = $y + 3;
552
                $x1 = $x;
553
                $y1 = round($yImg + $nImgH + 1, 0);
554
                $tw = $w;
555
            } elseif ($this->logoAlign == 'R') {
556
                $nImgW = round($w / 3, 0);
557
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
558
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
559
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
560
                $x1 = $x;
561
                $y1 = round($h / 3 + $y, 0);
562
                $tw = round(2 * $w / 3, 0);
563
            }
564
            $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...
565
        } else {
566
            $x1 = $x;
567
            $y1 = round($h / 3 + $y, 0);
568
            $tw = $w;
569
        }
570
        //Nome emitente
571
        $aFont = array(
572
            'font' => $this->fontePadrao,
573
            'size' => 9,
574
            'style' => 'B');
575
        $texto = $this->pSimpleGetValue($this->emit, "xNome");
576
        $this->pTextBox($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...
577
        //endereço
578
        $y1 = $y1 + 3;
579
        $aFont = array(
580
            'font' => $this->fontePadrao,
581
            'size' => 7,
582
            'style' => '');
583
        $fone = $this->pSimpleGetValue($this->enderEmit, "fone")!=""? $this->zFormatFone($this->enderEmit):'';
584
        $lgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
585
        $nro = $this->pSimpleGetValue($this->enderEmit, "nro");
586
        $cpl = $this->pSimpleGetValue($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...
587
        $bairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
588
        $CEP = $this->pSimpleGetValue($this->enderEmit, "CEP");
589
        $CEP = $this->pFormat($CEP, "#####-###");
590
        $mun = $this->pSimpleGetValue($this->enderEmit, "xMun");
591
        $UF = $this->pSimpleGetValue($this->enderEmit, "UF");
592
        $xPais = $this->pSimpleGetValue($this->enderEmit, "xPais");
593
        $texto = $lgr . "," . $nro . "\n" . $bairro . " - "
594
            . $CEP . " - " . $mun . " - " . $UF . " " . $xPais
595
            . "\n  Fone/Fax: " . $fone;
596
        $this->pTextBox($x1 - 5, $y1 + 2, $tw + 5, 8, $texto, $aFont, 'T', 'C', 0, '');
597
        //CNPJ/CPF IE
598
        $cpfCnpj = $this->zFormatCNPJCPF($this->emit);
599
        $ie = $this->pSimpleGetValue($this->emit, "IE");
600
        $texto = 'CNPJ/CPF:  ' . $cpfCnpj . '     Insc.Estadual: ' . $ie;
601
        $this->pTextBox($x1 - 1, $y1 + 12, $tw + 5, 8, $texto, $aFont, 'T', 'C', 0, '');
602
        //outra caixa
603
        $h1 = 17.5;
604
        $y1 = $y + $h + 1;
605
        $this->pTextBox($x, $y1, $w + 2, $h1);
606
        //TIPO DO CT-E
607
        $texto = 'TIPO DO CTE';
608
        $wa = 37;
609
        $aFont = array(
610
            'font' => $this->fontePadrao,
611
            'size' => 8,
612
            'style' => '');
613
        $this->pTextBox($x, $y1, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '');
614
        $tpCTe = $this->pSimpleGetValue($this->ide, "tpCTe");
615
        //0 - CT-e Normal,1 - CT-e de Complemento de Valores,
616
        //2 - CT-e de Anulação de Valores,3 - CT-e Substituto
617
        switch ($tpCTe) {
618
            case '0':
619
                $texto = 'Normal';
620
                break;
621
            case '1':
622
                $texto = 'Complemento de Valores';
623
                break;
624
            case '2':
625
                $texto = 'Anulação de Valores';
626
                break;
627
            case '3':
628
                $texto = 'Substituto';
629
                break;
630
            default:
631
                $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...
632
        }
633
        $aFont = $this->formatNegrito;
634
        $this->pTextBox($x, $y1 + 3, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '', false);
635
        //TIPO DO SERVIÇO
636
        $texto = 'TIPO DO SERVIÇO';
637
        $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...
638
        $aFont = array(
639
            'font' => $this->fontePadrao,
640
            'size' => 8,
641
            'style' => '');
642
        $this->pTextBox($x + $wa + 4.5, $y1, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '');
643
        $tpServ = $this->pSimpleGetValue($this->ide, "tpServ");
644
        //'6' => 'Transporte de Pessoas', '7' => 'Transporte de Valores', '8' => 'Transporte de Bagagem'
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

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

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
839
            if (!empty($this->protCTe)
840
                && !empty($this->protCTe->getElementsByTagName("dhRecbto")->item(0)->nodeValue)
841
            ) {
842
                $texto .= date(
843
                    'd/m/Y   H:i:s',
844
                    $this->pConvertTime($this->pSimpleGetValue($this->protCTe, "dhRecbto"))
845
                );
846
            }
847
            $texto = $this->pSimpleGetValue($this->protCTe, "nProt") == '' ? '' : $texto;
848
        }
849
        $aFont = $this->formatNegrito;
850
        $this->pTextBox($x, $y + 12, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
851
        //CFOP
852
        $x = $oldX;
853
        $h = 8.5;
854
        $w = round($maxW * 0.42);
855
        $y1 = $y + 7.5;
856
        $this->pTextBox($x, $y1, $w + 2, $h);
857
        $texto = 'CFOP - NATUREZA DA PRESTAÇÃO';
858
        $aFont = array(
859
            'font' => $this->fontePadrao,
860
            'size' => 8,
861
            'style' => '');
862
        $this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
863
        $texto = $this->pSimpleGetValue($this->ide, "CFOP") . ' - ' . $this->pSimpleGetValue($this->ide, "natOp");
864
        $aFont = $this->formatNegrito;
865
        $this->pTextBox($x, $y1 + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
866
        //ORIGEM DA PRESTAÇÃO
867
        $y += $h + 7.5;
868
        $x = $oldX;
869
        $h = 8;
870
        $w = ($maxW * 0.33);
871
        $this->pTextBox($x, $y, $w + 0.5, $h);
872
        $texto = 'INÍCIO DA PRESTAÇÃO';
873
        $aFont = array(
874
            'font' => $this->fontePadrao,
875
            'size' => 8,
876
            'style' => '');
877
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
878
        $texto = $this->pSimpleGetValue($this->ide, "xMunIni") . ' - ' . $this->pSimpleGetValue($this->ide, "UFIni");
879
        $aFont = $this->formatNegrito;
880
        $this->pTextBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
881
        //PERCURSO DO VEÍCULO
882
        $x = $oldX + 69;
883
        $oldX = $x;
884
        $h = 8;
885
        $w = ($maxW * 0.334);
886
        $this->pTextBox($x, $y, $w + 0.5, $h);
887
        $texto = 'PERCURSO DO VEÍCULO';
888
        $aFont = array(
889
            'font' => $this->fontePadrao,
890
            'size' => 8,
891
            'style' => '');
892
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
893
        $texto = '';
894
        $first = true;
895
        if (!empty($this->infPercurso)) {
896
            foreach ($this->infPercurso as $k => $d) {
897
                if (!$first) {
898
                    $texto .= ' - ';
899
                } else {
900
                    $first = false;
901
                }
902
                $texto .= $this->infPercurso->item($k)->getElementsByTagName('UFPer')->item(0)->nodeValue;
903
            }
904
        }
905
        $aFont = $this->formatNegrito;
906
        $this->pTextBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
907
        //DESTINO DA PRESTAÇÃO
908
        $x = $oldX + $w + 1;
909
        $h = 8;
910
        $w = $w - 1.3;
911
        $this->pTextBox($x - 0.5, $y, $w + 0.5, $h);
912
        $texto = 'TÉRMINO DA PRESTAÇÃO';
913
        $aFont = array(
914
            'font' => $this->fontePadrao,
915
            'size' => 8,
916
            'style' => '');
917
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
918
        $texto = $this->pSimpleGetValue($this->ide, "xMunFim") . ' - ' . $this->pSimpleGetValue($this->ide, "UFFim");
919
        $aFont = $this->formatNegrito;
920
        $this->pTextBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
921
        //#########################################################################
922
        //Indicação de CTe Homologação, cancelamento e falta de protocolo
923
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
924
        //indicar cancelamento
925
        $cStat = $this->pSimpleGetValue($this->cteProc, "cStat");
926
        if ($cStat == '101' || $cStat == '135' || $this->situacao_externa == self::NFEPHP_SITUACAO_EXTERNA_CANCELADA) {
927
            //101 Cancelamento
928
            $x = 10;
929
            $y = $this->hPrint - 130;
930
            $h = 25;
931
            $w = $maxW - (2 * $x);
932
            $this->pdf->SetTextColor(90, 90, 90);
933
            $texto = "CTe CANCELADO";
934
            $aFont = array(
935
                'font' => $this->fontePadrao,
936
                'size' => 48,
937
                'style' => 'B');
938
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
939
            $this->pdf->SetTextColor(0, 0, 0);
940
        }
941
        $cStat = $this->pSimpleGetValue($this->cteProc, "cStat");
942
        if ($cStat == '110' ||
943
            $cStat == '301' ||
944
            $cStat == '302' ||
945
            $this->situacao_externa == self::NFEPHP_SITUACAO_EXTERNA_DENEGADA
946
        ) {
947
            //110 Denegada
948
            $x = 10;
949
            $y = $this->hPrint - 130;
950
            $h = 25;
951
            $w = $maxW - (2 * $x);
952
            $this->pdf->SetTextColor(90, 90, 90);
953
            $texto = "CTe USO DENEGADO";
954
            $aFont = array(
955
                'font' => $this->fontePadrao,
956
                'size' => 48,
957
                'style' => 'B');
958
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
959
            $y += $h;
960
            $h = 5;
961
            $w = $maxW - (2 * $x);
962
            $texto = "SEM VALOR FISCAL";
963
            $aFont = array(
964
                'font' => $this->fontePadrao,
965
                'size' => 48,
966
                'style' => 'B');
967
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
968
            $this->pdf->SetTextColor(0, 0, 0);
969
        }
970
        //indicar sem valor
971
        if ($tpAmb != 1 && $this->preVisualizar=='0') { // caso não seja uma DA de produção
972
            $x = 10;
973
            if ($this->orientacao == 'P') {
974
                $y = round($this->hPrint / 2, 0);
975
            } else {
976
                $y = round($this->hPrint / 2, 0);
977
            }
978
            $h = 5;
979
            $w = $maxW - (2 * $x);
980
            $this->pdf->SetTextColor(90, 90, 90);
981
            $texto = "SEM VALOR FISCAL";
982
            $aFont = array(
983
                'font' => $this->fontePadrao,
984
                'size' => 48,
985
                'style' => 'B');
986
            $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
987
            $aFont = array(
988
                'font' => $this->fontePadrao,
989
                'size' => 30,
990
                'style' => 'B');
991
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
992
            $this->pTextBox($x, $y + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
993
            $this->pdf->SetTextColor(0, 0, 0);
994
        } elseif ($this->preVisualizar=='1') { // caso seja uma DA de Pré-Visualização
995
            $h = 5;
996
            $w = $maxW - (2 * 10);
997
            $x = 55;
998
            $y = 240;
999
            $this->pdf->SetTextColor(255, 100, 100);
1000
            $aFont = array(
1001
                'font' => $this->fontePadrao,
1002
                'size' => 40,
1003
                'style' => 'B');
1004
            $texto = "Pré-visualização";
1005
            $this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1006
            $this->pdf->SetTextColor(255, 100, 100);
1007
            $aFont = array(
1008
                'font' => $this->fontePadrao,
1009
                'size' => 41,
1010
                'style' => 'B');
1011
            $texto = "Sem Validade Jurídica";
1012
            $this->pTextBox90($x+20, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1013
            $this->pdf->SetTextColor(90, 90, 90);
1014
            $texto = "SEM VALOR FISCAL";
1015
            $aFont = array(
1016
                'font' => $this->fontePadrao,
1017
                'size' => 48,
1018
                'style' => 'B');
1019
            $this->pTextBox90($x+40, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1020
            $this->pdf->SetTextColor(0, 0, 0); // voltar a cor default
1021
        } else {
1022
            $x = 10;
1023
            if ($this->orientacao == 'P') {
1024
                $y = round($this->hPrint * 2 / 3, 0);
1025
            } else {
1026
                $y = round($this->hPrint / 2, 0);
1027
            } //fim orientacao
1028
            $h = 5;
1029
            $w = $maxW - (2 * $x);
1030
            $this->pdf->SetTextColor(90, 90, 90);
1031
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1032
            if (($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) && !$this->zCteDPEC()) {
1033
                //Contingência
1034
                $texto = "DACTE Emitido em Contingência";
1035
                $aFont = array(
1036
                    'font' => $this->fontePadrao,
1037
                    'size' => 48,
1038
                    'style' => 'B');
1039
                $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1040
                $aFont = array(
1041
                    'font' => $this->fontePadrao,
1042
                    'size' => 30,
1043
                    'style' => 'B');
1044
                $texto = "devido à problemas técnicos";
1045
                $this->pTextBox($x, $y + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1046
            } else {
1047
                if (!isset($this->protCTe)) {
1048
                    if (!$this->zCteDPEC()) {
1049
                        $texto = "SEM VALOR FISCAL";
1050
                        $aFont = array(
1051
                            'font' => $this->fontePadrao,
1052
                            'size' => 48,
1053
                            'style' => 'B');
1054
                        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1055
                    }
1056
                    $aFont = array(
1057
                        'font' => $this->fontePadrao,
1058
                        'size' => 30,
1059
                        'style' => 'B');
1060
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1061
                    if (!$this->zCteDPEC()) {
1062
                        $this->pTextBox($x, $y + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1063
                    } else {
1064
                        $this->pTextBox($x, $y + 25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1065
                    }
1066
                } //fim cteProc
1067
                if ($this->tpEmis == 4) {
1068
                    //DPEC
1069
                    $x = 10;
1070
                    $y = $this->hPrint - 130;
1071
                    $h = 25;
1072
                    $w = $maxW - (2 * $x);
1073
                    $this->pdf->SetTextColor(200, 200, 200); // 90,90,90 é muito escuro
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1074
                    $texto = "DACTE impresso em contingência -\n"
1075
                        . "DPEC regularmente recebido pela Receita\n"
1076
                        . "Federal do Brasil";
1077
                    $aFont = array(
1078
                        'font' => $this->fontePadrao,
1079
                        'size' => 48,
1080
                        'style' => 'B');
1081
                    $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1082
                    $this->pdf->SetTextColor(0, 0, 0);
1083
                }
1084
            } //fim tpEmis
1085
            $this->pdf->SetTextColor(0, 0, 0);
1086
        }
1087
        return $oldY;
1088
    } //fim zCabecalho
1089
1090
    /**
1091
     * rodapeDACTE
1092
     * Monta o rodape no final da DACTE ( retrato e paisagem )
1093
     *
1094
     * @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...
1095
     * @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...
1096
     */
1097
    protected function zRodape($x, $y)
1098
    {
1099
        $texto = "Impresso em  " . date('d/m/Y   H:i:s');
1100
        $w = $this->wPrint - 4;
1101
        $aFont = array(
1102
            'font' => $this->fontePadrao,
1103
            'size' => 6,
1104
            'style' => '');
1105
        $this->pTextBox($x-1, $y+2, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
1106
        $texto = $this->nomeDesenvolvedor . ' - '. $this->siteDesenvolvedor;
1107
        $aFont = array(
1108
            'font' => $this->fontePadrao,
1109
            'size' => 6,
1110
            'style' => '');
1111
        $this->pTextBox($x-50, $y+2, $w, 4, $texto, $aFont, 'T', 'R', 0, $this->siteDesenvolvedor);
1112
    } //fim zRodape
1113
1114
    /**
1115
     * zTomador
1116
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1117
     *
1118
     * @param  number $x Posição horizontal canto esquerdo
1119
     * @param  number $y Posição vertical canto superior
1120
     * @return number Posição vertical final
1121
     */
1122
    protected function zTomador($x = 0, $y = 0)
1123
    {
1124
        $oldX = $x;
1125
        $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...
1126
        if ($this->orientacao == 'P') {
1127
            $maxW = $this->wPrint;
1128
        } else {
1129
            $maxW = $this->wPrint - $this->wCanhoto;
1130
        }
1131
        $w = $maxW;
1132
        $h = 10;
1133
        $texto = 'TOMADOR DO SERVIÇO';
1134
        $aFont = $this->formatPadrao;
1135
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1136
        $aFont = $this->formatNegrito;
1137
        $texto = $this->pSimpleGetValue($this->toma, "xNome");
1138
        $this->pTextBox($x + 29, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1139
        $x = $maxW * 0.60;
1140
        $texto = 'MUNICÍPIO';
1141
        $aFont = $this->formatPadrao;
1142
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1143
        $texto = $this->pSimpleGetValue($this->toma, "xMun");
1144
        $aFont = $this->formatNegrito;
1145
        $this->pTextBox($x + 15, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1146
        $x = $maxW * 0.85;
1147
        $texto = 'UF';
1148
        $aFont = $this->formatPadrao;
1149
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1150
        $texto = $this->pSimpleGetValue($this->toma, "UF");
1151
        $aFont = $this->formatNegrito;
1152
        $this->pTextBox($x + 4, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1153
        $x = $w - 18;
1154
        $texto = 'CEP';
1155
        $aFont = $this->formatPadrao;
1156
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1157
        $texto = $this->pFormat($this->pSimpleGetValue($this->toma, "CEP"), "#####-###");
1158
        $aFont = $this->formatNegrito;
1159
        $this->pTextBox($x + 6, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1160
        $y += 3;
1161
        $x = $oldX;
1162
        $texto = 'ENDEREÇO';
1163
        $aFont = $this->formatPadrao;
1164
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1165
        $aFont = $this->formatNegrito;
1166
        $texto = $this->pSimpleGetValue($this->toma, "xLgr") . ',';
1167
        $texto .= $this->pSimpleGetValue($this->toma, "nro");
1168
        $texto .= ($this->pSimpleGetValue($this->toma, "xCpl") != "") ?
1169
            ' - ' . $this->pSimpleGetValue($this->toma, "xCpl") : '';
1170
        $texto .= ' - ' . $this->pSimpleGetValue($this->toma, "xBairro");
1171
        $this->pTextBox($x + 16, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1172
        $y += 3;
1173
        $texto = 'CNPJ/CPF';
1174
        $aFont = $this->formatPadrao;
1175
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1176
        $texto = $this->zFormatCNPJCPF($this->toma);
1177
        $aFont = $this->formatNegrito;
1178
        $this->pTextBox($x + 13, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1179
        $x = $x + 65;
1180
        $texto = 'INSCRIÇÃO ESTADUAL';
1181
        $aFont = $this->formatPadrao;
1182
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1183
        $texto = $this->pSimpleGetValue($this->toma, "IE");
1184
        $aFont = $this->formatNegrito;
1185
        $this->pTextBox($x + 28, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1186
        $x = $w * 0.75;
1187
        $texto = 'PAÍS';
1188
        $aFont = $this->formatPadrao;
1189
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1190
        $texto = $this->pSimpleGetValue($this->toma, "xPais") != "" ?
1191
            $this->pSimpleGetValue($this->toma, "xPais") : 'BRASIL';
1192
        $aFont = $this->formatNegrito;
1193
        $this->pTextBox($x + 6, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1194
        $x = $w - 27;
1195
        $texto = 'FONE';
1196
        $aFont = $this->formatPadrao;
1197
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1198
        $texto = $this->pSimpleGetValue($this->toma, "fone")!=""? $this->zFormatFone($this->toma):'';
1199
        $aFont = $this->formatNegrito;
1200
        $this->pTextBox($x + 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1201
    } //fim da função tomadorDACTE
1202
1203
    /**
1204
     * zCompValorServ
1205
     * Monta o campo com os componentes da prestação de serviços.
1206
     *
1207
     * @param  number $x Posição horizontal canto esquerdo
1208
     * @param  number $y Posição vertical canto superior
1209
     * @return number Posição vertical final
1210
     */
1211
    protected function zCompValorServ($x = 0, $y = 0)
1212
    {
1213
        $oldX = $x;
1214
        $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...
1215
        if ($this->orientacao == 'P') {
1216
            $maxW = $this->wPrint;
1217
        } else {
1218
            $maxW = $this->wPrint - $this->wCanhoto;
1219
        }
1220
        $w = $maxW;
1221
        $h = 25;
1222
        $texto = 'COMPONENTES DO VALOR DA PRESTAÇÃO DO SERVIÇO';
1223
        $aFont = $this->formatPadrao;
1224
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1225
        $y += 3.4;
1226
        $this->pdf->Line($x, $y, $w + 1, $y);
1227
        $texto = 'NOME';
1228
        $aFont = $this->formatPadrao;
1229
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1230
        $yIniDados = $y;
1231
        $x = $w * 0.14;
1232
        $texto = 'VALOR';
1233
        $aFont = $this->formatPadrao;
1234
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1235
        $x = $w * 0.28;
1236
        $this->pdf->Line($x, $y, $x, $y + 21.5);
1237
        $texto = 'NOME';
1238
        $aFont = $this->formatPadrao;
1239
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1240
        $x = $w * 0.42;
1241
        $texto = 'VALOR';
1242
        $aFont = $this->formatPadrao;
1243
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1244
        $x = $w * 0.56;
1245
        $this->pdf->Line($x, $y, $x, $y + 21.5);
1246
        $texto = 'NOME';
1247
        $aFont = $this->formatPadrao;
1248
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1249
        $x = $w * 0.70;
1250
        $texto = 'VALOR';
1251
        $aFont = $this->formatPadrao;
1252
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1253
        $x = $w * 0.86;
1254
        $this->pdf->Line($x, $y, $x, $y + 21.5);
1255
        $y += 1;
1256
        $texto = 'VALOR TOTAL DO SERVIÇO';
1257
        $aFont = $this->formatPadrao;
1258
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1259
        $texto = number_format($this->pSimpleGetValue($this->vPrest, "vTPrest"), 2, ",", ".");
1260
        $aFont = array(
1261
            'font' => $this->fontePadrao,
1262
            'size' => 9,
1263
            'style' => 'B');
1264
        $this->pTextBox($x, $y + 4, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1265
        $y += 10;
1266
        $this->pdf->Line($x, $y, $w + 1, $y);
1267
        $y += 1;
1268
        $texto = 'VALOR A RECEBER';
1269
        $aFont = $this->formatPadrao;
1270
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1271
        $texto = number_format($this->pSimpleGetValue($this->vPrest, "vRec"), 2, ",", ".");
1272
        $aFont = array(
1273
            'font' => $this->fontePadrao,
1274
            'size' => 9,
1275
            'style' => 'B');
1276
        $this->pTextBox($x, $y + 4, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1277
        $auxX = $oldX;
1278
        $yIniDados += 4;
1279
1280
        foreach ($this->Comp as $k => $d) {
1281
            $nome = $this->Comp->item($k)->getElementsByTagName('xNome')->item(0)->nodeValue;
1282
            $valor = number_format(
1283
                $this->Comp->item($k)->getElementsByTagName('vComp')->item(0)->nodeValue,
1284
                2,
1285
                ",",
1286
                "."
1287
            );
1288
            if ($auxX > $w * 0.60) {
1289
                $yIniDados = $yIniDados + 4;
1290
                $auxX = $oldX;
1291
            }
1292
            $texto = $nome;
1293
            $aFont = $this->formatPadrao;
1294
            $this->pTextBox($auxX, $yIniDados, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1295
            $auxX += $w * 0.14;
1296
            $texto = $valor;
1297
            $aFont = $this->formatPadrao;
1298
            $this->pTextBox($auxX, $yIniDados, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1299
            $auxX += $w * 0.14;
1300
        }
1301
    } //fim da função compValorDACTE
1302
1303
    /**
1304
     * zImpostos
1305
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1306
     *
1307
     * @param  number $x Posição horizontal canto esquerdo
1308
     * @param  number $y Posição vertical canto superior
1309
     * @return number Posição vertical final
1310
     */
1311
    protected function zImpostos($x = 0, $y = 0)
1312
    {
1313
        $oldX = $x;
1314
        $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...
1315
        if ($this->orientacao == 'P') {
1316
            $maxW = $this->wPrint;
1317
        } else {
1318
            $maxW = $this->wPrint - $this->wCanhoto;
1319
        }
1320
        $w = $maxW;
1321
        $h = 13;
1322
        $texto = 'INFORMAÇÕES RELATIVAS AO IMPOSTO';
1323
        $aFont = $this->formatPadrao;
1324
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1325
1326
        $y += 3.4;
1327
        $this->pdf->Line($x, $y, $w + 1, $y);
1328
        $texto = 'SITUAÇÃO TRIBUTÁRIA';
1329
        $aFont = $this->formatPadrao;
1330
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1331
1332
        $x += $w * 0.26;
1333
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1334
        $texto = 'BASE DE CALCULO';
1335
        $aFont = $this->formatPadrao;
1336
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1337
1338
        $wCol02=0.18;
1339
        $x += $w * $wCol02;
1340
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1341
        $texto = 'ALÍQ ICMS';
1342
        $aFont = $this->formatPadrao;
1343
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1344
1345
        $x += $w * $wCol02;
1346
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1347
        $texto = 'VALOR ICMS';
1348
        $aFont = $this->formatPadrao;
1349
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1350
1351
        $x += $w * $wCol02;
1352
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1353
        $texto = '% RED. BC ICMS';
1354
        $aFont = $this->formatPadrao;
1355
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1356
1357
        /*$x += $w * 0.14;
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1358
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1359
        $texto = 'ICMS ST';
1360
        $aFont = $this->formatPadrao;
1361
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1362
         * */
1363
1364
        $x = $oldX;
1365
        $y = $y + 4;
1366
        $texto = $this->pSimpleGetValue($this->ICMS, "CST");
1367
        switch ($texto) {
1368
            case '00':
1369
                $texto = "00 - Tributação normal ICMS";
1370
                break;
1371
            case '20':
1372
                $texto = "20 - Tributação com BC reduzida do ICMS";
1373
                break;
1374
            case '40':
1375
                $texto = "40 - ICMS isenção";
1376
                break;
1377
            case '41':
1378
                $texto = "41 - ICMS não tributada";
1379
                break;
1380
            case '51':
1381
                $texto = "51 - ICMS diferido";
1382
                break;
1383
            case '60':
1384
                $texto = "60 - ICMS cobrado anteriormente por substituição tributária";
1385
                break;
1386
            case '90':
1387
                $texto = "90 - ICMS outros";
1388
                break;
1389
        }
1390
        $texto .= $this->pSimpleGetValue($this->ICMSSN, "indSN");
1391
        $texto = $texto == 1 ? 'Simples Nacional' : $texto;
1392
        $aFont = $this->formatNegrito;
1393
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1394
        $x += $w * 0.26;
1395
1396
        $texto = !empty($this->ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
1397
            number_format($this->pSimpleGetValue($this->ICMS, "vBC"), 2, ",", ".") : '';
1398
        $aFont = $this->formatNegrito;
1399
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1400
        $x += $w * $wCol02;
1401
1402
        $texto = !empty($this->ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
1403
            number_format($this->pSimpleGetValue($this->ICMS, "pICMS"), 2, ",", ".") : '';
1404
        $aFont = $this->formatNegrito;
1405
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1406
        $x += $w * $wCol02;
1407
1408
        $texto = !empty($this->ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
1409
            number_format($this->pSimpleGetValue($this->ICMS, "vICMS"), 2, ",", ".") : '';
1410
        $aFont = $this->formatNegrito;
1411
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1412
        $x += $w * $wCol02;
1413
1414
        $texto = !empty($this->ICMS->getElementsByTagName("pRedBC")->item(0)->nodeValue) ?
1415
            number_format($this->pSimpleGetValue($this->ICMS, "pRedBC"), 2, ",", ".").'%' :'';
1416
        $aFont = $this->formatNegrito;
1417
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1418
1419
        /*$x += $w * 0.14;
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1420
        $texto = '';
1421
        $aFont = $this->formatNegrito;
1422
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');*/
1423
    } //fim da função compValorDACTE
1424
1425
    /**
1426
     * zGeraChaveAdicCont
1427
     *
1428
     * @return string chave
1429
     */
1430
    protected function zGeraChaveAdicCont()
1431
    {
1432
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
1433
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1434
        $forma = "%02d%d%s%014d%01d%01d%02d";
1435
        $cUF = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
1436
        $CNPJ = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
1437
        $CNPJ = substr($CNPJ, -14);
1438
        $vCT = number_format($this->pSimpleGetValue($this->vPrest, "vRec"), 2, "", "") * 100;
1439
        $ICMS_CST = $this->pSimpleGetValue($this->ICMS, "CST");
1440
        switch ($ICMS_CST) {
1441
            case '00':
1442
            case '20':
1443
                $ICMSp = '1';
1444
                $ICMSs = '2';
1445
                break;
1446
            case '40':
1447
            case '41':
1448
            case '51':
1449
            case '90':
1450
                $ICMSp = '2';
1451
                $ICMSs = '2';
1452
                break;
1453
            case '60':
1454
                $ICMSp = '2';
1455
                $ICMSs = '1';
1456
                break;
1457
        }
1458
        $dd = $this->ide->getElementsByTagName('dEmi')->item(0)->nodeValue;
1459
        $rpos = strrpos($dd, '-');
1460
        $dd = substr($dd, $rpos + 1);
1461
        $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...
1462
        $chave = $chave . $this->pModulo11($chave);
1463
        return $chave;
1464
    } //fim zGeraChaveAdicCont
1465
1466
    /**
1467
     * zInfPrestacaoServico
1468
     * Monta o campo com das informações da prestação do serviço
1469
     *
1470
     * @param  number $x Posição horizontal canto esquerdo
1471
     * @param  number $y Posição vertical canto superior
1472
     * @return number Posição vertical final
1473
     */
1474
    protected function zInfPrestacaoServico($x = 0, $y = 0)
1475
    {
1476
        $oldX = $x;
1477
        $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...
1478
        if ($this->orientacao == 'P') {
1479
            $maxW = $this->wPrint;
1480
        } else {
1481
            $maxW = $this->wPrint - $this->wCanhoto;
1482
        }
1483
        $w = $maxW;
1484
1485
        // SE FOR RODOVIARIO ( BTR-SEMPRE SERÁ )
1486
        if ($this->modal == '1') {
1487
            // 0 - Não; 1 - Sim Será lotação quando houver um único conhecimento de transporte por veículo,
1488
            // ou combinação veicular, e por viagem
1489
            $h = $this->lota == 1 ? 35 : 53;
1490
        } elseif ($this->modal == '3') {
1491
            $h = 37.6;
1492
        } else {
1493
            $h = 35;
1494
        }
1495
        $texto = 'INFORMAÇÕES DA PRESTAÇÃO DO SERVIÇO';
1496
        $aFont = $this->formatPadrao;
1497
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1498
        $descr1 = 'QUANTIDADE';
1499
        $descr2 = 'DESCRIÇÃO DO SERVIÇO PRESTADO';
1500
1501
        $y += 3.4;
1502
        $this->pdf->Line($x, $y, $w + 1, $y); // LINHA ABAIXO DO TEXTO: "DOCUMENTOS ORIGINÁRIOS
1503
        $texto = $descr1;
1504
        $aFont = $this->formatPadrao;
1505
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1506
        $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...
1507
1508
        $x += $w * 0.14;
1509
        if ($this->modal == '1') {
1510
            if ($this->lota == 1) {
1511
                $this->pdf->Line($x, $y, $x, $y + 31.5); // TESTE
1512
            } else {
1513
                $this->pdf->Line($x, $y, $x, $y + 49.5); // TESTE
1514
            }
1515
        } elseif ($this->modal == '3') {
1516
            $this->pdf->Line($x, $y, $x, $y + 34.1);
1517
        } else {
1518
            $this->pdf->Line($x, $y, $x, $y + 21.5);
1519
        }
1520
1521
        $x += $w * 0.08;
1522
        $texto = $descr2;
1523
        $aFont = $this->formatPadrao;
1524
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1525
1526
        //$auxX = $oldX;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1527
        //$yIniDados += 3;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1528
1529
        $x = $oldX;
1530
        $y = $y + 4;
1531
        $texto = number_format($this->pSimpleGetValue($this->infQ->item(0), "qCarga"), 3, ",", ".");
1532
        $aFont = $this->formatNegrito;
1533
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1534
        $x += $w * 0.26;
1535
1536
        $x = $oldX + 35;
1537
        $texto = $this->pSimpleGetValue($this->infServico->item(0), "xDescServ");
1538
        $aFont = $this->formatNegrito;
1539
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1540
        $x += $w * 0.26;
1541
1542
1543
        $r = $this->zCabecalho(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...
1544
        $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...
1545
    } //fim da função zInfPrestacaoServico
1546
1547
    /**
1548
     * zDocCompl
1549
     * Monta o campo com os dados do remetente na DACTE.
1550
     *
1551
     * @param number $x Posição horizontal canto esquerdo
1552
     * @param number $y Posição vertical canto superior
1553
     * @return number Posição vertical final
1554
     */
1555
    protected function zDocCompl($x = 0, $y = 0)
1556
    {
1557
        $oldX = $x;
1558
        $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...
1559
        if ($this->orientacao == 'P') {
1560
            $maxW = $this->wPrint;
1561
        } else {
1562
            $maxW = $this->wPrint - $this->wCanhoto;
1563
        }
1564
        $w = $maxW;
1565
        $h = 80;
1566
        $texto = 'DETALHAMENTO DO CT-E COMPLEMENTADO';
1567
        $aFont = $this->formatPadrao;
1568
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1569
        $descr1 = 'CHAVE DO CT-E COMPLEMENTADO';
1570
        $descr2 = 'VALOR COMPLEMENTADO';
1571
        $y += 3.4;
1572
        $this->pdf->Line($x, $y, $w + 1, $y);
1573
        $texto = $descr1;
1574
        $aFont = $this->formatPadrao;
1575
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1576
        $yIniDados = $y;
1577
        $x += $w * 0.37;
1578
        $texto = $descr2;
1579
        $aFont = $this->formatPadrao;
1580
        $this->pTextBox($x - 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1581
        $x += $w * 0.13;
1582
        $this->pdf->Line($x, $y, $x, $y + 76.5);
1583
        $texto = $descr1;
1584
        $aFont = $this->formatPadrao;
1585
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1586
        $x += $w * 0.3;
1587
        $texto = $descr2;
1588
        $aFont = $this->formatPadrao;
1589
        $this->pTextBox($x + 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1590
        $auxX = $oldX;
1591
        $yIniDados += 4;
1592
        if ($auxX > $w * 0.90) {
1593
            $yIniDados = $yIniDados + 4;
1594
            $auxX = $oldX;
1595
        }
1596
        $texto = $this->chaveCTeRef;
1597
        $aFont = array(
1598
            'font' => $this->fontePadrao,
1599
            'size' => 8,
1600
            'style' => '');
1601
        $this->pTextBox($auxX, $yIniDados, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1602
        $texto = number_format($this->pSimpleGetValue($this->vPrest, "vTPrest"), 2, ",", ".");
1603
        $aFont = array(
1604
            'font' => $this->fontePadrao,
1605
            'size' => 8,
1606
            'style' => '');
1607
        $this->pTextBox($w * 0.40, $yIniDados, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1608
    } //fim da função zDocCompl
1609
1610
    /**
1611
     * zObs
1612
     * Monta o campo com os dados do remetente na DACTE.
1613
     *
1614
     * @param  number $x Posição horizontal canto esquerdo
1615
     * @param  number $y Posição vertical canto superior
1616
     * @return number Posição vertical final
1617
     */
1618
    protected function zObs($x = 0, $y = 0)
1619
    {
1620
        $oldX = $x;
1621
        $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...
1622
        if ($this->orientacao == 'P') {
1623
            $maxW = $this->wPrint;
1624
        } else {
1625
            $maxW = $this->wPrint - $this->wCanhoto;
1626
        }
1627
        $w = $maxW;
1628
        //$h = 18;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1629
        $h = 18.8;
1630
        $texto = 'OBSERVAÇÕES GERAIS';
1631
        $aFont = $this->formatPadrao;
1632
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1633
        $y += 3.4;
1634
        $this->pdf->Line($x, $y, $w + 1, $y);
1635
        $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...
1636
        $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...
1637
        $texto = '';
1638
        foreach ($this->compl as $k => $d) {
1639
            $xObs = $this->pSimpleGetValue($this->compl->item($k), "xObs");
1640
            $texto .= $xObs;
1641
        }
1642
        $textoObs = explode("Motorista:", $texto);
1643
        $textoObs[1] = isset($textoObs[1]) ? "Motorista: ".$textoObs[1]: '';
1644
        $texto .= $this->pSimpleGetValue($this->imp, "infAdFisco", "\r\n");
1645
        $aFont = array(
1646
            'font' => $this->fontePadrao,
1647
            'size' => 7.5,
1648
            'style' => '');
1649
        $this->pTextBox($x, $y, $w, $h, $textoObs[0], $aFont, 'T', 'L', 0, '', false);
1650
        $this->pTextBox($x, $y+11.5, $w, $h, $textoObs[1], $aFont, 'T', 'L', 0, '', false);
1651
    } //fim da função obsDACTE
1652
1653
    /**
1654
     * zSeguro
1655
     * Monta o campo com os dados de seguro do CT-e OS.
1656
     *
1657
     * @param  number $x Posição horizontal canto esquerdo
1658
     * @param  number $y Posição vertical canto superior
1659
     * @return number Posição vertical final
1660
     */
1661
    protected function zSeguro($x = 0, $y = 0)
1662
    {
1663
        $oldX = $x;
1664
        $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...
1665
        if ($this->orientacao == 'P') {
1666
            $maxW = $this->wPrint;
1667
        } else {
1668
            $maxW = $this->wPrint - $this->wCanhoto;
1669
        }
1670
        $w = $maxW;
1671
        $h = 13;
1672
        $texto = 'SEGURO DA VIAGEM';
1673
        $aFont = $this->formatPadrao;
1674
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1675
1676
        $y += 3.4;
1677
        $this->pdf->Line($x, $y, $w + 1, $y);
1678
        $texto = 'RESPONSÁVEL';
1679
        $aFont = $this->formatPadrao;
1680
        $this->pTextBox($x, $y, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
1681
1682
        $x += $w * 0.33;
1683
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1684
        $texto = 'NOME DA SEGURADORA';
1685
        $aFont = $this->formatPadrao;
1686
        $this->pTextBox($x, $y, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
1687
1688
        $wCol02=0.33;
1689
        $x += $w * $wCol02;
1690
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1691
        $texto = 'NÚMERO DA APÓLICE';
1692
        $aFont = $this->formatPadrao;
1693
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1694
1695
        $x = $oldX;
1696
        $y = $y + 4;
1697
        $texto = $this->respSeg;
1698
        $aFont = $this->formatNegrito;
1699
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1700
        $x += $w * 0.26;
1701
1702
        $texto = '';
1703
        $aFont = $this->formatNegrito;
1704
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1705
        $x += $w * $wCol02;
1706
1707
        $texto = '';
1708
        $aFont = $this->formatNegrito;
1709
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1710
        $x += $w * $wCol02;
1711
    } //fim da função zSeguro
1712
1713
    /**
1714
     * zModalRod
1715
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1716
     *
1717
     * @param  number $x Posição horizontal canto esquerdo
1718
     * @param  number $y Posição vertical canto superior
1719
     * @return number Posição vertical final
1720
     */
1721
    protected function zModalRod($x = 0, $y = 0)
1722
    {
1723
        $oldX = $x;
1724
        $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...
1725
        if ($this->orientacao == 'P') {
1726
            $maxW = $this->wPrint;
1727
        } else {
1728
            $maxW = $this->wPrint - $this->wCanhoto;
1729
        }
1730
        $w = $maxW;
1731
        $h = 13;
1732
        $texto = 'DADOS ESPECÍFICOS DO MODAL RODOVIÁRIO';
1733
        $aFont = $this->formatPadrao;
1734
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1735
1736
        $y += 3.4;
1737
        $this->pdf->Line($x, $y, $w + 1, $y);
1738
        $texto = 'TERMO DE AUTORIZAÇÃO DE FRETAMENTO';
1739
        $aFont = $this->formatPadrao;
1740
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1741
1742
        $x += $w * 0.26;
1743
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1744
        $texto = 'Nº DE REGISTRO ESTADUAL';
1745
        $aFont = $this->formatPadrao;
1746
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1747
1748
        $wCol02=0.18;
1749
        $x += $w * $wCol02;
1750
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1751
        $texto = 'PLACA DO VEÍCULO';
1752
        $aFont = $this->formatPadrao;
1753
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1754
1755
        $x += $w * $wCol02;
1756
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1757
        $texto = 'RENAVAM DO VEÍCULO';
1758
        $aFont = $this->formatPadrao;
1759
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1760
1761
        $x += $w * $wCol02;
1762
        $this->pdf->Line($x, $y, $x, $y + 9.5);
1763
        $texto = 'CNPJ/CPF';
1764
        $aFont = $this->formatPadrao;
1765
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1766
1767
        $x = $oldX;
1768
        $y = $y + 4;
1769
        $texto = $this->pSimpleGetValue($this->rodo, "TAF");
1770
        $aFont = $this->formatNegrito;
1771
        $this->pTextBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1772
        $x += $w * 0.26;
1773
1774
        $texto = $this->pSimpleGetValue($this->rodo, "NroRegEstadual");
1775
        $aFont = $this->formatNegrito;
1776
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1777
        $x += $w * $wCol02;
1778
1779
        $texto = $this->pSimpleGetValue($this->veic->item(0), "placa");
1780
        $aFont = $this->formatNegrito;
1781
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1782
        $x += $w * $wCol02;
1783
1784
        $texto = $this->pSimpleGetValue($this->veic->item(0), "RENAVAM");
1785
        $aFont = $this->formatNegrito;
1786
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1787
        $x += $w * $wCol02;
1788
1789
        $texto = !empty($this->pSimpleGetValue($this->veic->item(0), "CPF")) ?
1790
            $this->pSimpleGetValue($this->veic->item(0), "CPF") :
1791
            (!empty($this->pSimpleGetValue($this->veic->item(0), "CNPJ")) ?
1792
            $this->pSimpleGetValue($this->veic->item(0), "CNPJ") : '');
1793
        $aFont = $this->formatNegrito;
1794
        $this->pTextBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1795
1796
        /*$x += $w * 0.14;
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1797
        $texto = '';
1798
        $aFont = $this->formatNegrito;
1799
        $this->pTextBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');*/
1800
    } //fim da função zModalRod
1801
1802
    /**
1803
     * zModalAquaviario
1804
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1805
     *
1806
     * @param  number $x Posição horizontal canto esquerdo
1807
     * @param  number $y Posição vertical canto superior
1808
     * @return number Posição vertical final
1809
     */
1810
    protected function zModalAquaviario($x = 0, $y = 0)
1811
    {
1812
        $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...
1813
        $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...
1814
        if ($this->orientacao == 'P') {
1815
            $maxW = $this->wPrint;
1816
        } else {
1817
            $maxW = $this->wPrint - $this->wCanhoto;
1818
        }
1819
        $w = $maxW;
1820
        $h = 8.5;
1821
        $texto = 'DADOS ESPECÍFICOS DO MODAL AQUAVIÁRIO';
1822
        $aFont = $this->formatPadrao;
1823
        $this->pTextBox($x, $y, $w, $h * 3.2, $texto, $aFont, 'T', 'C', 1, '');
1824
        $y += 3.4;
1825
        $this->pdf->Line($x, $y, $w + 1, $y);
1826
        $texto = 'PORTO DE EMBARQUE';
1827
        $aFont = $this->formatPadrao;
1828
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1829
        $texto = $this->pSimpleGetValue($this->aquav, "prtEmb");
1830
        $aFont = $this->formatNegrito;
1831
        $this->pTextBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1832
        $x += $w * 0.50;
1833
        $this->pdf->Line($x, $y, $x, $y + 7.7);
1834
        $texto = 'PORTO DE DESTINO';
1835
        $aFont = $this->formatPadrao;
1836
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1837
        $texto = $this->pSimpleGetValue($this->aquav, "prtDest");
1838
        $aFont = $this->formatNegrito;
1839
        $this->pTextBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1840
        $y += 8;
1841
        $this->pdf->Line(208, $y, 1, $y);
1842
        $x = 1;
1843
        $texto = 'IDENTIFICAÇÃO DO NAVIO / REBOCADOR';
1844
        $aFont = $this->formatPadrao;
1845
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1846
        $texto = $this->pSimpleGetValue($this->aquav, "xNavio");
1847
        $aFont = $this->formatNegrito;
1848
        $this->pTextBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1849
        $x += $w * 0.50;
1850
        $this->pdf->Line($x, $y, $x, $y + 7.7);
1851
        $texto = 'VR DA B. DE CALC. AFRMM';
1852
        $aFont = $this->formatPadrao;
1853
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1854
        $texto = $this->pSimpleGetValue($this->aquav, "vPrest");
1855
        $aFont = $this->formatNegrito;
1856
        $this->pTextBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1857
        $x += $w * 0.17;
1858
        $this->pdf->Line($x, $y, $x, $y + 7.7);
1859
        $texto = 'VALOR DO AFRMM';
1860
        $aFont = $this->formatPadrao;
1861
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1862
        $texto = $this->pSimpleGetValue($this->aquav, "vAFRMM");
1863
        $aFont = $this->formatNegrito;
1864
        $this->pTextBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1865
        $x += $w * 0.12;
1866
        $this->pdf->Line($x, $y, $x, $y + 7.7);
1867
        $texto = 'TIPO DE NAVEGAÇÃO';
1868
        $aFont = $this->formatPadrao;
1869
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1870
        $texto = $this->pSimpleGetValue($this->aquav, "tpNav");
1871
        switch ($texto) {
1872
            case '0':
1873
                $texto = 'INTERIOR';
1874
                break;
1875
            case '1':
1876
                $texto = 'CABOTAGEM';
1877
                break;
1878
        }
1879
        $aFont = $this->formatNegrito;
1880
        $this->pTextBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1881
        $x += $w * 0.14;
1882
        $this->pdf->Line($x, $y, $x, $y + 7.7);
1883
        $texto = 'DIREÇÃO';
1884
        $aFont = $this->formatPadrao;
1885
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1886
        $texto = $this->pSimpleGetValue($this->aquav, "direc");
1887
        switch ($texto) {
1888
            case 'N':
1889
                $texto = 'NORTE';
1890
                break;
1891
            case 'L':
1892
                $texto = 'LESTE';
1893
                break;
1894
            case 'S':
1895
                $texto = 'SUL';
1896
                break;
1897
            case 'O':
1898
                $texto = 'OESTE';
1899
                break;
1900
        }
1901
        $aFont = $this->formatNegrito;
1902
        $this->pTextBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1903
        $y += 8;
1904
        $this->pdf->Line(208, $y, 1, $y);
1905
        $x = 1;
1906
        $texto = 'IDENTIFICAÇÃO DOS CONTEINERS';
1907
        $aFont = $this->formatPadrao;
1908
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1909
        if ($this->infNF->item(0) !== null && $this->infNF->item(0)->getElementsByTagName('infUnidCarga') !== null) {
1910
            $texto = $this->infNF
1911
                ->item(0)
1912
                ->getElementsByTagName('infUnidCarga')
1913
                ->item(0)
1914
                ->getElementsByTagName('idUnidCarga')
1915
                ->item(0)->nodeValue;
1916
        } elseif ($this->infNFe->item(0) !== null
1917
            && $this->infNFe->item(0)->getElementsByTagName('infUnidCarga') !== null
1918
        ) {
1919
            $texto = $this->infNFe
1920
                ->item(0)
1921
                ->getElementsByTagName('infUnidCarga')
1922
                ->item(0)
1923
                ->getElementsByTagName('idUnidCarga')
1924
                ->item(0)
1925
                ->nodeValue;
1926
        } elseif ($this->infOutros->item(0) !== null
1927
            && $this->infOutros->item(0)->getElementsByTagName('infUnidCarga') !== null
1928
        ) {
1929
            $texto = $this->infOutros
1930
                ->item(0)
1931
                ->getElementsByTagName('infUnidCarga')
1932
                ->item(0)
1933
                ->getElementsByTagName('idUnidCarga')
1934
                ->item(0)
1935
                ->nodeValue;
1936
        } else {
1937
            $texto = '';
1938
        }
1939
        $aFont = $this->formatNegrito;
1940
        $this->pTextBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1941
        $x += $w * 0.50;
1942
        $this->pdf->Line($x, $y, $x, $y + 7.7);
1943
        $texto = 'IDENTIFICAÇÃO DAS BALSAS';
1944
        $aFont = $this->formatPadrao;
1945
        $this->pTextBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1946
        $texto = '';
1947
        if ($this->pSimpleGetValue($this->aquav, "balsa") !== '') {
1948
            foreach ($this->aquav->getElementsByTagName('balsa') as $k => $d) {
1949
                if ($k == 0) {
1950
                    $texto = $this->aquav
1951
                        ->getElementsByTagName('balsa')
1952
                        ->item($k)
1953
                        ->getElementsByTagName('xBalsa')
1954
                        ->item(0)
1955
                        ->nodeValue;
1956
                } else {
1957
                    $texto = $texto
1958
                        . ' / '
1959
                        . $this->aquav
1960
                            ->getElementsByTagName('balsa')
1961
                            ->item($k)
1962
                            ->getElementsByTagName('xBalsa')
1963
                            ->item(0)
1964
                            ->nodeValue;
1965
                }
1966
            }
1967
        }
1968
        $aFont = $this->formatNegrito;
1969
        $this->pTextBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1970
    } //fim da função zModalRod
1971
1972
    /**
1973
     * zModalFerr
1974
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1975
     *
1976
     * @param  number $x Posição horizontal canto esquerdo
1977
     * @param  number $y Posição vertical canto superior
1978
     * @return number Posição vertical final
1979
     */
1980
    protected function zModalFerr($x = 0, $y = 0)
1981
    {
1982
        $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...
1983
        $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...
1984
        if ($this->orientacao == 'P') {
1985
            $maxW = $this->wPrint;
1986
        } else {
1987
            $maxW = $this->wPrint - $this->wCanhoto;
1988
        }
1989
        $w = $maxW;
1990
        $h = 19.6;
1991
        $texto = 'DADOS ESPECÍFICOS DO MODAL FERROVIÁRIO';
1992
        $aFont = $this->formatPadrao;
1993
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1994
        $y += 3.4;
1995
        $this->pdf->Line($x, $y, $w + 1, $y);
1996
        $texto = 'DCL';
1997
        $aFont = array(
1998
            'font' => $this->fontePadrao,
1999
            'size' => 7,
2000
            'style' => 'B');
2001
        $this->pTextBox($x, $y, $w * 0.25, $h, $texto, $aFont, 'T', 'C', 0, '');
2002
        $this->pdf->Line($x + 49.6, $y, $x + 49.6, $y + 3.5);
2003
        $texto = 'VAGÕES';
2004
        $aFont = array(
2005
            'font' => $this->fontePadrao,
2006
            'size' => 7,
2007
            'style' => 'B');
2008
        $this->pTextBox($x + 50, $y, $w * 0.5, $h, $texto, $aFont, 'T', 'C', 0, '');
2009
        $y += 3.4;
2010
        $this->pdf->Line($x, $y, $w + 1, $y);
2011
        // DCL
2012
        $texto = 'ID TREM';
2013
        $aFont = array(
2014
            'font' => $this->fontePadrao,
2015
            'size' => 6,
2016
            'style' => '');
2017
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2018
        $texto = $this->pSimpleGetValue($this->ferrov, "idTrem");
2019
        $aFont = array(
2020
            'font' => $this->fontePadrao,
2021
            'size' => 6,
2022
            'style' => 'B');
2023
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2024
        $x += $w * 0.06;
2025
        $y1 = $y + 12.5;
2026
        $this->pdf->Line($x, $y, $x, $y1);
2027
        $texto = 'NUM';
2028
        $aFont = array(
2029
            'font' => $this->fontePadrao,
2030
            'size' => 6,
2031
            'style' => '');
2032
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2033
        $texto = $this->pSimpleGetValue($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...
2034
        $aFont = array(
2035
            'font' => $this->fontePadrao,
2036
            'size' => 6,
2037
            'style' => 'B');
2038
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2039
        $x += $w * 0.06;
2040
        $this->pdf->Line($x, $y, $x, $y1);
2041
        $texto = 'SÉRIE';
2042
        $aFont = array(
2043
            'font' => $this->fontePadrao,
2044
            'size' => 6,
2045
            'style' => '');
2046
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2047
        $texto = $this->pSimpleGetValue($this->rem, "serie");
2048
        $aFont = array(
2049
            'font' => $this->fontePadrao,
2050
            'size' => 6,
2051
            'style' => 'B');
2052
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2053
        $x += $w * 0.06;
2054
        $this->pdf->Line($x, $y, $x, $y1);
2055
        $texto = 'EMISSÃO';
2056
        $aFont = array(
2057
            'font' => $this->fontePadrao,
2058
            'size' => 6,
2059
            'style' => '');
2060
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2061
        $texto = $this->pYmd2dmy($this->pSimpleGetValue($this->rem, "dEmi"));
2062
        $aFont = array(
2063
            'font' => $this->fontePadrao,
2064
            'size' => 6,
2065
            'style' => 'B');
2066
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2067
        // VAGOES
2068
        $x += $w * 0.06;
2069
        $this->pdf->Line($x, $y, $x, $y1);
2070
        $texto = 'NUM';
2071
        $aFont = array(
2072
            'font' => $this->fontePadrao,
2073
            'size' => 6,
2074
            'style' => '');
2075
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2076
        $texto = $this->pSimpleGetValue($this->ferrov, "nVag");
2077
        $aFont = array(
2078
            'font' => $this->fontePadrao,
2079
            'size' => 6,
2080
            'style' => 'B');
2081
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2082
        $x += $w * 0.06;
2083
        $this->pdf->Line($x, $y, $x, $y1);
2084
        $texto = 'TIPO';
2085
        $aFont = array(
2086
            'font' => $this->fontePadrao,
2087
            'size' => 6,
2088
            'style' => '');
2089
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2090
        $texto = $this->pSimpleGetValue($this->ferrov, "tpVag");
2091
        $aFont = array(
2092
            'font' => $this->fontePadrao,
2093
            'size' => 6,
2094
            'style' => 'B');
2095
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2096
        $x += $w * 0.06;
2097
        $this->pdf->Line($x, $y, $x, $y1);
2098
        $texto = 'CAPACIDADE';
2099
        $aFont = array(
2100
            'font' => $this->fontePadrao,
2101
            'size' => 6,
2102
            'style' => '');
2103
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2104
        $texto = $this->pSimpleGetValue($this->ferrov, "cap");
2105
        $aFont = array(
2106
            'font' => $this->fontePadrao,
2107
            'size' => 6,
2108
            'style' => 'B');
2109
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2110
        $x += $w * 0.08;
2111
        $this->pdf->Line($x, $y, $x, $y1);
2112
        $texto = 'PESO REAL/TON';
2113
        $aFont = array(
2114
            'font' => $this->fontePadrao,
2115
            'size' => 6,
2116
            'style' => '');
2117
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2118
        $texto = $this->pSimpleGetValue($this->ferrov, "pesoR");
2119
        $aFont = array(
2120
            'font' => $this->fontePadrao,
2121
            'size' => 6,
2122
            'style' => 'B');
2123
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2124
        $x += $w * 0.09;
2125
        $this->pdf->Line($x, $y, $x, $y1);
2126
        $texto = 'PESO BRUTO/TON';
2127
        $aFont = array(
2128
            'font' => $this->fontePadrao,
2129
            'size' => 6,
2130
            'style' => '');
2131
        $this->pTextBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2132
        $texto = $this->pSimpleGetValue($this->ferrov, "pesoBC");
2133
        $aFont = array(
2134
            'font' => $this->fontePadrao,
2135
            'size' => 6,
2136
            'style' => 'B');
2137
        $this->pTextBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2138
        $x += $w * 0.1;
2139
        $this->pdf->Line($x, $y, $x, $y1);
2140
        $texto = 'IDENTIFICAÇÃO DOS CONTÊINERES';
2141
        $aFont = array(
2142
            'font' => $this->fontePadrao,
2143
            'size' => 6,
2144
            'style' => '');
2145
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2146
        $texto = $this->pSimpleGetValue($this->ferrov, "nCont");
2147
        $aFont = array(
2148
            'font' => $this->fontePadrao,
2149
            'size' => 6,
2150
            'style' => 'B');
2151
        $this->pTextBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2152
        // FLUXO
2153
        $x = 1;
2154
        $y += 12.9;
2155
        $h1 = $h * 0.5 + 0.27;
2156
        $wa = round($w * 0.103) + 0.5;
2157
        $texto = 'FLUXO FERROVIARIO';
2158
        $aFont = $this->formatPadrao;
2159
        $this->pTextBox($x, $y, $wa, $h1, $texto, $aFont, 'T', 'C', 1, '');
2160
        $texto = $this->pSimpleGetValue($this->ferrov, "fluxo");
2161
        $aFont = array(
2162
            'font' => $this->fontePadrao,
2163
            'size' => 7,
2164
            'style' => 'B');
2165
        $this->pTextBox($x, $y + 3, $wa, $h1, $texto, $aFont, 'T', 'C', 0, '');
2166
        $y += 10;
2167
        $texto = 'TIPO DE TRÁFEGO';
2168
        $aFont = $this->formatPadrao;
2169
        $this->pTextBox($x, $y, $wa, $h1, $texto, $aFont, 'T', 'C', 1, '');
2170
        $texto = $this->zConvertUnidTrafego($this->pSimpleGetValue($this->ferrov, "tpTraf"));
2171
        $aFont = array(
2172
            'font' => $this->fontePadrao,
2173
            'size' => 7,
2174
            'style' => 'B');
2175
        $this->pTextBox($x, $y + 3, $wa, $h1, $texto, $aFont, 'T', 'C', 0, '');
2176
        // Novo Box Relativo a Modal Ferroviário
2177
        $x = 22.5;
2178
        $y += -10.2;
2179
        $texto = 'INFORMAÇÕES DAS FERROVIAS ENVOLVIDAS';
2180
        $aFont = $this->formatPadrao;
2181
        $this->pTextBox($x, $y, $w - 21.5, $h1 * 2.019, $texto, $aFont, 'T', 'C', 1, '');
2182
        $y += 3.4;
2183
        $this->pdf->Line($x, $y, $w + 1, $y);
2184
        $w = $w * 0.2;
2185
        $h = $h * 1.04;
2186
        $texto = 'CÓDIGO INTERNO';
2187
        $aFont = array(
2188
            'font' => $this->fontePadrao,
2189
            'size' => 6,
2190
            'style' => '');
2191
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2192
        $texto = $this->pSimpleGetValue($this->ferrov, "cInt");
2193
        $aFont = array(
2194
            'font' => $this->fontePadrao,
2195
            'size' => 6,
2196
            'style' => 'B');
2197
        $this->pTextBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2198
        $texto = 'CNPJ';
2199
        $aFont = array(
2200
            'font' => $this->fontePadrao,
2201
            'size' => 6,
2202
            'style' => '');
2203
        $this->pTextBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2204
        $texto = $this->pSimpleGetValue($this->ferrov, "CNPJ");
2205
        $aFont = array(
2206
            'font' => $this->fontePadrao,
2207
            'size' => 6,
2208
            'style' => 'B');
2209
        $this->pTextBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2210
        $x += 50;
2211
        $texto = 'NOME';
2212
        $aFont = array(
2213
            'font' => $this->fontePadrao,
2214
            'size' => 6,
2215
            'style' => '');
2216
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2217
        $texto = $this->pSimpleGetValue($this->ferrov, "xNome");
2218
        $aFont = array(
2219
            'font' => $this->fontePadrao,
2220
            'size' => 6,
2221
            'style' => 'B');
2222
        $this->pTextBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2223
        $texto = 'INSCRICAO ESTADUAL';
2224
        $aFont = array(
2225
            'font' => $this->fontePadrao,
2226
            'size' => 6,
2227
            'style' => '');
2228
        $this->pTextBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2229
        $texto = $this->pSimpleGetValue($this->ferrov, "IE");
2230
        $aFont = array(
2231
            'font' => $this->fontePadrao,
2232
            'size' => 6,
2233
            'style' => 'B');
2234
        $this->pTextBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2235
        $x += 50;
2236
        $texto = 'PARTICIPAÇÃO OUTRA FERROVIA';
2237
        $aFont = array(
2238
            'font' => $this->fontePadrao,
2239
            'size' => 6,
2240
            'style' => '');
2241
        $this->pTextBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2242
        $texto = '';
2243
        $aFont = array(
2244
            'font' => $this->fontePadrao,
2245
            'size' => 6,
2246
            'style' => 'B');
2247
        $this->pTextBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2248
    } //fim da função zModalFerr
2249
2250
    /**
2251
     * zCanhoto
2252
     * Monta o campo com os dados do remetente na DACTE.
2253
     *
2254
     * @param  number $x Posição horizontal canto esquerdo
2255
     * @param  number $y Posição vertical canto superior
2256
     * @return number Posição vertical final
2257
     */
2258
    protected function zCanhoto($x = 0, $y = 0)
2259
    {
2260
        $this->zhDashedLine($x, $y+2, $this->wPrint, 0.1, 80);
2261
        $y = $y + 2;
2262
        $oldX = $x;
2263
        $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...
2264
        if ($this->orientacao == 'P') {
2265
            $maxW = $this->wPrint;
2266
        } else {
2267
            $maxW = $this->wPrint - $this->wCanhoto;
2268
        }
2269
        $w = $maxW - 1;
2270
        $h = 20;
2271
        $y = $y + 1;
2272
        $texto = 'DECLARO QUE RECEBI OS VOLUMES DESTE CONHECIMENTO EM PERFEITO ESTADO ';
2273
        $texto .= 'PELO QUE DOU POR CUMPRIDO O PRESENTE CONTRATO DE TRANSPORTE';
2274
        $aFont = $this->formatPadrao;
2275
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2276
        $y += 3.4;
2277
        $this->pdf->Line($x, $y, $w + 1, $y); // LINHA ABAICO DO TEXTO DECLARO QUE RECEBI...
2278
2279
        $texto = 'NOME';
2280
        $aFont = array(
2281
            'font' => $this->fontePadrao,
2282
            'size' => 6,
2283
            'style' => '');
2284
        $this->pTextBox($x, $y, $w * 0.25, $h, $texto, $aFont, 'T', 'L', 0, '');
2285
        $x += $w * 0.25;
2286
2287
        $this->pdf->Line($x, $y, $x, $y + 16.5);
2288
2289
        $texto = 'ASSINATURA / CARIMBO';
2290
        $aFont = array(
2291
            'font' => $this->fontePadrao,
2292
            'size' => 6,
2293
            'style' => '');
2294
        $this->pTextBox($x, $y, $w * 0.25, $h - 3.4, $texto, $aFont, 'B', 'C', 0, '');
2295
        $x += $w * 0.25;
2296
2297
        $this->pdf->Line($x, $y, $x, $y + 16.5);
2298
2299
        $texto = 'TÉRMINO DA PRESTAÇÃO - DATA/HORA' . "\r\n" . "\r\n" . "\r\n". "\r\n";
2300
        $texto .= ' INÍCIO DA PRESTAÇÃO - DATA/HORA';
2301
        $aFont = array(
2302
            'font' => $this->fontePadrao,
2303
            'size' => 6,
2304
            'style' => '');
2305
        $this->pTextBox($x + 10, $y, $w * 0.25, $h - 3.4, $texto, $aFont, 'T', 'C', 0, '');
2306
        $x = $oldX;
2307
        $y = $y + 5;
2308
2309
        $this->pdf->Line($x, $y+3, $w * 0.255, $y+3); // LINHA HORIZONTAL ACIMA DO RG ABAIXO DO NOME
2310
2311
        $texto = 'RG';
2312
        $aFont = array(
2313
            'font' => $this->fontePadrao,
2314
            'size' => 6,
2315
            'style' => '');
2316
        $this->pTextBox($x, $y+3, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
2317
        $x += $w * 0.85;
2318
2319
        $this->pdf->Line($x, $y + 11.5, $x, $y - 5); // LINHA VERTICAL PROXIMO AO CT-E
2320
2321
        $texto = "CT-E OS";
2322
        $aFont = $this->formatNegrito;
2323
        $this->pTextBox($x, $y - 5, $w * 0.15, $h, $texto, $aFont, 'T', 'C', 0, '');
2324
        $texto = "\r\n Nº. DOCUMENTO  " . $this->pSimpleGetValue($this->ide, "nCT") . " \n";
2325
        $texto .= "\r\n SÉRIE  " . $this->pSimpleGetValue($this->ide, "serie");
2326
        $aFont = array(
2327
            'font' => $this->fontePadrao,
2328
            'size' => 6,
2329
            'style' => '');
2330
        $this->pTextBox($x, $y - 8, $w * 0.15, $h, $texto, $aFont, 'C', 'C', 0, '');
2331
        $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...
2332
        //$this->zhDashedLine($x, $y + 7.5, $this->wPrint, 0.1, 80);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2333
    } //fim da função canhotoDACTE
2334
2335
    /**
2336
     * zDadosAdic
2337
     * Coloca o grupo de dados adicionais da DACTE.
2338
     *
2339
     * @param  number $x Posição horizontal canto esquerdo
2340
     * @param  number $y Posição vertical canto superior
2341
     * @param  number $h altura do campo
2342
     * @return number Posição vertical final
2343
     */
2344
    protected function zDadosAdic($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...
2345
    {
2346
        $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...
2347
        //###########################################################################
2348
        //DADOS ADICIONAIS DACTE
2349
        if ($this->orientacao == 'P') {
2350
            $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...
2351
        } else {
2352
            $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...
2353
        }
2354
        //INFORMAÇÕES COMPLEMENTARES
2355
        $texto = "USO EXCLUSIVO DO EMISSOR DO CT-E";
2356
        $y += 3;
2357
        $w = $this->wAdic;
2358
        $h = 20; //mudar
2359
        $aFont = array(
2360
            'font' => $this->fontePadrao,
2361
            'size' => 6,
2362
            'style' => '');
2363
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2364
        //$this->pdf->Line($x, $y + 3, $w * 1.385, $y + 3);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2365
        $this->pdf->Line($x, $y + 3, $w * 1.385, $y + 3);
2366
        //o texto com os dados adicionais foi obtido na função xxxxxx
2367
        //e carregado em uma propriedade privada da classe
2368
        //$this->wAdic com a largura do campo
2369
        //$this->textoAdic com o texto completo do campo
2370
        $y += 1;
2371
        $aFont = $this->formatPadrao;
2372
        $this->pTextBox($x, $y + 3, $w - 2, $h - 3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2373
        //RESERVADO AO FISCO
2374
        $texto = "RESERVADO AO FISCO";
2375
        $x += $w;
2376
        $y -= 1;
2377
        if ($this->orientacao == 'P') {
2378
            $w = $this->wPrint - $w;
2379
        } else {
2380
            $w = $this->wPrint - $w - $this->wCanhoto;
2381
        }
2382
        $aFont = array(
2383
            'font' => $this->fontePadrao,
2384
            'size' => 6,
2385
            'style' => '');
2386
        $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2387
        //inserir texto informando caso de contingência
2388
        //1 – Normal – emissão normal;
2389
        //2 – Contingência FS – emissão em contingência com impressão do DACTE em Formulário de Segurança;
2390
        //3 – Contingência SCAN – emissão em contingência  – SCAN;
2391
        //4 – Contingência DPEC - emissão em contingência com envio da Declaração Prévia de
2392
        //Emissão em Contingência – DPEC;
2393
        //5 – Contingência FS-DA - emissão em contingência com impressão do DACTE em Formulário de
2394
        //Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA).
2395
        $xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: ');
2396
        $dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2397
        $texto = '';
2398
        switch ($this->tpEmis) {
2399
            case 2:
2400
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2401
                break;
2402
            case 3:
2403
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2404
                break;
2405
            case 4:
2406
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2407
                break;
2408
            case 5:
2409
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2410
                break;
2411
        }
2412
        $y += 2;
2413
        $aFont = $this->formatPadrao;
2414
        $this->pTextBox($x, $y + 2, $w - 2, $h - 3, $texto, $aFont, 'T', 'L', 0, '', false);
2415
        return $y + $h;
2416
    } //fim zDadosAdic
2417
2418
    /**
2419
     * zhDashedLine
2420
     * Desenha uma linha horizontal tracejada com o FPDF
2421
     *
2422
     * @param  number $x Posição horizontal inicial, em mm
2423
     * @param  number $y Posição vertical inicial, em mm
2424
     * @param  number $w Comprimento da linha, em mm
2425
     * @param  number $h Espessura da linha, em mm
2426
     * @param  number $n Numero de traços na seção da linha com o comprimento $w
2427
     * @return none
2428
     */
2429
    protected function zhDashedLine($x, $y, $w, $h, $n)
2430
    {
2431
        $this->pdf->SetLineWidth($h);
2432
        $wDash = ($w / $n) / 2; // comprimento dos traços
2433
        for ($i = $x; $i <= $x + $w; $i += $wDash + $wDash) {
2434
            for ($j = $i; $j <= ($i + $wDash); $j++) {
2435
                if ($j <= ($x + $w - 1)) {
2436
                    $this->pdf->Line($j, $y, $j + 1, $y);
2437
                }
2438
            }
2439
        }
2440
    } //fim função hDashedLine
2441
2442
    /**
2443
     * zhDashedVerticalLine
2444
     * Desenha uma linha vertical tracejada com o FPDF
2445
     *
2446
     * @param  number $x Posição horizontal inicial, em mm
2447
     * @param  number $y Posição vertical inicial, em mm
2448
     * @param  number $w Comprimento da linha, em mm
2449
     * @param  number $yfinal Espessura da linha, em mm
2450
     * @param  number $n Numero de traços na seção da linha com o comprimento $w
2451
     * @return none
2452
     */
2453
    protected function zhDashedVerticalLine($x, $y, $w, $yfinal, $n)
2454
    {
2455
        $this->pdf->SetLineWidth($w);
2456
        /* Organizando valores */
2457
        if ($y > $yfinal) {
2458
            $aux = $yfinal;
2459
            $yfinal = $y;
2460
            $y = $aux;
2461
        }
2462
        while ($y < $yfinal && $n > 0) {
2463
            $this->pdf->Line($x, $y, $x, $y + 1);
2464
            $y += 3;
2465
            $n--;
2466
        }
2467
    } //fim função hDashedVerticalLine
2468
2469
    /**
2470
     * zFormatCNPJCPF
2471
     * Formata campo CnpjCpf contida na CTe
2472
     *
2473
     * @param  string $field campo cnpjCpf da CT-e
2474
     * @return string
2475
     */
2476
    protected function zFormatCNPJCPF($field)
2477
    {
2478
        if (!isset($field)) {
2479
            return '';
2480
        }
2481
        $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...
2482
            $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...
2483
        if ($cnpj != "" && $cnpj != "00000000000000") {
2484
            $cnpj = $this->pFormat($cnpj, '###.###.###/####-##');
2485
        } else {
2486
            $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...
2487
                $this->pFormat($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...
2488
        }
2489
        return $cnpj;
2490
    } //fim formatCNPJCPF
2491
2492
    /**
2493
     * zFormatFone
2494
     * Formata campo fone contida na CTe
2495
     *
2496
     * @param  string $field campo fone da CT-e
2497
     * @return string
2498
     */
2499
    protected function zFormatFone($field)
2500
    {
2501
        try {
2502
            $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...
2503
            $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...
2504
            $foneLen = strlen($fone);
2505
            if ($foneLen > 0) {
2506
                $fone2 = substr($fone, 0, $foneLen - 4);
2507
                $fone1 = substr($fone, 0, $foneLen - 8);
2508
                $fone = '(' . $fone1 . ') ' . substr($fone2, -4) . '-' . substr($fone, -4);
2509
            } else {
2510
                $fone = '';
2511
            }
2512
            return $fone;
2513
        } catch (Exception $exc) {
2514
            return '';
2515
        }
2516
    } //fim formatFone
2517
2518
    /**
2519
     * zUnidade
2520
     * Converte a imformação de peso contida na CTe
2521
     *
2522
     * @param  string $c unidade de trafego extraida da CTe
2523
     * @return string
2524
     */
2525
    protected function zUnidade($c = '')
2526
    {
2527
        switch ($c) {
2528
            case '00':
2529
                $r = 'M3';
2530
                break;
2531
            case '01':
2532
                $r = 'KG';
2533
                break;
2534
            case '02':
2535
                $r = 'TON';
2536
                break;
2537
            case '03':
2538
                $r = 'UN';
2539
                break;
2540
            case '04':
2541
                $r = 'LT';
2542
                break;
2543
            case '05':
2544
                $r = 'MMBTU';
2545
                break;
2546
            default:
2547
                $r = '';
2548
        }
2549
        return $r;
2550
    } //fim unidade
2551
2552
    /**
2553
     * zConvertUnidTrafego
2554
     * Converte a imformação de peso contida na CTe
2555
     *
2556
     * @param  string $U Informação de trafego extraida da CTe
2557
     * @return string
2558
     */
2559
    protected function zConvertUnidTrafego($U = '')
2560
    {
2561
        if ($U) {
2562
            switch ($U) {
2563
                case '0':
2564
                    $stringU = 'Próprio';
2565
                    break;
2566
                case '1':
2567
                    $stringU = 'Mútuo';
2568
                    break;
2569
                case '2':
2570
                    $stringU = 'Rodoferroviário';
2571
                    break;
2572
                case '3':
2573
                    $stringU = 'Rodoviário';
2574
                    break;
2575
            }
2576
            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...
2577
        }
2578
    } //fim da função zConvertUnidTrafego
2579
2580
    /**
2581
     * zMultiUniPeso
2582
     * Fornece a imformação multiplicação de peso contida na CTe
2583
     *
2584
     * @param  interger $U Informação de peso extraida da CTe
2585
     * @return interger
2586
     */
2587
    protected function zMultiUniPeso($U = '')
2588
    {
2589
        if ($U === "01") {
2590
            // tonelada
2591
            //return 1000;
2592
            return 1;
2593
        }
2594
        return 1; // M3, KG, Unidade, litros, mmbtu
2595
    } //fim da função zMultiUniPeso
2596
}
2597