Passed
Push — master ( b6c7f7...cb9572 )
by Roberto
09:19 queued 06:19
created

Dabpe::checkCancelada()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\BPe;
4
5
/**
6
 * Classe para a impressão em PDF do Documento Auxiliar de Bilhete de Passagem eletronico
7
 * NOTA: Esta classe não é a indicada para quem faz uso de impressoras térmicas ESCPOS
8
 *
9
* @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @copyright 2009-2020 NFePHP
12
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3 or MIT
13
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
14
 * @author    Roberto L. Machado <linux at rlm dot gmail dot com>
15
 */
16
17
use \Exception;
18
use InvalidArgumentException;
19
use NFePHP\DA\Legacy\Dom;
20
use NFePHP\DA\Legacy\Pdf;
21
use NFePHP\DA\Common\DaCommon;
22
use Com\Tecnick\Barcode\Barcode;
23
use \DateTime;
24
25
class Dabpe extends DaCommon
26
{
27
    /**
28
     * @var array
29
     */
30
    protected $aFontTit;
31
    /**
32
     * @var array
33
     */
34
    protected $aFontTex;
35
    /**
36
     * @var int
37
     */
38
    protected $paperwidth = 80;
39
    /**
40
     * @var string
41
     */
42
    protected $creditos;
43
    /**
44
     * @var string
45
     */
46
    protected $xml; // string XML BPe
47
    /**
48
     * @var \NFePHP\DA\Legacy\Dom
49
     */
50
    protected $dom;
51
    /**
52
     * @var \DOMElement
53
     */
54
    protected $infBPe;
55
    /**
56
     * @var \DOMElement
57
     */
58
    protected $ide;
59
    /**
60
     * @var \DOMElement
61
     */
62
    protected $agencia;
63
    /**
64
     * @var \DOMElement
65
     */
66
    protected $enderAgencia;
67
    /**
68
     * @var \DOMElement
69
     */
70
    protected $emit;
71
    /**
72
     * @var \DOMElement
73
     */
74
    protected $enderEmit;
75
    /**
76
     * @var \DOMElement
77
     */
78
    protected $infViagem;
79
    /**
80
     * @var \DOMElement
81
     */
82
    protected $infPassagem;
83
    /**
84
     * @var \DOMElement
85
     */
86
    protected $infPassageiro;
87
    /**
88
     * @var \DOMElement
89
     */
90
    protected $infValorBPe;
91
    /**
92
     * @var \DOMNodeList
93
     */
94
    protected $Comp;
95
    /**
96
     * @var \DOMNodeList
97
     */
98
    protected $pag;
99
    /**
100
     * @var \DOMElement
101
     */
102
    protected $infProt;
103
    /**
104
     * @var int
105
     */
106
    protected $tpEmis;
107
    /**
108
     * @var \DOMElement
109
     */
110
    protected $nBP;
111
    /**
112
     * @var \DOMElement
113
     */
114
    protected $protBPe;
115
    /**
116
     * @var \DOMElement
117
     */
118
    protected $ICMSSN;
119
    /**
120
     * @var string
121
     */
122
    protected $dhCont;
123
    /**
124
     * @var string
125
     */
126
    protected $cUF;
127
    /**
128
     * @var \DOMElement
129
     */
130
    protected $infBPeSupl;
131
    /**
132
     * @var string|null
133
     */
134
    protected $qrCodBPe;
135
    /**
136
     * @var string
137
     */
138
    protected $urlChave;
139
    /**
140
     * @var string
141
     */
142
    protected $infAdic;
143
    /**
144
     * @var string
145
     */
146
    protected $textoAdic;
147
    /**
148
     * @var int
149
     */
150
    protected $margemInterna = 2;
151
    /**
152
     * @var int
153
     */
154
    protected $hMaxLinha = 9;
155
    /**
156
     * @var int
157
     */
158
    protected $hBoxLinha = 6;
159
    /**
160
     * @var int
161
     */
162
    protected $hLinha = 3;
163
164
    /**
165
     * Construtor
166
     * @param string $xml
167
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
168
     * @throws \Exception
169
     */
170
    public function __construct(
171
        $xml
172
    ) {
173
        $this->xml = $xml;
174
        $this->aFontTit = array('font' => $this->fontePadrao, 'size' => 9, 'style' => 'B');
175
        $this->aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
176
        if (empty($this->xml)) {
177
            throw new \Exception('É necessário passar um XML de BPe.');
178
        }
179
        $this->dom = new Dom();
180
        $this->dom->loadXML($this->xml);
181
        $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
182
        if ($this->getTagValue($this->ide, "mod") != '63') {
183
            throw new \Exception("O xml do DOCUMENTO deve ser uma BPe modelo 63");
184
        }
185
        $this->protBPe = $this->dom->getElementsByTagName("protBPe")->item(0);
186
        $this->infBPe = $this->dom->getElementsByTagName("infBPe")->item(0);
187
        $this->agencia = $this->dom->getElementsByTagName("agencia")->item(0);
188
        $this->enderAgencia = $this->dom->getElementsByTagName("enderAgencia")->item(0);
189
        $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
190
        $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
191
        $this->infViagem = $this->dom->getElementsByTagName("infViagem")->item(0);
192
        $this->infPassagem = $this->dom->getElementsByTagName("infPassagem")->item(0);
193
        $this->infPassageiro = $this->dom->getElementsByTagName("infPassageiro")->item(0);
194
        $this->infValorBPe = $this->dom->getElementsByTagName("infValorBPe")->item(0);
195
        $this->Comp = $this->dom->getElementsByTagName("Comp");
196
        $this->pag = $this->dom->getElementsByTagName("pag");
197
        $this->infProt = $this->dom->getElementsByTagName("infProt")->item(0);
198
        $this->tpEmis = (int) $this->dom->getElementsByTagName('tpEmis')->item(0)->nodeValue;
199
        $this->nBP = $this->dom->getElementsByTagName("nBP")->item(0);
200
        $this->ICMSSN = !empty($this->dom->getElementsByTagName("ICMSSN")->item(0))
0 ignored issues
show
Documentation Bug introduced by
It seems like !empty($this->dom->getEl...'ICMSSN')->item(0) : '' of type object<DOMNode> or string is incompatible with the declared type object<DOMElement> of property $ICMSSN.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
201
            ? $this->dom->getElementsByTagName("ICMSSN")->item(0) : '';
202
        $this->dhCont = $this->getTagValue($this->ide, "dhCont") ?? '';
203
        $this->cUF = $this->getTagValue($this->ide, "cUF") ?? '';
204
        $this->infBPeSupl = !empty($this->dom->getElementsByTagName("infBPeSupl")->item(0))
0 ignored issues
show
Documentation Bug introduced by
It seems like !empty($this->dom->getEl...eSupl')->item(0) : null can also be of type object<DOMNode>. However, the property $infBPeSupl is declared as type object<DOMElement>. 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...
205
            ? $this->dom->getElementsByTagName("infBPeSupl")->item(0) : null;
206
        $this->qrCodBPe = !empty($this->dom->getElementsByTagName('qrCodBPe')->item(0)->nodeValue)
207
            ? $this->dom->getElementsByTagName('qrCodBPe')->item(0)->nodeValue : null;
208
        $this->urlChave = $this->urlConsulta($this->cUF);
209
    }
210
    
211
    /**
212
     * Seta a largura do papel de impressão
213
     * @param int $width
214
     */
215
    public function setPaperWidth($width = 80)
216
    {
217
        $this->paperwidth = $width;
218
    }
219
    
220
    public function printParameters($orientacao = '', $papel = 'A4', $margSup = 2, $margEsq = 2)
221
    {
222
        //do nothing
223
    }
224
    
225
    /**
226
     * Renderiza o pdf e retorna como raw
227
     * @param string $logo
228
     * @return string
229
     */
230
    public function render(
231
        $logo = ''
232
    ) {
233
        if (empty($this->pdf)) {
234
            $this->monta($logo);
235
        }
236
        return $this->pdf->getPdf();
237
    }
238
239
    /**
240
     * Busca a url de consulta
241
     * @param string $uf
242
     * @return string
243
     */
244
    protected function urlConsulta($uf)
245
    {
246
        switch ($uf) {
247
            case "11": // Rondônia
248
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
249
                break;
250
            case "12": //Acre
251
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
252
                break;
253
            case "13": //Amazonas
254
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
255
                break;
256
            case "14": //Roraima
257
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
258
                break;
259
            case "15": //Pará
260
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
261
                break;
262
            case "16": //Amapá
263
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
264
                break;
265
            case "17": //Tocantins
266
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
267
                break;
268
            case "21": //Maranhão
269
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
270
                break;
271
            case "22": //Piauí
272
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
273
                break;
274
            case "23": //Ceará
275
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
276
                break;
277
            case "24": //Rio Grande do Norte
278
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
279
                break;
280
            case "25": //Paraíba
281
                $url = "https://www.sefaz.pb.gov.br/bpe/consulta";
282
                break;
283
            case "26": //Pernambuco
284
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
285
                break;
286
            case "27": //Alagoas
287
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
288
                break;
289
            case "28": //Sergipe
290
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
291
                break;
292
            case "29": //Bahia
293
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
294
                break;
295
            case "31": //Minas Gerais
296
                $url = "https://bpe.fazenda.mg.gov.br/portalbpe/sistema/consultaarg.xhtml";
297
                break;
298
            case "32": //Espírito Santo
299
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
300
                break;
301
            case "33": //Rio de Janeiro
302
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
303
                break;
304
            case "35": //São Paulo
305
                $url = "https://bpe.fazenda.sp.gov.br/BPe/";
306
                break;
307
            case "41": //Paraná
308
                $url = "http://www.sped.fazenda.pr.gov.br/modules/conteudo/bpe.php?consulta=completa";
309
                break;
310
            case "42": //Santa Catarina(Não usa BPE)
311
                $url = "";
312
                break;
313
            case "43": //Rio Grande do Sul (*)
314
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
315
                break;
316
            case "50": //Mato Grosso do Sul
317
                $url = "http://www.dfe.ms.gov.br/bpe/#/consulta";
318
                break;
319
            case "51": //Mato Grosso
320
                $url = "https://www.sefaz.mt.gov.br/BPe/consulta";
321
                break;
322
            case "52": //Goiás
323
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
324
                break;
325
            case "53": //Distrito Federal
326
                $url = "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
327
                break;
328
            default:
329
                $url = '';
330
        }
331
        return $url;
332
    }
333
334
    /**
335
     * Monta o pdf
336
     * @param string|null $logo
337
     */
338
    protected function monta(
339
        $logo = null
340
    ) {
341
        if (!empty($logo)) {
342
            $this->logomarca = $this->adjustImage($logo, true);
343
        }
344
        $qtdItens = $this->Comp->length;
345
        $qtdPgto = $this->pag->length;
346
        $hMaxLinha = $this->hMaxLinha;
0 ignored issues
show
Unused Code introduced by
$hMaxLinha 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...
347
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha 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...
348
        $hLinha = $this->hLinha;
349
        $tamPapelVert = 190 + (($qtdItens - 1) * $hLinha) + ($qtdPgto * $hLinha);
350
        // verifica se existe informações adicionais
351
        $this->orientacao = 'P';
352
        $this->papel = [$this->paperwidth, $tamPapelVert];
353
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer,{"...nteger","1":"integer"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
354
355
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
356
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
357
        //apenas para controle se necessário ser maior do que a margem superior
358
        $margSup = 2;
359
        $margEsq = 2;
360
        $margInf = 2;
361
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
362
        $xInic = $margEsq;
363
        $yInic = $margSup;
364
        $maxW = $this->paperwidth;
365
        $maxH = $tamPapelVert;
366
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
367
        $this->wPrint = $maxW - ($margEsq * 2);
0 ignored issues
show
Documentation Bug introduced by
The property $wPrint was declared of type double, but $maxW - $margEsq * 2 is of type integer. Maybe add a type cast?

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

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

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
368
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
369
        //superior e inferior
370
        $this->hPrint = $maxH - $margSup - $margInf;
0 ignored issues
show
Documentation Bug introduced by
The property $hPrint was declared of type double, but $maxH - $margSup - $margInf is of type integer. Maybe add a type cast?

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

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

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
371
        // estabelece contagem de paginas
372
        $this->pdf->aliasNbPages();
373
        $this->pdf->setMargins($margEsq, $margSup); // fixa as margens
374
        $this->pdf->setDrawColor(0, 0, 0);
375
        $this->pdf->setFillColor(255, 255, 255);
376
        $this->pdf->open(); // inicia o documento
377
        $this->pdf->addPage($this->orientacao, $this->papel); // adiciona a primeira página
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer,{"...nteger","1":"integer"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
378
        $this->pdf->setLineWidth(0.1); // define a largura da linha
379
        $this->pdf->setTextColor(0, 0, 0);
380
        $this->pdf->textBox(0, 0, $maxW, $maxH); // POR QUE PRECISO DESA LINHA?
381
        $hcabecalho = 16;//para cabeçalho (dados emitente mais logomarca)  (FIXO)
382
        if (strlen($this->getTagValue($this->emit, "xNome")) > 40) {
383
            $hcabecalho += 2;
384
            $tamPapelVert += 2;
385
        };
386
        $hcabecalhoSecundario = 18;//para cabeçalho secundário (cabeçalho sefaz) (FIXO)
387
        $hagencia = 0;
388
        if (!empty($this->agencia)) {
389
            if (strlen($this->getTagValue($this->agencia, "xNome")) > 39) {
390
                $hagencia += 2;
391
                $tamPapelVert += 2;
392
            };
393
            $hagencia += 20;
394
            $tamPapelVert += 18;
395
        }
396
        $hprodutos = $hLinha + ($qtdItens * $hLinha);//box poduto
397
        $hTotal = 12; //box total (FIXO)
398
        $hpagamentos = (2 * $hLinha) + ($qtdPgto * $hLinha);//para pagamentos
399
        if (!empty($this->vTroco)) {
0 ignored issues
show
Bug introduced by
The property vTroco 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...
400
            $hpagamentos += $hLinha;
401
        }
402
403
        $hmsgfiscal = 28; // para imposto (FIXO)
404
        $hcliente = !isset($this->dest) ? 6 : 12; // para cliente (FIXO)
405
        $hcontingencia = $this->tpEmis == 9 ? 6 : 0; // para contingência (FIXO)
0 ignored issues
show
Unused Code introduced by
$hcontingencia 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...
406
        $hQRCode = 50; // para qrcode (FIXO)
407
        $hCabecItens = 4; //cabeçalho dos itens
408
409
        $hUsado = $hCabecItens;
0 ignored issues
show
Unused Code introduced by
$hUsado 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...
410
        $w2 = round($this->wPrint * 0.31, 0);
0 ignored issues
show
Unused Code introduced by
$w2 is not used, you could remove the assignment.

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

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

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

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

Loading history...
411
        $x = $xInic;
412
        //COLOCA CABEÇALHO
413
        $y = $yInic;
414
        if (!empty($this->agencia)) {
415
            $y += $this->cabecalhoAgencia($x, $y, $hagencia);
416
            if (!empty($this->dhCont)) {
417
                $hcabecalho = $hcabecalho + ($this->hLinha * 2);
418
            }
419
            $y += $this->cabecalhoDABPE($x, $y, $hcabecalho);
420
            $hcabecalho = $hcabecalho + $hagencia;
421
        } else {
422
            if (!empty($this->dhCont)) {
423
                $hcabecalho = $hcabecalho + ($this->hLinha * 2);
424
            }
425
            $y += $this->cabecalhoDABPE($x, $y, $hcabecalho) + 2;
426
        }
427
        //COLOCA CABEÇALHO SECUNDÁRIO
428
        $y += $this->cabecalhoSecundarioDABPE($x, $y, $hcabecalhoSecundario);
429
        //COLOCA Componentes
430
        $y += $this->produtosDABPE($x, $y, $hprodutos);
431
        //COLOCA TOTAL
432
        $y += $this->totalDABPE($x, $y, $hTotal);
433
        //COLOCA PAGAMENTOS
434
        $y += $this->pagamentosDABPE($x, $y, $hpagamentos);
435
        //COLOCA MENSAGEM FISCAL
436
        $y += $this->fiscalDABPE($x, $y, $hmsgfiscal);
437
        //COLOCA QRCODE
438
        $y += $this->qrCodeDABPE($x, $y, $hQRCode);
439
        //adiciona as informações opcionais
440
        if (!empty($this->textoAdic)) {
441
            $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos
442
                + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente + $hQRCode;
443
            $hInfAdic = 0;
444
            $y = $this->infAdic($x, $y, $hInfAdic);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->infAdic($x, $y, $hInfAdic) (which targets NFePHP\DA\BPe\Dabpe::infAdic()) seems to always return null.

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

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

}

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

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

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

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

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

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

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

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

Loading history...
445
        }
446
        //creditos do integrador
447
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
448
        $this->pdf->textBox($x, $this->hPrint-1, $this->wPrint, 3, $this->creditos, $aFont, 'T', 'L', false, '', false);
449
        $texto = "Powered by NFePHP®";
450
        $this->pdf->textBox($x, $this->hPrint-1, $this->wPrint, 0, $texto, $aFont, 'T', 'R', false, '');
451
    }
452
453
    /**
454
     * Coloca o cabeçalho da agencia
455
     * @param float $x
456
     * @param float $y
457
     * @param float $h
458
     * @return float
459
     */
460
    protected function cabecalhoAgencia($x = 0.0, $y = 0.0, $h = 0.0)
0 ignored issues
show
Unused Code introduced by
The parameter $x 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...
461
    {
462
        $hTotal = 0;
463
        $agenciaRazao = $this->getTagValue($this->agencia, "xNome");
464
        $agenciaCnpj = $this->getTagValue($this->agencia, "CNPJ");
465
        $agenciaCnpj = $this->formatField($agenciaCnpj, "##.###.###/####-##");
466
        $agenciaLgr = $this->getTagValue($this->enderAgencia, "xLgr");
467
        $agenciaNro = $this->getTagValue($this->enderAgencia, "nro");
468
        $agenciaCpl = $this->getTagValue($this->enderAgencia, "xCpl", "");
469
        $agenciaBairro = $this->getTagValue($this->enderAgencia, "xBairro");
470
        $agenciaCEP = $this->formatField($this->getTagValue($this->enderAgencia, "CEP"), "#####-###");
471
        $agenciaMun = $this->getTagValue($this->enderAgencia, "xMun");
472
        $agenciaUF = $this->getTagValue($this->enderAgencia, "UF");
473
        // CONFIGURAÇÃO DE POSIÇÃO
474
        $margemInterna = $this->margemInterna;
475
        $maxW = $this->wPrint;
476
        $h = $h - ($margemInterna);
0 ignored issues
show
Unused Code introduced by
$h 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...
477
        //COLOCA LOGOMARCA
478
        $xRs = $margemInterna;
479
        $wRs = ($maxW * 1);
480
        $alignEmit = 'C';
481
        $texto = "CNPJ: " . $agenciaCnpj . " " . "$agenciaRazao";
482
        $hRazao = ceil((strlen($texto) / 41)) * $this->hLinha;
483
        $hTotal += $hRazao;
484
        $endereco = "\n"
485
            . $agenciaLgr
486
            . ", "
487
            . $agenciaNro
488
            . " "
489
            . $agenciaCpl
490
            . ", "
491
            . $agenciaBairro
492
            . ". CEP:"
493
            . $agenciaCEP
494
            . ". "
495
            . $agenciaMun
496
            . "-"
497
            . $agenciaUF;
498
        $hEndereco = $this->hLinha * ceil(strlen($endereco) / 41);
499
        $hTotal += $hEndereco;
500
        //COLOCA RAZÃO SOCIAL
501
        $texto = $texto . $endereco;
502
        $texto .= "\n____________________________________________________";
503
        $hTotal += $this->hLinha;
504
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
505
        $this->pdf->textBox($xRs, $y, $wRs, $hTotal, $texto, $aFont, 'T', $alignEmit, false, '', false);
506
        return $hTotal;
507
    }
508
    
509
    /**
510
     * Monta o cabeçalho do BPe
511
     * @param float $x
512
     * @param float $y
513
     * @param float $h
514
     * @return float
515
     */
516
    protected function cabecalhoDABPE($x = 0.0, $y = 0.0, $h = 0.0)
0 ignored issues
show
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...
517
    {
518
        $hTotal = 0;
519
        $emitRazao = $this->getTagValue($this->emit, "xNome");
520
        $emitCnpj = $this->getTagValue($this->emit, "CNPJ");
521
        $emitCnpj = $this->formatField($emitCnpj, "##.###.###/####-##");
522
        $emitIE = $this->getTagValue($this->emit, "IE");
523
        $emitIM = $this->getTagValue($this->emit, "IM");
0 ignored issues
show
Unused Code introduced by
$emitIM 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...
524
        $emitFone = $this->getTagValue($this->enderEmit, "fone");
525
        $foneLen = strlen($emitFone);
526
        if ($foneLen > 0) {
527
            $ddd = substr($emitFone, 0, 2);
528
            $fone1 = substr($emitFone, -8);
529
            $digito9 = ' ';
530
            if ($foneLen == 11) {
531
                $digito9 = substr($emitFone, 2, 1);
532
            }
533
            $emitFone = ' - (' . $ddd . ') ' . $digito9 . ' ' . substr($fone1, 0, 4) . '-' . substr($fone1, -4);
534
        } else {
535
            $emitFone = '';
536
        }
537
        $emitLgr = $this->getTagValue($this->enderEmit, "xLgr");
538
        $emitNro = $this->getTagValue($this->enderEmit, "nro");
539
        $emitCpl = $this->getTagValue($this->enderEmit, "xCpl", "");
540
        $emitBairro = $this->getTagValue($this->enderEmit, "xBairro");
541
        $emitCEP = $this->formatField($this->getTagValue($this->enderEmit, "CEP"), "#####-###");
542
        $emitMun = $this->getTagValue($this->enderEmit, "xMun");
543
        $emitUF = $this->getTagValue($this->enderEmit, "UF");
544
        // CONFIGURAÇÃO DE POSIÇÃO
545
        $margemInterna = $this->margemInterna;
546
        $maxW = $this->wPrint;
547
        //COLOCA LOGOMARCA
548
        if (!empty($this->logomarca)) {
549
            $xImg = $margemInterna;
550
            $logoInfo = getimagesize($this->logomarca);
551
            $logoWmm = ($logoInfo[0]/72)*25.4;
552
            $logoHmm = ($logoInfo[1]/72)*25.4;
553
            $nImgW = $this->paperwidth/2 - ($this->paperwidth/10 + 4);
554
            $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
555
            if ($nImgH > 18) {
556
                $nImgH = 18;
557
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
558
            }
559
            $yImg = 15;
560
            $this->pdf->image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, 'jpeg');
561
            $xRs = ($maxW * 0.4) + $margemInterna;
562
            $wRs = ($maxW * 0.6);
563
            $alignEmit = 'L';
564
            $limiteChar = 22;
565
        } else {
566
            $xRs = $margemInterna;
567
            $wRs = ($maxW * 1);
568
            $alignEmit = 'C';
569
            $limiteChar = 40;
570
        }
571
        //COLOCA RAZÃO SOCIAL
572
        $hRazao = ceil(strlen($emitRazao) / $limiteChar) * $this->hLinha;
573
574
        $hTotal += $hRazao;
575
        $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B'];
576
        $this->pdf->textBox($xRs, $y, $wRs, $hRazao, $emitRazao, $aFont, 'T', $alignEmit, false, '', false);
577
578
        $y += $hRazao;
579
580
        $linhaCNPJ = "CNPJ: " . $emitCnpj;
581
        $linhaCNPJ = $linhaCNPJ . " IE: " . $emitIE;
582
583
        $endereco = $emitLgr
584
            . ", "
585
            . $emitNro
586
            . " "
587
            . $emitCpl
588
            . ", "
589
            . $emitBairro
590
            . ". CEP: "
591
            . $emitCEP
592
            . " . "
593
            . $emitMun
594
            . " - " . $emitUF
595
            . $emitFone;
596
597
        $hEndereco = $this->hLinha * ceil(strlen($endereco) / 41);
598
599
        $linhaDabpe = "Documento Auxiliar do Bilhete de Passagem Eletrônico";
600
        $texto = $linhaCNPJ . "\n" . $endereco . "\n";
601
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
602
        $h = $this->hLinha + $hEndereco;
603
        if (empty($this->dhCont)) {
604
            if (empty($this->logomarca)) {
605
                $texto = $texto . $linhaDabpe . "\n____________________________________________________";
606
                $h = $h + $this->hLinha;
607
                $this->pdf->textBox($xRs, $y, $wRs, $h, $texto, $aFont, 'T', $alignEmit, false, '', false);
608
            } else {
609
                if (empty($this->agencia)) {
610
                    $y += $this->hLinha;
611
                    $hTotal += $this->hLinha;
612
                }
613
                $this->pdf->textBox($xRs, $y, $wRs, $h, $texto, $aFont, 'T', $alignEmit, false, '', false);
614
                $h = $h + $this->hLinha * 2;
615
                $y += $h;
616
                $texto = $linhaDabpe . "\n____________________________________________________";
617
                $this->pdf->textBox($x, $y, $maxW, $this->hLinha, $texto, $aFont, 'T', 'C', false, '', false);
618
                $hTotal += $this->hLinha * 2;
619
            }
620
        } else {
621
            $texto = $texto . "\n____________________________________________________";
622
            $this->pdf->textBox($xRs, $y, $wRs, $this->hLinha, $texto, $aFont, 'T', $alignEmit, false, '', false);
623
            $texto = "\nEMITIDA EM CONTINGÊNCIA\nPendente de autorização";
624
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
625
            $this->pdf->textBox(
626
                $xRs,
627
                $h - $this->hLinha,
628
                $wRs,
629
                $this->hLinha * 2,
630
                $texto,
631
                $aFont,
632
                'T',
633
                $alignEmit,
634
                false,
635
                '',
636
                false
637
            );
638
        }
639
        $hTotal += $h;
640
        return $hTotal;
641
    }
642
643
    /**
644
     * Cabeçalho secundário com os dados da viagem
645
     * @param float $x
646
     * @param float $y
647
     * @param float $h
648
     * @return float
649
     */
650
    protected function cabecalhoSecundarioDABPE($x = 0.0, $y = 0.0, $h = 0.0): float
0 ignored issues
show
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...
651
    {
652
        $hTotal = 0;
653
        $margemInterna = $this->margemInterna;
654
        $hTotal += $margemInterna;
655
        $y += $margemInterna;
656
        $maxW = $this->wPrint;
657
        $w = ($maxW * 1);
658
        $hBox1 = 12;
659
        $hBox2 = 11;
660
        $origem = $this->getTagValue($this->infPassagem, "xLocOrig");
661
        $uforigem = $this->getTagValue($this->ide, "UFIni");
662
        $texto = "\nOrigem: " . $origem . "(" . $uforigem . ")";
663
        $destino = $this->getTagValue($this->infPassagem, "xLocDest");
664
        $ufdestino = $this->getTagValue($this->ide, "UFFim");
665
        $texto = $texto . "\nDestino: " . $destino . "(" . $ufdestino . ")";
666
        $dhViagem = $this->getTagValue($this->infViagem, "dhViagem");
667
        $dhViagemformatado = new \DateTime($dhViagem);
668
        $data = $dhViagemformatado->format('d/m/Y');
669
        $hora = $dhViagemformatado->format('H:i:s');
670
        $texto = "\n" . $texto . "\nData: " . $data . " | Horário: " . $hora;
671
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
672
        $this->pdf->textBox($x, $y, $w, $hBox1, $texto, $aFont, 'T', 'C', false, '', false);
673
        $hTotal += $hBox1;
674
        if (!empty($this->getTagValue($this->infViagem, "prefixo"))) {
675
            $prefixo = $this->getTagValue($this->infViagem, "prefixo");
676
        } else {
677
            $prefixo = "";
678
        }
679
        $linha = $this->getTagValue($this->infViagem, "xPercurso");
680
        $tpServ = $this->getTagValue($this->infViagem, "tpServ");
681
        $tipo = "Não Definido";
682
        switch ($tpServ) {
683
            case "1":
684
                $tipo = "Convencional com sanitário";
685
                break;
686
            case "2":
687
                $tipo = "Convencional sem sanitário";
688
                break;
689
            case "3":
690
                $tipo = "Semileito";
691
                break;
692
            case "4":
693
                $tipo = "Leito com ar condicionado";
694
                break;
695
            case "5":
696
                $tipo = "Leito sem ar condicionado";
697
                break;
698
            case "6":
699
                $tipo = "Executivo";
700
                break;
701
            case "7":
702
                $tipo = "Semiurbano";
703
                break;
704
            case "8":
705
                $tipo = "Longitudinal";
706
                break;
707
            case "9":
708
                $tipo = "Travessia";
709
                break;
710
        }
711
712
        $texto = "\n(Poltrona: "
713
            . $this->getTagValue($this->infViagem, "poltrona")
714
            . " Plataforma: "
715
            . $this->getTagValue($this->infViagem, "plataforma")
716
            . ")";
717
        $texto = $texto
718
            . "\nPrefixo: "
719
            . $prefixo
720
            . "  Linha: "
721
            . $linha
722
            . "\nTipo: "
723
            . $tipo
724
            . "\n_____________________________________________________________";
725
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
726
        $y += $hBox1;
727
        $this->pdf->textBox($x, $y, $w, $hBox2, $texto, $aFont, 'T', 'C', false, '', false);
728
        $hTotal += $hBox2;
729
        return $hTotal;
730
    }
731
732
    protected function produtosDABPE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
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...
733
    {
734
        $hTotal = 0;
735
        $qtdItens = $this->Comp->length;
736
        $w = $this->wPrint;
737
        $cont = 0;
738
        $aFontComp = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
739
        if ($qtdItens > 0) {
740
            foreach ($this->Comp as $compI) {
741
                $item = $compI;
742
                $tpComp = $this->getTagValue($item, "tpComp");
743
                switch ($tpComp) {
744
                    case "01":
745
                        $xtpComp = "Tarifa";
746
                        break;
747
                    case "02":
748
                        $xtpComp = "Pedagio";
749
                        break;
750
                    case "03":
751
                        $xtpComp = "Taxa Embarque";
752
                        break;
753
                    case "04":
754
                        $xtpComp = "Seguro";
755
                        break;
756
                    case "05":
757
                        $xtpComp = "TMR";
758
                        break;
759
                    case "06":
760
                        $xtpComp = "SVI";
761
                        break;
762
                    case "99":
763
                        $xtpComp = "Outros";
764
                        break;
765
766
                    default:
767
                        $xtpComp = "Outro";
768
                        break;
769
                }
770
                //COLOCA DESCRIÇÃO DO COMPONENTE(tpComp)
771
                $wBoxCompEsq = $w * 0.7;
772
                $wBoxCompDir = $w * 0.3;
773
                $texto = $xtpComp;
774
                $yBoxComp = $y + ($cont * $this->hLinha);
775
                $this->pdf->textBox(
776
                    $x,
777
                    $yBoxComp,
778
                    $wBoxCompEsq,
779
                    $this->hLinha,
780
                    $texto,
781
                    $aFontComp,
782
                    'T',
783
                    'L',
784
                    false,
785
                    '',
786
                    false
787
                );
788
                $vComp = number_format((float) $this->getTagValue($item, "vComp"), 2, ",", ".");
789
                //COLOCA VALOR DO COMPONENTE
790
791
                $xBoxValor = $x + $wBoxCompEsq;
792
                $texto = $vComp;
793
                $this->pdf->textBox(
794
                    $xBoxValor,
795
                    $yBoxComp,
796
                    $wBoxCompDir,
797
                    $this->hLinha,
798
                    $texto,
799
                    $aFontComp,
800
                    'T',
801
                    'R',
802
                    false,
803
                    '',
804
                    false
805
                );
806
                $hTotal += $this->hLinha;
807
                $cont++;
808
            }
809
        }
810
        return $hTotal;
811
    }
812
813
    protected function totalDABPE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
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...
814
    {
815
        $hTotal = 0;
816
        $maxW = $this->wPrint;
817
        $hLinha = $this->hLinha;
818
        $wColEsq = ($maxW * 0.7);
819
        $wColDir = ($maxW * 0.3);
820
        $xValor = $x + $wColEsq;
821
        $qtdItens = $this->Comp->length;
0 ignored issues
show
Unused Code introduced by
$qtdItens 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...
822
823
        $vBP = number_format((float) $this->getTagValue($this->infValorBPe, "vBP"), 2, ",", ".");
824
        $vDesconto = number_format((float) $this->getTagValue($this->infValorBPe, "vDesconto"), 2, ",", ".");
825
        $vTroco = number_format((float) $this->getTagValue($this->infValorBPe, "vTroco"), 2, ",", ".");
0 ignored issues
show
Unused Code introduced by
$vTroco 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...
826
        $vPgto = number_format((float) $this->getTagValue($this->infValorBPe, "vPgto"), 2, ",", ".");
827
828
829
        $texto = "Valor total R$";
830
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
831
        $this->pdf->textBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', false, '', false);
832
        $texto = $vBP;
833
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
834
        $this->pdf->textBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', false, '', false);
835
        $hTotal += $this->hLinha;
836
        $y += $this->hLinha;
837
838
        $texto = "Desconto R$";
839
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
840
        $this->pdf->textBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', false, '', false);
841
        $texto = $vDesconto;
842
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
843
        $this->pdf->textBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', false, '', false);
844
        $y += $this->hLinha;
845
        $hTotal += $this->hLinha;
846
847
        $texto = "Valor a Pagar R$";
848
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B'];
849
        $this->pdf->textBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', false, '', false);
850
        $texto = $vPgto;
851
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B'];
852
        $this->pdf->textBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', false, '', false);
853
        $hTotal += $this->hLinha;
854
        return $hTotal;
855
    }
856
857
    protected function fiscalDABPE($x = 0, $y = 0, $h = 0)
858
    {
859
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
860
        $maxW = $this->wPrint;
861
        $w = ($maxW * 1);
862
        $hLinha = $this->hLinha;
863
        $aFontTit = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B'];
864
        $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
865
        $chBPe = str_replace('BPe', '', $this->infBPe->getAttribute("Id"));
866
        $chBPe = $this->formatField($chBPe, "#### #### #### #### #### #### #### #### #### #### ####");
867
868
        if ($this->checkCancelada()) {
869
            //101 Cancelamento
870
            $this->pdf->setTextColor(255, 0, 0);
871
            $texto = "BPe CANCELADO";
872
            $this->pdf->textBox(
873
                $x,
874
                $y,
875
                $w,
876
                $h,
877
                $texto,
878
                ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B'],
879
                'T',
880
                'C',
881
                false,
882
                ''
883
            );
884
            $this->pdf->setTextColor(0, 0, 0);
885
        }
886
887
888
        if ($this->checkSubstituto()) {
889
            //uso denegado
890
            $this->pdf->setTextColor(255, 0, 0);
891
            $texto = "BPe Substituto";
892
            $this->pdf->textBox($x, $y - 25, $w, $h, $texto, $aFontTit, 'T', 'C', false, '');
893
            $this->pdf->SetTextColor(0, 0, 0);
894
        }
895
896
        $cUF = $this->getTagValue($this->ide, 'cUF');
0 ignored issues
show
Unused Code introduced by
$cUF 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...
897
        $nBP = $this->getTagValue($this->ide, 'nBP');
898
        $serieBPe = str_pad($this->getTagValue($this->ide, "serie"), 3, "0", STR_PAD_LEFT);
899
        $dhEmi = $this->getTagValue($this->ide, "dhEmi");
900
        $dhEmilocal = new \DateTime($dhEmi);
901
        $dhEmiLocalFormat = $dhEmilocal->format('d/m/Y H:i:s');
902
        $texto = "Consulte pela chave de acesso em \n";
903
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
904
        $texto = $this->urlConsulta($this->getTagValue($this->ide, 'cUF'));
905
        $y += $this->hLinha;
906
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'T', 'C', false, '', false);
907
908
        $texto = $chBPe ?? 'Chave Não Localizada no XML';
909
        $y += $this->hLinha;
910
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
911
912
        $y += $this->hLinha;
913
        $hTex1 = $hLinha * 2;
0 ignored issues
show
Unused Code introduced by
$hTex1 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...
914
915
        if (isset($this->infPassageiro)) {
916
            $xNome = $this->getTagValue($this->infPassageiro, "xNome");
917
            $nDoc = $this->getTagValue($this->infPassageiro, "nDoc");
918
            $texto = "PASSAGEIRO: DOC: " . $nDoc . " - " . $xNome;
919
            $this->pdf->textBox($x, $y, $w, $hLinha * 2, $texto, $aFontTex, 'T', 'C', false, '', false);
920
            $y += $this->hLinha;
921
        }
922
923
        if (!empty($this->getTagValue($this->infValorBPe, "tpDesconto"))) {
924
            switch ($this->getTagValue($this->infValorBPe, "tpDesconto")) {
925
                case "01":
926
                    $xtpDesconto = "Tarifa promocional";
927
                    break;
928
                case "02":
929
                    $xtpDesconto = "Idoso";
930
                    break;
931
                case "03":
932
                    $xtpDesconto = "Criança";
933
                    break;
934
                case "04":
935
                    $xtpDesconto = "Deficiente";
936
                    break;
937
                case "05":
938
                    $xtpDesconto = "Estudante";
939
                    break;
940
                case "06":
941
                    $xtpDesconto = "Animal Doméstico";
942
                    break;
943
                case "07":
944
                    $xtpDesconto = "Acordo Coletivo";
945
                    break;
946
                case "08":
947
                    $xtpDesconto = "Profissional em Deslocamento";
948
                    break;
949
                case "09":
950
                    $xtpDesconto = "Profissional da Empresa";
951
                    break;
952
                case "10":
953
                    $xtpDesconto = "Jovem";
954
                    break;
955
                case "99":
956
                    $xtpDesconto = "Outros";
957
                    break;
958
                default:
959
                    $xtpDesconto = '';
960
            }
961
            $y += $this->hLinha * 3;
962
            $texto = "TIPO DE DESCONTO: " . $xtpDesconto;
963
            $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
964
        }
965
966
        $texto = "BP-e nº " . $nBP . " Série " . $serieBPe . " " . $dhEmiLocalFormat;
967
        $y += $this->hLinha;
968
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'T', 'C', false, '', false);
969
        $y += $this->hLinha * 2;
970
        if (empty($this->dhCont)) {
971
            $nProt = $this->getTagValue($this->protBPe, "nProt");
972
            $dhRecbto = $this->getTagValue($this->protBPe, "dhRecbto");
973
            $dhRecbto = new \DateTime($dhRecbto);
974
            $texto = "Protocolo de autorização: " . $nProt;
975
            $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
976
            $y += $this->hLinha * 2;
977
            $texto = "\nData de autorização: " . $dhRecbto->format('d/m/Y H:i:s');
978
            $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
979
        } else {
980
            $texto = "EMITIDA EM CONTINGÊNCIA";
981
            $aFontTex = ['font' => $this->fontePadrao, 'size' => 12, 'style' => 'B'];
982
            $this->pdf->textBox($x, $y + $hLinha, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
983
            $yTex4 = $y + ($hLinha * 8);
984
            $texto = "\nPendente de autorização ";
985
            $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
986
            $this->pdf->textBox($x, $yTex4 + $hLinha, $w, $hLinha, $texto, $aFontTex, 'T', 'C', false, '', false);
987
        }
988
    }
989
990
    protected function checkCancelada()
991
    {
992
        if (!isset($this->infProt)) {
993
            return false;
994
        }
995
        $cStat = $this->getTagValue($this->infProt, "cStat");
996
        return $cStat == '101';
997
    }
998
999
    protected function checkNaoAutorizada()
1000
    {
1001
        if (!isset($this->infProt)) {
1002
            $cStat = $this->getTagValue($this->infProt, "cStat");
0 ignored issues
show
Documentation introduced by
$this->infProt is of type null, but the function expects a object.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1003
            return $cStat == '';
1004
        }
1005
    }
1006
1007
    protected function checkSubstituto()
1008
    {
1009
        if (!isset($this->infProt)) {
1010
            return false;
1011
        }
1012
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1013
        //1 VEZ NO ARQUIVO INTEIRO
1014
        $cStat = $this->getTagValue($this->infProt, "cStat");
1015
        return $cStat == '102';
1016
    }
1017
1018
    protected function qrCodeDABPE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
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...
1019
    {
1020
        $y += 30;
1021
        $margemInterna = $this->margemInterna;
1022
        $maxW = $this->wPrint;
1023
        $w = ($maxW * 1) + 4;
1024
        $hLinha = $this->hLinha;
0 ignored issues
show
Unused Code introduced by
$hLinha 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...
1025
        $hBoxLinha = $this->hBoxLinha;
1026
        $aFontTit = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
0 ignored issues
show
Unused Code introduced by
$aFontTit 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...
1027
        $aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1028
        $dhRecbto = '';
1029
        $nProt = '';
0 ignored issues
show
Unused Code introduced by
$nProt 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...
1030
        if (isset($this->infBPeSupl)) {
1031
            $nProt = $this->getTagValue($this->infProt, "nProt");
0 ignored issues
show
Unused Code introduced by
$nProt 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...
1032
            $dhRecbto = $this->getTagValue($this->infProt, "dhRecbto");
1033
        }
1034
1035
        $barcode = new Barcode();
1036
        $bobj = $barcode->getBarcodeObj(
1037
            'QRCODE,M',
1038
            $this->qrCodBPe,
1039
            -4,
1040
            -4,
1041
            'black',
1042
            array(-2, -2, -2, -2)
1043
        )->setBackgroundColor('white');
1044
        $qrcode = $bobj->getPngData();
1045
        $wQr = 50;
1046
        $hQr = 50;
1047
        $yQr = ($y + $margemInterna);
1048
        $xQr = ($w / 2) - ($wQr / 2);
1049
        // prepare a base64 encoded "data url"
1050
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
1051
        $info = getimagesize($pic);
0 ignored issues
show
Unused Code introduced by
$info 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...
1052
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
1053
        $dt = new DateTime($dhRecbto);
0 ignored issues
show
Unused Code introduced by
$dt 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...
1054
        $yQr = ($yQr + $hQr + $margemInterna);
1055
1056
        if (isset($this->ICMSSN)) {
1057
            $vTotTrib = $this->getTagValue($this->ICMSSN, "vTotTrib");
1058
            $this->pdf->textBox(
1059
                $x,
1060
                $yQr,
1061
                $w - 4,
1062
                $hBoxLinha,
1063
                "Tributos Totais Incidentes(Lei Federal 12.741/2012): R$"
1064
                . $vTotTrib,
1065
                $aFontTex,
1066
                'T',
1067
                'C',
1068
                false,
1069
                '',
1070
                false
1071
            );
1072
        }
1073
    }
1074
1075
    protected function infAdic($x = 0, $y = 0, $h = 0)
0 ignored issues
show
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...
1076
    {
1077
        $y += 17;
1078
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
1079
        $maxW = $this->wPrint;
1080
        $w = ($maxW * 1);
1081
        $hLinha = $this->hLinha;
1082
        $aFontTit = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B'];
1083
        $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
1084
        // seta o textbox do titulo
1085
        $texto = "INFORMAÇÃO ADICIONAL";
1086
        $heigthText = $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', false, '', false);
0 ignored issues
show
Unused Code introduced by
$heigthText 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...
1087
1088
        // seta o textbox do texto adicional
1089
        $this->pdf->textBox($x, $y + 3, $w - 2, $hLinha - 3, $this->textoAdic, $aFontTex, 'T', 'L', false, '', false);
1090
    }
1091
1092
    protected function pagamentosDABPE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
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...
1093
    {
1094
        $hTotal = 0;
1095
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
1096
        $maxW = $this->wPrint;
1097
        $qtdPgto = $this->pag->length;
1098
        $w = ($maxW * 1);
1099
        $hLinha = $this->hLinha;
1100
        $wColEsq = ($maxW * 0.7);
1101
        $wColDir = ($maxW * 0.3);
0 ignored issues
show
Unused Code introduced by
$wColDir 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...
1102
        $xValor = $x + $wColEsq;
0 ignored issues
show
Unused Code introduced by
$xValor 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...
1103
1104
        $aFontPgto = array('font' => $this->fontePadrao, 'size' => 7, 'style' => '');
1105
        $wBoxEsq = $w * 0.7;
1106
        $texto = "FORMA PAGAMENTO";
1107
        $this->pdf->textBox($x, $y, $wBoxEsq, $this->hLinha, $texto, $aFontPgto, 'T', 'L', false, '', false);
1108
        $wBoxDir = $w * 0.3;
1109
        $xBoxDescricao = $x + $wBoxEsq;
1110
        $texto = "VALOR PAGO";
1111
        $this->pdf->textBox($xBoxDescricao, $y, $wBoxDir, $hLinha, $texto, $aFontPgto, 'T', 'R', false, '', false);
1112
        $y += $this->hLinha;
1113
        $hTotal += $this->hLinha;
1114
1115
        $cont = 0;
1116
        if ($qtdPgto > 0) {
1117
            foreach ($this->pag as $pagI) {
1118
                $tPag = $this->getTagValue($pagI, "tPag");
1119
                switch ($tPag) {
1120
                    case "01":
1121
                        $tPagNome = "Dinheiro R$";
1122
                        break;
1123
                    case "02":
1124
                        $tPagNome = "Cheque R$";
1125
                        break;
1126
                    case "03":
1127
                        $tPagNome = "Cartão de Crédito R$";
1128
                        break;
1129
                    case "04":
1130
                        $tPagNome = "Cartão de Débito R$";
1131
                        break;
1132
                    case "05":
1133
                        $tPagNome = "Vale Transporte R$";
1134
                        break;
1135
                    case "99":
1136
                        $tPagNome = "Outros";
1137
                        break;
1138
                    default:
1139
                        $tPagNome = '';
1140
                }
1141
                $vPag = number_format((float) $this->getTagValue($pagI, "vPag"), 2, ",", ".");
1142
                $texto = $tPagNome;
1143
                $this->pdf->textBox($x, $y, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', false, '', false);
1144
                //COLOCA PRODUTO DESCRIÇÃO
1145
                $xBoxDescricao = $wBoxEsq + $x;
1146
                $texto = $vPag;
1147
                $this->pdf->textBox(
1148
                    $xBoxDescricao,
1149
                    $y,
1150
                    $wBoxDir,
1151
                    $this->hLinha,
1152
                    $texto,
1153
                    $aFontPgto,
1154
                    'T',
1155
                    'R',
1156
                    false,
1157
                    '',
1158
                    false
1159
                );
1160
1161
                $y += $this->hLinha;
1162
                $hTotal += $this->hLinha;
1163
                $cont++;
1164
            }
1165
        }
1166
        $texto = "Troco";
1167
        $this->pdf->textBox($x, $y, $wBoxEsq, $this->hLinha, $texto, $aFontPgto, 'T', 'L', false, '', false);
1168
1169
        $vTroco = number_format((float) $this->getTagValue($this->infValorBPe, "vTroco"), 2, ",", ".");
1170
        $texto = $vTroco;
1171
        $this->pdf->textBox(
1172
            $xBoxDescricao,
1173
            $y,
1174
            $wBoxDir,
1175
            $this->hLinha,
1176
            $texto,
1177
            $aFontPgto,
1178
            'T',
1179
            'R',
1180
            false,
1181
            '',
1182
            false
1183
        );
1184
        $hTotal += $this->hLinha * 2;
1185
        return $hTotal;
1186
    }
1187
}
1188