Passed
Push — master ( 37bece...8e0b9d )
by Roberto
01:11 queued 10s
created

Dabpe::produtosDABPE()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 80

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
nc 10
nop 3
dl 0
loc 80
ccs 0
cts 76
cp 0
crap 110
rs 6.5696
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\BPe;
4
/**
5
 * Classe para a impressão em PDF do Documento Auxiliar de NFe Consumidor
6
 * NOTA: Esta classe não é a indicada para quem faz uso de impressoras térmicas ESCPOS
7
 *
8
 * @category  Library
9
 * @package   nfephp-org/sped-da
10
 * @copyright 2009-2019 NFePHP
11
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
12
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
13
 * @author    Roberto Spadim <roberto at spadim dot com dot br>
14
 */
15
16
17
use Exception;
18
use InvalidArgumentException;
19
use NFePHP\DA\Legacy\Dom;
20
use NFePHP\DA\Legacy\Pdf;
21
use NFePHP\DA\Legacy\Common;
22
use Com\Tecnick\Barcode\Barcode;
23
use DateTime;
24
25
26
class Dabpe extends Common
27
{
28
    protected $papel;
29
    protected $paperwidth = 80;
30
    protected $creditos;
31
    protected $xml; // string XML BPe
32
    protected $logomarca = ''; // path para logomarca em jpg
33
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
34
    protected $debugMode = 0; //ativa ou desativa o modo de debug
35
    protected $tpImp; //ambiente
36
    protected $fontePadrao = 'Times';
37
    protected $nfeProc;
38
    protected $infBPeSupl;
39
    protected $nfe;
40
    protected $infBPe;
41
    protected $ide;
42
    protected $enderDest;
43
    protected $ICMSTot;
44
    protected $imposto;
45
    protected $agencia;
46
    protected $enderAgencia;
47
    protected $emit;
48
    protected $enderEmit;
49
    protected $qrCode;
50
    protected $urlChave;
51
    protected $det;
52
    protected $infAdic;
53
    protected $textoAdic;
54
    protected $tpEmis;
55
    protected $Comp;
56
    protected $pag;
57
    protected $vTroco;
58
    protected $dest;
59
    protected $imgQRCode;
60
    protected $urlQR = '';
61
    protected $pdf;
62
    protected $margemInterna = 2;
63
    protected $hMaxLinha = 9;
64
    protected $hBoxLinha = 6;
65
    protected $hLinha = 3;
66
    protected $protBPe;
67
    protected $ICMSSN;
68
    protected $dhCont;
69
70
    /**
71
     * __contruct
72
     *
73
     * @param string $docXML
74
     * @param string $sPathLogo
75
     * @param string $mododebug
76
     * @param string $idToken
77
     * @param string $Token
0 ignored issues
show
Bug introduced by
There is no parameter named $Token. 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...
78
     */
79
    public function __construct(
80
        $docXML,
81
        $sPathLogo = '',
82
        $mododebug = 0,
83
        // habilita os erros do sistema
84
        $idToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $idToken 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...
85
        $emitToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $emitToken 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...
86
        $urlQR = ''
0 ignored issues
show
Unused Code introduced by
The parameter $urlQR 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...
87
    )
88
    {
89
        if (is_numeric($mododebug)) {
90
            $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...
91
        }
92
        if ($this->debugMode) {
93
            //ativar modo debug
94
            error_reporting(E_ALL);
95
            ini_set('display_errors', 'On');
96
        } else {
97
            //desativar modo debug
98
            error_reporting(0);
99
            ini_set('display_errors', 'Off');
100
        }
101
        $this->xml = $docXML;
102
        $this->logomarca = $sPathLogo;
103
104
        $this->fontePadrao = empty($fonteDABPE) ? 'Times' : $fonteDABPE;
0 ignored issues
show
Bug introduced by
The variable $fonteDABPE seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
105
        $this->aFontTit = array('font' => $this->fontePadrao, 'size' => 9, 'style' => 'B');
0 ignored issues
show
Bug introduced by
The property aFontTit 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...
106
        $this->aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
0 ignored issues
show
Bug introduced by
The property aFontTex 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...
107
        if (!empty($this->xml)) {
108
            $this->dom = new Dom();
0 ignored issues
show
Bug introduced by
The property dom 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...
109
            $this->dom->loadXML($this->xml);
110
            $this->infBPe = $this->dom->getElementsByTagName("infBPe")->item(0);
111
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
112
            $this->agencia = $this->dom->getElementsByTagName("agencia")->item(0);
113
            $this->enderAgencia = $this->dom->getElementsByTagName("enderAgencia")->item(0);
114
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
115
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
116
            $this->infViagem = $this->dom->getElementsByTagName("infViagem")->item(0);
0 ignored issues
show
Bug introduced by
The property infViagem 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...
117
            $this->infPassagem = $this->dom->getElementsByTagName("infPassagem")->item(0);
0 ignored issues
show
Bug introduced by
The property infPassagem 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...
118
            $this->infPassageiro = $this->dom->getElementsByTagName("infPassageiro")->item(0);
0 ignored issues
show
Bug introduced by
The property infPassageiro 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...
119
            $this->infValorBPe = $this->dom->getElementsByTagName("infValorBPe")->item(0);
0 ignored issues
show
Bug introduced by
The property infValorBPe 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...
120
            $this->Comp = $this->dom->getElementsByTagName("Comp");
121
            $this->pag = $this->dom->getElementsByTagName("pag");
122
            $this->infProt = $this->dom->getElementsByTagName("infProt")->item(0);
0 ignored issues
show
Bug introduced by
The property infProt 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...
123
            $this->tpEmis = $this->dom->getElementsByTagName('tpEmis')->item(0)->nodeValue;
124
            $this->nBP = $this->dom->getElementsByTagName("nBP")->item(0);
0 ignored issues
show
Bug introduced by
The property nBP 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...
125
            $this->protBPe = $this->dom->getElementsByTagName("protBPe")->item(0);
126
            $this->ICMSSN = $this->dom->getElementsByTagName("ICMSSN")->item(0);
127
            $this->dhCont = $this->getTagValue($this->ide, "dhCont") ?? '';
128
        }
129
        $this->qrCodBPe = !empty($this->dom->getElementsByTagName('qrCodBPe')->item(0)->nodeValue)
0 ignored issues
show
Bug introduced by
The property qrCodBPe 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...
130
            ? $this->dom->getElementsByTagName('qrCodBPe')->item(0)->nodeValue : null;
131
132
        $this->urlChave = $this->urlConsulta($this->cUF);
0 ignored issues
show
Bug introduced by
The property cUF 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...
133
        if ($this->getTagValue($this->ide, "mod") != '63') {
134
            throw new InvalidArgumentException("O xml do DOCUMENTO deve ser uma BP-e modelo 63");
135
        }
136
    }
137
138
    protected function urlConsulta($uf)
139
    {
140
        switch ($uf) {
141
            case "11": // Rondônia
142
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
143
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
144
            case "12": //Acre
145
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
146
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
147
            case "13": //Amazonas
148
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
149
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
150
            case "14": //Roraima
151
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
152
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
153
            case "15": //Pará
154
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
155
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
156
            case "16": //Amapá
157
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
158
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
159
            case "17": //Tocantins
160
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
161
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
162
            case "21": //Maranhão
163
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
164
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
165
            case "22": //Piauí
166
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
167
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
168
            case "23": //Ceará
169
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
170
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
171
            case "24": //Rio Grande do Norte
172
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
173
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
174
            case "25": //Paraíba
175
                return "https://www.sefaz.pb.gov.br/bpe/consulta";
176
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
177
            case "26": //Pernambuco
178
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
179
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
180
            case "27": //Alagoas
181
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
182
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
183
            case "28": //Sergipe
184
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
185
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
186
            case "29": //Bahia
187
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
188
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
189
            case "31": //Minas Gerais
190
                return "https://bpe.fazenda.mg.gov.br/portalbpe/sistema/consultaarg.xhtml";
191
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
192
            case "32": //Espírito Santo
193
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
194
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
195
            case "33": //Rio de Janeiro
196
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
197
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
198
            case "35": //São Paulo
199
                return "https://bpe.fazenda.sp.gov.br/BPe/";
200
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
201
            case "41": //Paraná
202
                return "http://www.sped.fazenda.pr.gov.br/modules/conteudo/bpe.php?consulta=completa";
203
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
204
            case "42": //Santa Catarina(Não usa BPE)
205
                return "";
206
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
207
            case "43": //Rio Grande do Sul (*)
208
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
209
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
210
            case "50": //Mato Grosso do Sul
211
                return "http://www.dfe.ms.gov.br/bpe/#/consulta";
212
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
213
            case "51": //Mato Grosso
214
                return "https://www.sefaz.mt.gov.br/BPe/consulta";
215
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
216
            case "52": //Goiás
217
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
218
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
219
            case "53": //Distrito Federal
220
                return "https://dfe-portal.svrs.rs.gov.br/BPE/Consulta";
221
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
222
        }
223
    }
224
225
    protected static function getCardName($tBand)
226
    {
227
        switch ($tBand) {
228
            case '01':
229
                $tBandNome = 'VISA';
230
                break;
231
            case '02':
232
                $tBandNome = 'MASTERCARD';
233
                break;
234
            case '03':
235
                $tBandNome = 'AMERICAM EXPRESS';
236
                break;
237
            case '04':
238
                $tBandNome = 'SOROCRED';
239
                break;
240
            case '99':
241
                $tBandNome = 'OUTROS';
242
                break;
243
            default:
244
                $tBandNome = '';
245
        }
246
        return $tBandNome;
247
    }
248
249
    /**
250
     * Ativa ou desativa o modo debug
251
     * @param bool $activate
252
     * @return bool
253
     */
254
    public function debugMode($activate = null)
255
    {
256
        if (isset($activate) && is_bool($activate)) {
257
            $this->debugmode = $activate;
0 ignored issues
show
Bug introduced by
The property debugmode does not seem to exist. Did you mean debugMode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
258
        }
259
        if ($this->debugmode) {
0 ignored issues
show
Bug introduced by
The property debugmode does not seem to exist. Did you mean debugMode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
260
            //ativar modo debug
261
            error_reporting(E_ALL);
262
            ini_set('display_errors', 'On');
263
        } else {
264
            //desativar modo debug
265
            error_reporting(0);
266
            ini_set('display_errors', 'Off');
267
        }
268
        return $this->debugmode;
0 ignored issues
show
Bug introduced by
The property debugmode does not seem to exist. Did you mean debugMode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
269
    }
270
271
    /**
272
     * Add the credits to the integrator in the footer message
273
     * @param string $message
274
     */
275
    public function creditsIntegratorFooter($message = '')
276
    {
277
        $this->creditos = trim($message);
278
    }
279
280
    /**
281
     * Dados brutos do PDF
282
     * @return string
283
     */
284
    public function render()
285
    {
286
        if (empty($this->pdf)) {
287
            $this->monta();
288
        }
289
        return $this->pdf->getPdf();
290
291
    }
292
293
    public function monta(
294
        $logo = null,
295
        $depecNumReg = '',
296
        $logoAlign = 'C'
297
    )
298
    {
299
        $this->logomarca = $logo;
300
        $qtdItens = $this->Comp->length;
301
        $qtdPgto = $this->pag->length;
302
        $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...
303
        $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...
304
        $hLinha = $this->hLinha;
305
        $tamPapelVert = 140 + 16 + 12 + (($qtdItens - 1) * $hLinha) + ($qtdPgto * $hLinha);
306
        // verifica se existe informações adicionais
307
        $this->textoAdic = '';
308
        if (isset($this->infAdic)) {
309
            $this->textoAdic .= !empty($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue) ? 'Inf. Contribuinte: ' . trim($this->anfaveaDANFE($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue)) : '';
0 ignored issues
show
Bug introduced by
The method anfaveaDANFE() does not seem to exist on object<NFePHP\DA\BPe\Dabpe>.

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...
310
            if (!empty($this->textoAdic)) {
311
                $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
312
                $alinhas = explode("\n", $this->textoAdic);
313
                $numlinhasdados = 0;
314
                $tempPDF = new Pdf(); // cria uma instancia temporaria da class pdf
315
                $tempPDF->setFont('times', '', '8'); // seta a font do PDF
316
                foreach ($alinhas as $linha) {
317
                    $linha = trim($linha);
318
                    $numlinhasdados += $tempPDF->wordWrap($linha, 76 - 0.2);
0 ignored issues
show
Documentation introduced by
$linha is of type string, but the function expects a object<NFePHP\DA\Legacy\type>.

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...
Documentation introduced by
76 - 0.2 is of type double, but the function expects a object<NFePHP\DA\Legacy\type>.

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...
319
                }
320
                $hdadosadic = round(($numlinhasdados + 1) * $tempPDF->fontSize, 0);
321
                if ($hdadosadic < 5) {
322
                    $hdadosadic = 5;
323
                }
324
                // seta o tamanho do papel
325
                $tamPapelVert += $hdadosadic;
326
            }
327
        }
328
329
        if (!empty($this->agencia)) {
330
            $hagencia = 20;
331
            $tamPapelVert += 18;
332
        }
333
        $this->orientacao = 'P';
0 ignored issues
show
Bug introduced by
The property orientacao 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...
334
        $this->papel = [$this->paperwidth, $tamPapelVert];
335
        $this->logoAlign = $logoAlign;
0 ignored issues
show
Bug introduced by
The property logoAlign 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...
336
        //$this->situacao_externa = $situacaoExterna;
337
        $this->numero_registro_dpec = $depecNumReg;
0 ignored issues
show
Bug introduced by
The property numero_registro_dpec 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...
338
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer|do...,"1":"double|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...
339
340
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
341
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
342
        //apenas para controle se necessário ser maior do que a margem superior
343
        $margSup = 2;
344
        $margEsq = 2;
345
        $margInf = 2;
346
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
347
        $xInic = $margEsq;
348
        $yInic = $margSup;
349
        $maxW = 80;
350
        $maxH = $tamPapelVert;
351
        //total inicial de paginas
352
        $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...
353
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
354
        $this->wPrint = $maxW - ($margEsq * 2);
0 ignored issues
show
Bug introduced by
The property wPrint 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...
355
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
356
        //superior e inferior
357
        $this->hPrint = $maxH - $margSup - $margInf;
0 ignored issues
show
Bug introduced by
The property hPrint 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...
358
        // estabelece contagem de paginas
359
        $this->pdf->aliasNbPages();
360
        $this->pdf->setMargins($margEsq, $margSup); // fixa as margens
361
        $this->pdf->setDrawColor(0, 0, 0);
362
        $this->pdf->setFillColor(255, 255, 255);
363
        $this->pdf->open(); // inicia o documento
364
        $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|do...,"1":"double|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...
365
        $this->pdf->setLineWidth(0.1); // define a largura da linha
366
        $this->pdf->setTextColor(0, 0, 0);
367
        $this->pdf->textBox(0, 0, $maxW, $maxH); // POR QUE PRECISO DESA LINHA?
368
        $hcabecalho = 16;//para cabeçalho (dados emitente mais logomarca)  (FIXO)
369
        $hcabecalhoSecundario = 18;//para cabeçalho secundário (cabeçalho sefaz) (FIXO)
370
        $hprodutos = $hLinha + ($qtdItens * $hLinha);//box poduto
371
        $hTotal = 12; //box total (FIXO)
372
        $hpagamentos = (2 * $hLinha) + ($qtdPgto * $hLinha);//para pagamentos
373
        if (!empty($this->vTroco)) {
374
            $hpagamentos += $hLinha;
375
        }
376
377
        $hmsgfiscal = 28; // para imposto (FIXO)
378
        $hcliente = !isset($this->dest) ? 6 : 12; // para cliente (FIXO)
379
        $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...
380
        $hQRCode = 50; // para qrcode (FIXO)
381
        $hCabecItens = 4; //cabeçalho dos itens
382
383
        $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...
384
        $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...
385
        $totPag = 1;
386
        $pag = 1;
387
        $x = $xInic;
388
        //COLOCA CABEÇALHO
389
        $y = $yInic;
390
        if (!empty($this->agencia)) {
391
            $y = $this->cabecalhoAgencia($x, $y, $hagencia, $pag, $totPag);
0 ignored issues
show
Bug introduced by
The variable $hagencia 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...
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...
392
            $y = $hagencia;
393
            if (!empty($this->dhCont)) {
394
                $hcabecalho = $hcabecalho + ($this->hLinha * 2);
395
            }
396
            $y = $this->cabecalhoDABPE($x, $y, $hcabecalho);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->cabecalhoDABPE($x, $y, $hcabecalho) (which targets NFePHP\DA\BPe\Dabpe::cabecalhoDABPE()) 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...
397
            $hcabecalho = $hcabecalho + $hagencia;
398
        } else {
399
            if (!empty($this->dhCont)) {
400
                $hcabecalho = $hcabecalho + ($this->hLinha * 2);
401
            }
402
            $y = $this->cabecalhoDABPE($x, $y, $hcabecalho, $pag, $totPag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->cabecalhoDABPE($x...becalho, $pag, $totPag) (which targets NFePHP\DA\BPe\Dabpe::cabecalhoDABPE()) 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...
403
        }
404
        //COLOCA CABEÇALHO SECUNDÁRIO
405
        $y = $hcabecalho + 4;// Adiciona-se +4 na altura para servir como "margem" Após o término da Box Anterior
406
        $y = $this->cabecalhoSecundarioDABPE($x, $y, $hcabecalhoSecundario);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->cabecalhoSecundar... $hcabecalhoSecundario) (which targets NFePHP\DA\BPe\Dabpe::cabecalhoSecundarioDABPE()) 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...
407
        $jj = $hcabecalho + $hcabecalhoSecundario;
0 ignored issues
show
Unused Code introduced by
$jj 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
        //COLOCA PRODUTOS
409
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + 6; // +6 devido a um aumento na BOX2 do cabecalhosecundariodabpe
410
        $y = $this->produtosDABPE($x, $y, $hprodutos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->produtosDABPE($x, $y, $hprodutos) (which targets NFePHP\DA\BPe\Dabpe::produtosDABPE()) 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...
411
        //COLOCA TOTAL
412
        $y = $yInic + $hcabecalho + $hcabecalhoSecundario + 6 + $hprodutos;
413
        $y = $this->totalDABPE($x, $y, $hTotal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->totalDABPE($x, $y, $hTotal) (which targets NFePHP\DA\BPe\Dabpe::totalDABPE()) 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...
414
        //COLOCA PAGAMENTOS
415
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal;
416
        $y = $this->pagamentosDABPE($x, $y, $hpagamentos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pagamentosDABPE($x, $y, $hpagamentos) (which targets NFePHP\DA\BPe\Dabpe::pagamentosDABPE()) 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...
417
        //COLOCA MENSAGEM FISCAL
418
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos;
419
        $y = $this->fiscalDABPE($x, $y, $hmsgfiscal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->fiscalDABPE($x, $y, $hmsgfiscal) (which targets NFePHP\DA\BPe\Dabpe::fiscalDABPE()) 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...
420
        //COLOCA CONSUMIDOR
421
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal;
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...
422
        //COLOCA QRCODE
423
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal;
424
        $y = $this->qrCodeDABPE($x, $y, $hQRCode);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->qrCodeDABPE($x, $y, $hQRCode) (which targets NFePHP\DA\BPe\Dabpe::qrCodeDABPE()) 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...
425
426
        //adiciona as informações opcionais
427
        if (!empty($this->textoAdic)) {
428
            $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos
429
                + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente + $hQRCode;
430
            $hInfAdic = 0;
431
            $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...
432
        }
433
    }
434
435
    /**
436
     * anfavea
437
     * Função para transformar o campo cdata do padrão ANFAVEA para
438
     * texto imprimível
439
     *
440
     * @param string $cdata campo CDATA
441
     * @return string conteúdo do campo CDATA como string
0 ignored issues
show
Bug introduced by
There is no parameter named $cdata. 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...
442
     */
443
444
    protected function cabecalhoAgencia($x = 0, $y = 0, $h = 0, $pag = '1', $totPag = '1')
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...
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 $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...
445
    {
446
        $agenciaRazao = $this->getTagValue($this->agencia, "xNome");
447
        $agenciaCnpj = $this->getTagValue($this->agencia, "CNPJ");
448
        $agenciaCnpj = $this->formatField($agenciaCnpj, "##.###.###/####-##");
449
        $agenciaLgr = $this->getTagValue($this->enderAgencia, "xLgr");
450
        $agenciaNro = $this->getTagValue($this->enderAgencia, "nro");
451
        $agenciaCpl = $this->getTagValue($this->enderAgencia, "xCpl", "");
452
        $agenciaBairro = $this->getTagValue($this->enderAgencia, "xBairro");
453
        $agenciaCEP = $this->formatField($this->getTagValue($this->enderAgencia, "CEP"), "#####-###");
454
        $agenciaMun = $this->getTagValue($this->enderAgencia, "xMun");
455
        $agenciaUF = $this->getTagValue($this->enderAgencia, "UF");
456
        // CONFIGURAÇÃO DE POSIÇÃO
457
        $margemInterna = $this->margemInterna;
458
        $maxW = $this->wPrint;
459
        $h = $h - ($margemInterna);
460
        //COLOCA LOGOMARCA
461
        if (is_file($this->logomarca)) {
462
            $xImg = $margemInterna;
463
            $yImg = $margemInterna + 1;
464
            $this->pdf->image($this->logomarca, $xImg, $yImg, 30, 22.5);
465
            $xRs = ($maxW * 0.4) + $margemInterna;
466
            $wRs = ($maxW * 0.6);
467
            $alignEmit = 'R';
468
        } else {
469
            $xRs = $margemInterna;
470
            $wRs = ($maxW * 1);
471
            $alignEmit = 'C';
472
        }
473
        //COLOCA RAZÃO SOCIAL
474
        $texto = "CNPJ:" . $agenciaCnpj;
475
        $texto = $texto . "\n" . $agenciaRazao;
476
477
        $texto = $texto . "\n" . $agenciaLgr . "," . $agenciaNro . " " . $agenciaCpl . "," . $agenciaBairro
478
            . ". CEP:" . $agenciaCEP . ". " . $agenciaMun . "-" . $agenciaUF . "\n____________________________________________________";
479
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
480
        $this->pdf->textBox($xRs, $y, $wRs, $h, $texto, $aFont, 'T', $alignEmit, 0, '', false);
481
    }
482
483
    protected function cabecalhoDABPE($x = 0, $y = 0, $h = 0, $pag = '1', $totPag = '1')
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...
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 $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...
484
    {
485
        $emitRazao = $this->getTagValue($this->emit, "xNome");
486
        $emitCnpj = $this->getTagValue($this->emit, "CNPJ");
487
        $emitCnpj = $this->formatField($emitCnpj, "##.###.###/####-##");
488
        $emitIE = $this->getTagValue($this->emit, "IE");
489
        $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...
490
        $emitFone = $this->getTagValue($this->enderEmit, "fone");
491
        $foneLen = strlen($emitFone);
492
        if ($foneLen > 0) {
493
            $ddd = substr($emitFone, 0, 2);
494
            $fone1 = substr($emitFone, -8);
495
            $digito9 = ' ';
496
            if ($foneLen == 11) {
497
                $digito9 = substr($emitFone, 2, 1);
498
            }
499
            $emitFone = ' - (' . $ddd . ') ' . $digito9 . ' ' . substr($fone1, 0, 4) . '-' . substr($fone1, -4);
500
        } else {
501
            $emitFone = '';
502
        }
503
        $emitLgr = $this->getTagValue($this->enderEmit, "xLgr");
504
        $emitNro = $this->getTagValue($this->enderEmit, "nro");
505
        $emitCpl = $this->getTagValue($this->enderEmit, "xCpl", "");
506
        $emitBairro = $this->getTagValue($this->enderEmit, "xBairro");
507
        $emitCEP = $this->formatField($this->getTagValue($this->enderEmit, "CEP"), "#####-###");
508
        $emitMun = $this->getTagValue($this->enderEmit, "xMun");
509
        $emitUF = $this->getTagValue($this->enderEmit, "UF");
510
        // CONFIGURAÇÃO DE POSIÇÃO
511
        $margemInterna = $this->margemInterna;
512
        $maxW = $this->wPrint;
513
        //COLOCA LOGOMARCA
514
        if (is_file($this->logomarca)) {
515
            $xImg = $margemInterna;
516
            $yImg = $margemInterna + 1;
517
            $this->pdf->image($this->logomarca, $xImg, $yImg, 30, 22.5);
518
            $xRs = ($maxW * 0.4) + $margemInterna;
519
            $wRs = ($maxW * 0.6);
520
            $alignEmit = 'C';
521
        } else {
522
            $xRs = $margemInterna;
523
            $wRs = ($maxW * 1);
524
            $alignEmit = 'C';
525
        }
526
        //COLOCA RAZÃO SOCIAL
527
        $texto = $emitRazao;
528
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
529
        $this->pdf->textBox($xRs, $y, $wRs, $this->hLinha + 1, $texto, $aFont, 'T', $alignEmit, 0, '', false);
530
        $y = $y + 3;
531
        $texto = "CNPJ: " . $emitCnpj;
532
        $texto = $texto . " IE: " . $emitIE;
533
        $texto = $texto . "\n" . $emitLgr . "," . $emitNro . " " . $emitCpl . "," . $emitBairro . ". CEP: " . $emitCEP . " . " . $emitMun . "-" . $emitUF . $emitFone . "\nDocumento Auxiliar do Bilhete de Passagem Eletrônico";
534
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
535
        if (empty($this->dhCont)) {
536
            $texto = $texto . "\n____________________________________________________";
537
            $this->pdf->textBox($xRs, $y, $wRs, $h, $texto, $aFont, 'T', $alignEmit, 0, '', false);
538
        } else {
539
            $texto = $texto . "\n____________________________________________________";
540
            $this->pdf->textBox($xRs, $y, $wRs, $this->hLinha, $texto, $aFont, 'T', $alignEmit, 0, '', false);
541
            $texto = "\nEMITIDA EM CONTINGÊNCIA\nPendente de autorização\n____________________________________________________";
542
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
543
            $this->pdf->textBox($xRs, $h - $this->hLinha, $wRs, $this->hlinha * 2, $texto, $aFont, 'T', $alignEmit, 0, '', false);
0 ignored issues
show
Bug introduced by
The property hlinha does not seem to exist. Did you mean hLinha?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
544
        }
545
546
    }
547
548
    protected function cabecalhoSecundarioDABPE($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...
549
    {
550
        $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...
551
        $maxW = $this->wPrint;
552
        $w = ($maxW * 1);
553
        $hBox1 = 12;
554
        $hBox2 = 12;
555
        $yBox2 = $y + $hBox1;
556
        $origem = $this->getTagValue($this->infPassagem, "xLocOrig");
557
        $uforigem = $this->getTagValue($this->ide, "UFIni");
558
        $texto = "\nOrigem:" . $origem . "(" . $uforigem . ")";
559
        $destino = $this->getTagValue($this->infPassagem, "xLocDest");
560
        $ufdestino = $this->getTagValue($this->ide, "UFFim");
561
        $texto = $texto . "\nDestino:" . $destino . "(" . $ufdestino . ")";
562
        $dhViagem = $this->getTagValue($this->infViagem, "dhViagem");
563
        $dhViagemformatado = new \DateTime($dhViagem);
564
        $data = $dhViagemformatado->format('d/m/Y');
565
        $hora = $dhViagemformatado->format('H:i:s');
566
        $texto = $texto . "\nData: " . $data . " | Horário: " . $hora;
567
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
568
        $this->pdf->textBox($x, $y, $w, $hBox1, $texto, $aFont, 'T', 'C', 0, '', false);
569
        if ($this->getTagValue($this->infViagem, "prefixo") !== null) {
570
            $prefixo = $this->getTagValue($this->infViagem, "prefixo");
571
        } else {
572
            $prefixo = "";
573
        }
574
        $linha = $this->getTagValue($this->infViagem, "xPercurso");
575
        $tpServ = $this->getTagValue($this->infViagem, "tpServ");
576
        switch ($tpServ) {
577
            case "1":
578
                $tipo = "Convencional com sanitário";
579
                break;
580
            case "2":
581
                $tipo = "Convencional sem sanitário";
582
                break;
583
            case "3":
584
                $tipo = "Semileito";
585
                break;
586
            case "4":
587
                $tipo = "Leito com ar condicionado";
588
                break;
589
            case "5":
590
                $tipo = "Leito sem ar condicionado";
591
                break;
592
            case "6":
593
                $tipo = "Executivo";
594
                break;
595
            case "7":
596
                $tipo = "Semiurbano";
597
                break;
598
            case "8":
599
                $tipo = "Longitudinal";
600
                break;
601
            case "9":
602
                $tipo = "Travessia";
603
                break;
604
        }
605
606
        $texto = "\n(Poltrona: " . $this->getTagValue($this->infViagem, "poltrona") . " Plataforma: " . $this->getTagValue($this->infViagem, "plataforma") . ")";
607
        $texto = $texto . "\nPrefixo: " . $prefixo . "  Linha: " . $linha . "\nTipo: " . $tipo . "\n_____________________________________________________________";
0 ignored issues
show
Bug introduced by
The variable $tipo 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...
608
        $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
609
        $this->pdf->textBox($x, $yBox2, $w, $hBox2, $texto, $aFont, 'T', 'C', 0, '', false);
610
    }
611
612
    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...
613
    {
614
        $qtdItens = $this->Comp->length;
615
        $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...
616
        $maxW = $this->wPrint;
617
        $w = $maxW;
618
        $hLinha = $this->hLinha;
619
        $cont = 0;
620
        $aFontComp = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
621
        if ($qtdItens > 0) {
622
            foreach ($this->Comp as $compI) {
623
                $item = $compI;
624
                $tpComp = $this->getTagValue($item, "tpComp");
625
                switch ($tpComp) {
626
                    case "01":
627
                        $xtpComp = "TARIFA";
628
                        break;
629
                    case "02":
630
                        $xtpComp = "PEDAGIO";
631
                        break;
632
                    case "03":
633
                        $xtpComp = "TAXA EMBARQUE";
634
                        break;
635
                    case "04":
636
                        $xtpComp = "SEGURO";
637
                        break;
638
                    case "05":
639
                        $xtpComp = "TMR";
640
                        break;
641
                    case "06":
642
                        $xtpComp = "SVI";
643
                        break;
644
                    case "99":
645
                        $xtpComp = "OUTROS";
646
                        break;
647
648
                    default:
649
                        $xtpComp = "Outro";
650
                        break;
651
                }
652
                //COLOCA DESCRIÇÃO DO COMPONENTE(tpComp)
653
                $wBoxComp = $w / 2;
654
                $texto = $xtpComp;
655
                $yBoxComp = $y + $hLinha + ($cont * $hLinha);
656
                $this->pdf->textBox(
657
                    $x,
658
                    $yBoxComp,
659
                    $wBoxComp,
660
                    $hLinha,
661
                    $texto,
662
                    $aFontComp,
663
                    'C',
664
                    'L',
665
                    0,
666
                    '',
667
                    false
668
                );
669
                $vComp = number_format($this->getTagValue($item, "vComp"), 2, ",", ".");
670
                //COLOCA VALOR DO COMPONENTE
671
                $wBoxValor = $w / 2;
672
                $xBoxValor = ($w / 2) + 2;
673
                $texto = $vComp;
674
                $this->pdf->textBox(
675
                    $xBoxValor,
676
                    $yBoxComp,
677
                    $wBoxValor,
678
                    $hLinha,
679
                    $texto,
680
                    $aFontComp,
681
                    'C',
682
                    'R',
683
                    0,
684
                    '',
685
                    false
686
                );
687
688
                $cont++;
689
            }
690
        }
691
    }
692
693
    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...
694
    {
695
        $maxW = $this->wPrint;
696
        $hLinha = 3;
697
        $wColEsq = ($maxW * 0.7);
698
        $wColDir = ($maxW * 0.3);
699
        $xValor = $x + $wColEsq;
700
        $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...
701
702
        $vBP = number_format($this->getTagValue($this->infValorBPe, "vBP"), 2, ",", ".");
703
        $vDesconto = number_format($this->getTagValue($this->infValorBPe, "vDesconto"), 2, ",", ".");
704
        $vTroco = number_format($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...
705
        $vPgto = number_format($this->getTagValue($this->infValorBPe, "vPgto"), 2, ",", ".");
706
        $yTotal = $y + ($hLinha);
707
708
        $texto = "Valor total R$";
709
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
710
        $this->pdf->textBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
711
712
        $texto = $vBP;
713
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
714
        $this->pdf->textBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
715
716
        $yDesconto = $y + ($hLinha * 2);
717
        $texto = "Desconto R$";
718
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
719
        $this->pdf->textBox($x, $yTotal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
720
721
        $texto = $vDesconto;
722
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => ''];
723
        $this->pdf->textBox($xValor, $yTotal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
724
725
        $yFrete = $y + ($hLinha * 3);
0 ignored issues
show
Unused Code introduced by
$yFrete 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...
726
        $texto = "Valor a Pagar R$";
727
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B'];
728
        $this->pdf->textBox($x, $yDesconto, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
729
730
        $texto = $vPgto;
731
        $aFont = ['font' => $this->fontePadrao, 'size' => 7, 'style' => 'B'];
732
        $this->pdf->textBox($xValor, $yDesconto, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
733
734
    }
735
736
    protected function fiscalDABPE($x = 0, $y = 0, $h = 0)
737
    {
738
        $y += 8;
739
        $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...
740
        $maxW = $this->wPrint;
741
        $w = ($maxW * 1);
742
        $hLinha = $this->hLinha;
743
        $aFontTit = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B'];
744
        $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
745
        $chBPe = str_replace('BPe', '', $this->infBPe->getAttribute("Id"));
746
747
        if ($this->checkCancelada()) {
748
            //101 Cancelamento
749
            $this->pdf->setTextColor(255, 0, 0);
750
            $texto = "BPe CANCELADO";
751
            $this->pdf->textBox($x, $y - 25, $w, $h, $texto, ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B'], 'T', 'C', 0, '');
752
            $this->pdf->setTextColor(0, 0, 0);
753
        }
754
755
        if (!$this->checkNaoAutorizada()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->checkNaoAutorizada() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
756
            //'' Não Aprovada
757
            $this->pdf->setTextColor(255, 0, 0);
758
            $texto = "SEM VALOR FISCAL";
759
            $this->pdf->textBox($x, $y - 25, $w, $h, $texto, ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B'], 'T', 'C', 0, '');
760
            $this->pdf->setTextColor(0, 0, 0);
761
        }
762
763
        if ($this->checkSubstituto()) {
764
            //uso denegado
765
            $this->pdf->setTextColor(255, 0, 0);
766
            $texto = "BPe Substituto";
767
            $this->pdf->textBox($x, $y - 25, $w, $h, $texto, $aFontTit, 'T', 'C', 0, '');
768
            $this->pdf->SetTextColor(0, 0, 0);
769
        }
770
771
        $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...
772
        $nBP = $this->getTagValue($this->ide, 'nBP');
773
        $serieBPe = str_pad($this->getTagValue($this->ide, "serie"), 3, "0", STR_PAD_LEFT);
774
        $dhEmi = $this->getTagValue($this->ide, "dhEmi");
775
        $dhEmilocal = new \DateTime($dhEmi);
776
        $dhEmiLocalFormat = $dhEmilocal->format('d/m/Y H:i:s');
777
778
        $texto = "Consulte pela chave de acesso em \n";
779
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
780
781
        $texto = $this->urlConsulta($this->getTagValue($this->ide, 'cUF'));
782
        $y = $y + $hLinha;
783
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'T', 'C', 0, '', false);
784
785
        $texto = $chBPe ?? 'Chave Não Localizada no XML';
786
        $y = $y + $hLinha;
787
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
788
789
        $y = $y + $hLinha;
790
        $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...
791
792
        if (isset($this->infPassageiro)) {
793
            $xNome = $this->getTagValue($this->infPassageiro, "xNome");
794
            $nDoc = $this->getTagValue($this->infPassageiro, "nDoc");
795
            $texto = "PASSAGEIRO: DOC: " . $nDoc . " - " . $xNome;
796
            $y = $y + $hLinha;
797
            $this->pdf->textBox($x, $y, $w, $hLinha * 2, $texto, $aFontTex, 'T', 'C', 0, '', false);
798
        }
799
800
        if (!empty($this->getTagValue($this->infValorBPe, "tpDesconto"))) {
801
802
            switch ($this->getTagValue($this->infValorBPe, "tpDesconto")) {
803
                case "01":
804
                    $xtpDesconto = "Tarifa promocional";
805
                    break;
806
                case "02":
807
                    $xtpDesconto = "Idoso";
808
                    break;
809
                case "03":
810
                    $xtpDesconto = "Criança";
811
                    break;
812
                case "04":
813
                    $xtpDesconto = "Deficiente";
814
                    break;
815
                case "05":
816
                    $xtpDesconto = "Estudante";
817
                    break;
818
                case "06":
819
                    $xtpDesconto = "Animal Doméstico";
820
                    break;
821
                case "07":
822
                    $xtpDesconto = "Acordo Coletivo";
823
                    break;
824
                case "08":
825
                    $xtpDesconto = "Profissional em Deslocamento";
826
                    break;
827
                case "09":
828
                    $xtpDesconto = "Profissional da Empresa";
829
                    break;
830
                case "10":
831
                    $xtpDesconto = "Jovem";
832
                    break;
833
                case "99":
834
                    $xtpDesconto = "Outros";
835
                    break;
836
            }
837
            $y = $y + $hLinha * 3;
838
            $texto = "TIPO DE DESCONTO: " . $xtpDesconto;
0 ignored issues
show
Bug introduced by
The variable $xtpDesconto 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...
839
            $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
840
        }
841
842
        $texto = "BP-e nº " . $nBP . " Série " . $serieBPe . " " . $dhEmiLocalFormat;
843
        $y = $y + ($hLinha * 3);
844
        $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'T', 'C', 0, '', false);
845
846
        $y = $y + $hLinha * 2;
847
        if (empty($this->dhCont)) {
848
849
            $nProt = $this->getTagValue($this->protBPe, "nProt");
850
            $dhRecbto = $this->getTagValue($this->protBPe, "dhRecbto");
851
            $dhRecbto = new \DateTime($dhRecbto);
852
            $texto = "Protocolo de autorização: " . $nProt;
853
            $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
854
            $y = $y + $hLinha * 2;
855
            $texto = "\nData de autorização: " . $dhRecbto->format('d/m/Y H:i:s');
856
            $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
857
858
        } else {
859
            $texto = "EMITIDA EM CONTINGÊNCIA";
860
            $aFontTex = ['font' => $this->fontePadrao, 'size' => 12, 'style' => 'B'];
861
            $this->pdf->textBox($x, $yTex3 + $hLinha, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
0 ignored issues
show
Bug introduced by
The variable $yTex3 does not exist. Did you forget to declare it?

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

Loading history...
862
            $yTex4 = $y + ($hLinha * 8);
863
            $texto = "\nPendente de autorização ";
864
            $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
865
            $this->pdf->textBox($x, $yTex4 + $hLinha, $w, $hLinha, $texto, $aFontTex, 'T', 'C', 0, '', false);
866
        }
867
    }
868
869
    protected function checkCancelada()
870
    {
871
        if (!isset($this->infProt)) {
872
            return false;
873
        }
874
        $cStat = $this->getTagValue($this->infProt, "cStat");
875
        return $cStat == '101';
876
    }
877
878
    protected function checkNaoAutorizada()
879
    {
880
        if (!isset($this->infProt)) {
881
            $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...
882
            return $cStat == '';
883
        }
884
    }
885
886
    protected function checkSubstituto()
887
    {
888
        if (!isset($this->infProt)) {
889
            return false;
890
        }
891
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
892
        //1 VEZ NO ARQUIVO INTEIRO
893
        $cStat = $this->getTagValue($this->infProt, "cStat");
894
        return $cStat == '102';
895
    }
896
897
    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...
898
    {
899
        $y += 15;
900
        $margemInterna = $this->margemInterna;
901
        $maxW = $this->wPrint;
902
        $w = ($maxW * 1) + 4;
903
        $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...
904
        $hBoxLinha = $this->hBoxLinha;
905
        $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...
906
        $aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
907
        $dhRecbto = '';
908
        $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...
909
        if (isset($this->infBPeSupl)) {
910
            $nProt = $this->getTagValue($this->nfeProc, "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...
911
            $dhRecbto = $this->getTagValue($this->nfeProc, "dhRecbto");
912
        }
913
914
        $barcode = new Barcode();
915
        $bobj = $barcode->getBarcodeObj(
916
            'QRCODE,M',
917
            $this->qrCodBPe,
918
            -4,
919
            -4,
920
            'black',
921
            array(-2, -2, -2, -2)
922
        )->setBackgroundColor('white');
923
        $qrcode = $bobj->getPngData();
924
        $wQr = 50;
925
        $hQr = 50;
926
        $yQr = ($y + $margemInterna);
927
        $xQr = ($w / 2) - ($wQr / 2);
928
        // prepare a base64 encoded "data url"
929
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
930
        $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...
931
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
932
        $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...
933
        $yQr = ($yQr + $hQr + $margemInterna);
934
935
        if (isset($this->ICMSSN)) {
936
            $vTotTrib = $this->getTagValue($this->ICMSSN, "vTotTrib");
937
            $this->pdf->textBox($x, $yQr, $w - 4, $hBoxLinha, "Tributos Totais Incidentes(Lei Federal 12.741/2012): R$" . $vTotTrib, $aFontTex, 'C', 'C', 0, '', false);
938
        }
939
940
    }
941
942
    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...
943
    {
944
        $y += 17;
945
        $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...
946
        $maxW = $this->wPrint;
947
        $w = ($maxW * 1);
948
        $hLinha = $this->hLinha;
949
        $aFontTit = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B'];
950
        $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
951
        // seta o textbox do titulo
952
        $texto = "INFORMAÇÃO ADICIONAL";
953
        $heigthText = $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', 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...
954
955
        // seta o textbox do texto adicional
956
        $this->pdf->textBox($x, $y + 3, $w - 2, $hLinha - 3, $this->textoAdic, $aFontTex, 'T', 'L', 0, '', false);
957
    }
958
959
    public function paperWidth($width = 80)
960
    {
961
        if (is_int($width) && $width > 60) {
962
            $this->paperwidth = $width;
963
        }
964
        return $this->paperwidth;
965
    }
966
967
//    public function inicia($id)
968
//    {
969
//        $pdo = Conexao::getInstance();
970
//        $bpe = $pdo->prepare('SELECT chbpe, CNPJ FROM bpe WHERE id = ? ')
971
//            ->execute([
972
//                $id,
973
//            ]);
974
//        $pastaxml = 'homologacao'; // Pegar do Banco de dados, se emissão em homologação ou produção
975
//        $filename = "../../../../_backend/XML/{$bpe->CNPJ}/BP-e/{$pastaxml}/assinadas/{$bpe->chBPe}-bpe.xml"; // Ambiente Windows
976
//        file_get_contents($filename, $xml);
977
//        try {
978
//            $this->__construct($xml, '', 1);
979
//            $pdf = $this->render();
980
//            header('Content-Type: application/pdf');
981
//            echo $pdf;
982
//        }
983
//    }
984
985
    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...
986
    {
987
        $y += 6;
988
        $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...
989
        $maxW = $this->wPrint;
990
        $qtdPgto = $this->pag->length;
991
        $w = ($maxW * 1);
992
        $hLinha = $this->hLinha;
993
        $wColEsq = ($maxW * 0.7);
994
        $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...
995
        $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...
996
        $aFontPgto = array('font' => $this->fontePadrao, 'size' => 7, 'style' => '');
997
        $wBoxEsq = $w * 0.7;
998
        $texto = "FORMA PAGAMENTO";
999
        $this->pdf->textBox($x, $y, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
1000
        $wBoxDir = $w * 0.3;
1001
        $xBoxDescricao = $x + $wBoxEsq;
1002
        $texto = "VALOR PAGO";
1003
        $this->pdf->textBox($xBoxDescricao, $y, $wBoxDir, $hLinha, $texto, $aFontPgto, 'T', 'R', 0, '', false);
1004
        $vTroco = number_format($this->getTagValue($this->infValorBPe, "vTroco"), 2, ",", ".");
1005
        $cont = 0;
1006
        if ($qtdPgto > 0) {
1007
            foreach ($this->pag as $pagI) {
1008
                $tPag = $this->getTagValue($pagI, "tPag");
1009
                switch ($tPag) {
1010
                    case "01":
1011
                        $tPagNome = "Dinheiro R$";
1012
                        break;
1013
                    case "02":
1014
                        $tPagNome = "Cheque R$";
1015
                        break;
1016
                    case "03":
1017
                        $tPagNome = "Cartão de Crédito R$";
1018
                        break;
1019
                    case "04":
1020
                        $tPagNome = "Cartão de Débito R$";
1021
                        break;
1022
                    case "05":
1023
                        $tPagNome = "Vale Transporte R$";
1024
                        break;
1025
                    case "99":
1026
                        $tPagNome = "Outros";
1027
                        break;
1028
                }
1029
                $vPag = number_format($this->getTagValue($pagI, "vPag"), 2, ",", ".");
1030
                $yBoxProd = $y + $hLinha + ($cont * $hLinha);
1031
                $texto = $tPagNome;
0 ignored issues
show
Bug introduced by
The variable $tPagNome 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...
1032
                $this->pdf->textBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
1033
                //COLOCA PRODUTO DESCRIÇÃO
1034
                $xBoxDescricao = $wBoxEsq + $x;
1035
                $texto = $vPag;
1036
                $this->pdf->textBox(
1037
                    $xBoxDescricao,
1038
                    $yBoxProd,
1039
                    $wBoxDir,
1040
                    $hLinha,
1041
                    $texto,
1042
                    $aFontPgto,
1043
                    'C',
1044
                    'R',
1045
                    0,
1046
                    '',
1047
                    false
1048
                );
1049
                $cont++;
1050
            }
1051
            $ytroco = $qtdPgto;
1052
        } else {
1053
            $ytroco = 1;
1054
        }
1055
        $yBoxProd = $y + $hLinha + ($ytroco * $hLinha);
1056
        $texto = "Troco";
1057
        $this->pdf->textBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
1058
1059
        $texto = $vTroco;
1060
        $this->pdf->textBox(
1061
            $xBoxDescricao,
1062
            $yBoxProd,
1063
            $wBoxDir,
1064
            $hLinha,
1065
            $texto,
1066
            $aFontPgto,
1067
            'C',
1068
            'R',
1069
            0,
1070
            '',
1071
            false
1072
        );
1073
    }
1074
}
1075
1076
/*
1077
    $pdf = $dabpe->render();
1078
    header('Content-Type: application/pdf');
1079
    echo $pdf;
1080
    $xml = file_get_contents($filename, $xml);
1081
    $dabpe = new Dabpe($xml);
1082
1083
} catch (Exception $e) {
1084
    echo $e->getMessage();
1085
}
1086
*/
1087