Passed
Push — master ( 0f40a7...02804d )
by Roberto
02:45 queued 10s
created

Damdfe::qrCodeDamdfe()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 25
ccs 0
cts 24
cp 0
crap 6
rs 9.52
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\MDFe;
4
5
/**
6
 * Esta classe gera do PDF do MDFDe, conforme regras e estruturas
7
 * estabelecidas pela SEFAZ.
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @name      Damdfe.php
12
 * @copyright 2009-2016 NFePHP
13
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
14
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
15
 * @author    Leandro C. Lopez <leandro dot castoldi at gmail dot com>
16
 */
17
18
use Com\Tecnick\Barcode\Barcode;
19
use NFePHP\DA\Legacy\Dom;
20
use NFePHP\DA\Legacy\Common;
21
use NFePHP\DA\Legacy\Pdf;
22
23
class Damdfe extends Common
24
{
25
    //publicas
26
    public $logoAlign = 'L'; //alinhamento do logo
27
    public $yDados = 0;
28
    public $debugMode = 0; //ativa ou desativa o modo de debug
29
    //privadas
30
    protected $pdf; // objeto fpdf()
31
    protected $xml; // string XML NFe
32
    protected $logomarca = ''; // path para logomarca em jpg
33
    protected $errMsg = ''; // mesagens de erro
34
    protected $errStatus = false;// status de erro TRUE um erro ocorreu false sem erros
35
    protected $orientacao = 'P'; //orientação da DANFE P-Retrato ou L-Paisagem
36
    protected $papel = 'A4'; //formato do papel
37
    //destivo do arquivo pdf I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
38
    protected $destino = 'I';
39
    protected $pdfDir = ''; //diretorio para salvar o pdf com a opção de destino = F
40
    protected $fontePadrao = 'Times'; //Nome da Fonte para gerar o DANFE
41
    protected $version = '3.00a';
42
    protected $wPrint; //largura imprimivel
43
    protected $hPrint; //comprimento imprimivel
44
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
45
    protected $margemInterna = 2;
46
47
    //variaveis da damdfe
48
    protected $id;
49
    protected $chMDFe;
50
    protected $tpAmb;
51
    protected $cOrgao;
52
    protected $xCondUso;
53
    protected $dhEvento;
54
    protected $cStat;
55
    protected $xMotivo;
56
    protected $CNPJDest = '';
57
    protected $dhRegEvento;
58
    protected $nProt;
59
    protected $tpEmis;
60
    protected $qrCodMDFe;
61
    //objetos
62
    private $dom;
63
64
    /**
65
     * __construct
66
     *
67
     * @param string $xmlfile Arquivo XML da MDFe
68
     * @param string $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
69
     * @param string $sPapel Tamanho do papel (Ex. A4)
70
     * @param string $sPathLogo Caminho para o arquivo do logo
71
     * @param string $sDestino Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
72
     * @param string $sDirPDF Caminho para o diretorio de armazenamento dos arquivos PDF
73
     * @param string $fonteDAMDFE Nome da fonte alternativa do DAnfe
0 ignored issues
show
Bug introduced by
There is no parameter named $fonteDAMDFE. 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...
74
     * @param integer $mododebug 0-Não 1-Sim e 2-nada (2 default)
75
     */
76
    public function __construct(
77
        $xmlfile = '',
78
        $sOrientacao = '',
79
        $sPapel = '',
80
        $sPathLogo = '',
81
        $sDestino = 'I',
82
        $sDirPDF = '',
83
        $fontePDF = '',
84
        $mododebug = 2
85
    ) {
86
        //define o caminho base da instalação do sistema
87
        if (!defined('PATH_ROOT')) {
88
            define('PATH_ROOT', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
89
        }
90
        //ajuste do tempo limite de resposta do processo
91
        set_time_limit(1800);
92
        //definição do caminho para o diretorio com as fontes do FDPF
93
        if (!defined('FPDF_FONTPATH')) {
94
            define('FPDF_FONTPATH', 'font/');
95
        }
96
97
        if (is_numeric($mododebug)) {
98
            $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...
99
        }
100
        if ($this->debugMode) {
101
            //ativar modo debug
102
            error_reporting(E_ALL);
103
            ini_set('display_errors', 'On');
104
        } else {
105
            //desativar modo debug
106
            error_reporting(0);
107
            ini_set('display_errors', 'Off');
108
        }
109
        $this->orientacao = $sOrientacao;
110
        $this->papel = $sPapel;
111
        $this->pdf = '';
112
        $this->xml = $xmlfile;
113
        $this->logomarca = $sPathLogo;
114
        $this->destino = $sDestino;
115
        $this->pdfDir = $sDirPDF;
116
        // verifica se foi passa a fonte a ser usada
117
        if (empty($fontePDF)) {
118
            $this->fontePadrao = 'Times';
119
        } else {
120
            $this->fontePadrao = $fontePDF;
121
        }
122
        //se for passado o xml
123
        if (empty($xmlfile)) {
124
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
125
            $this->errStatus = true;
126
        }
127
        if (!is_file($xmlfile)) {
128
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
129
            $this->errStatus = true;
130
        }
131
132
        $this->dom = new Dom();
133
        $this->dom->loadXML($this->xml);
134
        $this->mdfeProc = $this->dom->getElementsByTagName("mdfeProc")->item(0);
0 ignored issues
show
Bug introduced by
The property mdfeProc 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...
135
        $this->infMDFe = $this->dom->getElementsByTagName("infMDFe")->item(0);
0 ignored issues
show
Bug introduced by
The property infMDFe 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...
136
        $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
0 ignored issues
show
Bug introduced by
The property emit 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...
137
        if ($this->dom->getElementsByTagName("CPF")->item(0)) {
138
            $this->CPF = $this->dom->getElementsByTagName("CPF")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property CPF 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...
139
        } else {
140
            $this->CNPJ = $this->dom->getElementsByTagName("CNPJ")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property CNPJ 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...
141
        }
142
        $this->IE = $this->dom->getElementsByTagName("IE")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property IE 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...
143
        $this->xNome = $this->dom->getElementsByTagName("xNome")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property xNome 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...
144
        $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
0 ignored issues
show
Bug introduced by
The property enderEmit 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...
145
        $this->xLgr = $this->dom->getElementsByTagName("xLgr")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property xLgr 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...
146
        $this->nro = $this->dom->getElementsByTagName("nro")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property nro 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...
147
        $this->xBairro = $this->dom->getElementsByTagName("xBairro")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property xBairro 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...
148
        $this->UF = $this->dom->getElementsByTagName("UF")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property UF 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...
149
        $this->xMun = $this->dom->getElementsByTagName("xMun")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property xMun 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...
150
        $this->CEP = $this->dom->getElementsByTagName("CEP")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property CEP 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...
151
        $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
0 ignored issues
show
Bug introduced by
The property ide 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...
152
        $this->tpAmb = $this->dom->getElementsByTagName("tpAmb")->item(0)->nodeValue;
153
        $this->mod = $this->dom->getElementsByTagName("mod")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property mod 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...
154
        $this->serie = $this->dom->getElementsByTagName("serie")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property serie 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...
155
        $this->dhEmi = $this->dom->getElementsByTagName("dhEmi")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property dhEmi does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
156
        $this->UFIni = $this->dom->getElementsByTagName("UFIni")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property UFIni 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...
157
        $this->UFFim = $this->dom->getElementsByTagName("UFFim")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property UFFim 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...
158
        $this->nMDF = $this->dom->getElementsByTagName("nMDF")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property nMDF 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...
159
        $this->tpEmis = $this->dom->getElementsByTagName("tpEmis")->item(0)->nodeValue;
160
        $this->tot = $this->dom->getElementsByTagName("tot")->item(0);
0 ignored issues
show
Bug introduced by
The property tot does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
161
        $this->qMDFe = "";
0 ignored issues
show
Bug introduced by
The property qMDFe 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...
162
        if ($this->dom->getElementsByTagName("qMDFe")->item(0) != "") {
163
            $this->qMDFe = $this->dom->getElementsByTagName("qMDFe")->item(0)->nodeValue;
164
        }
165
        $this->qNFe = "";
0 ignored issues
show
Bug introduced by
The property qNFe 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...
166
        if ($this->dom->getElementsByTagName("qNFe")->item(0) != "") {
167
            $this->qNFe = $this->dom->getElementsByTagName("qNFe")->item(0)->nodeValue;
168
        }
169
        $this->qNF = "";
0 ignored issues
show
Bug introduced by
The property qNF 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...
170
        if ($this->dom->getElementsByTagName("qNF")->item(0) != "") {
171
            $this->qNF = $this->dom->getElementsByTagName("qNF")->item(0)->nodeValue;
172
        }
173
        $this->qCTe = "";
0 ignored issues
show
Bug introduced by
The property qCTe 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...
174
        if ($this->dom->getElementsByTagName("qCTe")->item(0) != "") {
175
            $this->qCTe = $this->dom->getElementsByTagName("qCTe")->item(0)->nodeValue;
176
        }
177
        $this->qCT = "";
0 ignored issues
show
Bug introduced by
The property qCT does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
178
        if ($this->dom->getElementsByTagName("qCT")->item(0) != "") {
179
            $this->qCT = $this->dom->getElementsByTagName("qCT")->item(0)->nodeValue;
180
        }
181
        $this->qCarga = $this->dom->getElementsByTagName("qCarga")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property qCarga does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
183
        $this->rodo = $this->dom->getElementsByTagName("rodo")->item(0);
0 ignored issues
show
Bug introduced by
The property rodo 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...
184
        $this->aereo = $this->dom->getElementsByTagName("aereo")->item(0);
0 ignored issues
show
Bug introduced by
The property aereo 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...
185
        $this->aquav = $this->dom->getElementsByTagName("aquav")->item(0);
0 ignored issues
show
Bug introduced by
The property aquav 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...
186
        $this->ferrov = $this->dom->getElementsByTagName("ferrov")->item(0);
0 ignored issues
show
Bug introduced by
The property ferrov does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
187
        $this->ciot = "";
0 ignored issues
show
Bug introduced by
The property ciot 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...
188
        if ($this->dom->getElementsByTagName('CIOT')->item(0) != "") {
189
            $this->ciot = $this->dom->getElementsByTagName('CIOT')->item(0)->nodeValue;
190
        }
191
        $this->veicTracao = $this->dom->getElementsByTagName("veicTracao")->item(0);
0 ignored issues
show
Bug introduced by
The property veicTracao 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...
192
        $this->veicReboque = $this->dom->getElementsByTagName("veicReboque");
0 ignored issues
show
Bug introduced by
The property veicReboque does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
194
        if ($this->dom->getElementsByTagName("valePed")->item(0) != "") {
195
            $this->valePed = $this->dom->getElementsByTagName("valePed")->item(0)->getElementsByTagName("disp");
196
        }
197
        $this->infCpl = ($infCpl = $this->dom->getElementsByTagName('infCpl')->item(0)) ? $infCpl->nodeValue : "";
0 ignored issues
show
Bug introduced by
The property infCpl does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
198
        $this->chMDFe = str_replace(
199
            'MDFe',
200
            '',
201
            $this->infMDFe->getAttribute("Id")
202
        );
203
        $this->qrCodMDFe = $this->dom->getElementsByTagName('qrCodMDFe')->item(0) ?
204
            $this->dom->getElementsByTagName('qrCodMDFe')->item(0)->nodeValue : 'SEM INFORMAÇÃO DE QRCODE';
205
        if (is_object($this->mdfeProc)) {
206
            $this->nProt = !empty($this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
207
                $this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
208
            $this->dhRecbto = $this->mdfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property dhRecbto 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...
209
        }
210
    }//fim construct
211
212
    /**
213
     *buildMDFe
214
     *
215
     */
216
    public function buildMDFe()
217
    {
218
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
219
        if ($this->orientacao == 'P') {
220
            // margens do PDF
221
            $margSup = 7;
222
            $margEsq = 7;
223
            $margDir = 7;
224
            // posição inicial do relatorio
225
            $xInic = 7;
226
            $yInic = 7;
227
            if ($this->papel == 'A4') { //A4 210x297mm
228
                $maxW = 210;
229
                $maxH = 297;
230
            }
231
        } else {
232
            // margens do PDF
233
            $margSup = 7;
234
            $margEsq = 7;
235
            $margDir = 7;
236
            // posição inicial do relatorio
237
            $xInic = 7;
238
            $yInic = 7;
239
            if ($this->papel == 'A4') { //A4 210x297mm
240
                $maxH = 210;
241
                $maxW = 297;
242
            }
243
        }//orientação
244
        //largura imprimivel em mm
245
        $this->wPrint = $maxW - ($margEsq + $xInic);
0 ignored issues
show
Bug introduced by
The variable $maxW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
246
        //comprimento imprimivel em mm
247
        $this->hPrint = $maxH - ($margSup + $yInic);
0 ignored issues
show
Bug introduced by
The variable $maxH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
248
        // estabelece contagem de paginas
249
        $this->pdf->aliasNbPages();
250
        // fixa as margens
251
        $this->pdf->setMargins($margEsq, $margSup, $margDir);
252
        $this->pdf->setDrawColor(0, 0, 0);
253
        $this->pdf->setFillColor(255, 255, 255);
254
        // inicia o documento
255
        $this->pdf->open();
256
        // adiciona a primeira página
257
        $this->pdf->addPage($this->orientacao, $this->papel);
258
        $this->pdf->setLineWidth(0.1);
259
        $this->pdf->setTextColor(0, 0, 0);
260
        //montagem da página
261
        $pag = 1;
262
        $x = $xInic;
263
        $y = $yInic;
264
        //coloca o cabeçalho Paisagem
265
        if ($this->orientacao == 'P') {
266
            $y = $this->headerMDFeRetrato($x, $y, $pag);
267
        } else {
268
            $y = $this->headerMDFePaisagem($x, $y, $pag);
269
        }
270
        //coloca os dados da MDFe
271
        $y = $this->bodyMDFe($x, $y);
272
        //coloca os dados da MDFe
273
        $y = $this->footerMDFe($x, $y);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->footerMDFe($x, $y) (which targets NFePHP\DA\MDFe\Damdfe::footerMDFe()) 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...
274
    } //fim buildCCe
275
276
    /**
277
     * headerMDFePaisagem
278
     * @param float $x
279
     * @param float $y
280
     * @param integer $pag
281
     * @return string
282
     */
283
    private function headerMDFePaisagem($x, $y, $pag)
0 ignored issues
show
Unused Code introduced by
The parameter $pag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
284
    {
285
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX is not used, you could remove the assignment.

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

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

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

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

Loading history...
286
        $oldY = $y;
287
        $maxW = $this->wPrint;
288
        //####################################################################################
289
        //coluna esquerda identificação do emitente
290
        //$w = $maxW; //round($maxW*0.41, 0);// 80;
291
        $w = round($maxW * 0.70, 0);
292
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
293
        $w1 = $w;
0 ignored issues
show
Unused Code introduced by
$w1 is not used, you could remove the assignment.

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

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

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

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

Loading history...
294
        $h = 30;
295
        $oldY += $h;
296
        $this->pdf->textBox($x, $y, $w, $h);
297
        if (is_file($this->logomarca)) {
298
            $logoInfo = getimagesize($this->logomarca);
299
            //largura da imagem em mm
300
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
301
            //altura da imagem em mm
302
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
303
            if ($this->logoAlign == 'L') {
304
                $nImgW = round($w / 3, 0);
305
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
306
                $xImg = $x + 1;
307
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
308
                //estabelecer posições do texto
309
                $x1 = round($xImg + $nImgW + 1, 0);
310
                $y1 = round($y + 2, 0);
311
                $tw = round(2 * $w / 3, 0);
312
            }
313
            if ($this->logoAlign == 'C') {
314
                $nImgH = round($h / 3, 0);
315
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
316
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
317
                $yImg = $y + 3;
318
                $x1 = $x;
319
                $y1 = round($yImg + $nImgH + 1, 0);
320
                $tw = $w;
321
            }
322
            if ($this->logoAlign == 'R') {
323
                $nImgW = round($w / 3, 0);
324
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
325
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
326
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
327
                $x1 = $x;
328
                $y1 = round($h / 3 + $y, 0);
329
                $tw = round(2 * $w / 3, 0);
330
            }
331
            $this->pdf->image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, 'jpeg');
0 ignored issues
show
Bug introduced by
The variable $xImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $yImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
332
        } else {
333
            $x1 = $x;
334
            $y1 = round($h / 3 + $y, 0);
335
            $tw = $w;
336
        }
337
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
338
        $razao = $this->xNome;
0 ignored issues
show
Unused Code introduced by
$razao 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...
339
        if (isset($this->CPF)) {
340
            $cpfcnpj = 'CPF: ' . $this->formatField($this->CPF, "###.###.###-##");
341
        } else {
342
            $cpfcnpj = 'CNPJ: ' . $this->formatField($this->CNPJ, "###.###.###/####-##");
343
        }
344
        $ie = 'IE: ' . $this->formatField($this->IE, '##/########');
345
        $lgr = 'Logradouro: ' . $this->xLgr;
346
        $nro = 'Nº: ' . $this->nro;
347
        $bairro = 'Bairro: ' . $this->xBairro;
348
        $CEP = $this->CEP;
349
        $CEP = 'CEP: ' . $this->formatField($CEP, "##.###-###");
350
        $UF = 'UF: ' . $this->UF;
351
        $mun = 'Municipio: ' . $this->xMun;
352
353
        $texto = $cpfcnpj . ' - ' . $ie . "\n";
354
        $texto .= $lgr . ' - ' . $nro . "\n";
355
        $texto .= $bairro . "\n";
356
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
357
        $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
358
        $this->pdf->textBox($x1, $y1 + 6, $tw, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $tw does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
359
        //##################################################
360
        $w = round($maxW * 0.70, 0);
361
        $y = $h + 9;
362
        $this->pdf->textBox($x, $y, $w, 6);
363
        $aFont = ['font' => $this->fontePadrao, 'size' => 12, 'style' => 'I'];
364
        $this->pdf->textBox(
365
            $x,
366
            $y,
367
            $w,
368
            8,
369
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
370
            $aFont,
371
            'T',
372
            'C',
373
            0,
374
            ''
375
        );
376
377
        if ($this->tpAmb != 1) {
378
            $x = 10;
379
            if ($this->orientacao == 'P') {
380
                $yy = round($this->hPrint * 2 / 3, 0);
381
            } else {
382
                $yy = round($this->hPrint / 2, 0);
383
            }
384
            $h = 5;
385
            $w = $maxW - (2 * $x);
386
            $this->pdf->setTextColor(90, 90, 90);
387
            $texto = "SEM VALOR FISCAL";
388
            $aFont = ['font' => $this->fontePadrao, 'size' => 48, 'style' => 'B'];
389
            $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
390
            $aFont = ['font' => $this->fontePadrao, 'size' => 30, 'style' => 'B'];
391
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
392
            $this->pdf->textBox($x, $yy + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
393
            $this->pdf->setTextColor(0, 0, 0);
394
        } else {
395
            $x = 10;
396
            if ($this->orientacao == 'P') {
397
                $yy = round($this->hPrint * 2 / 3, 0);
398
            } else {
399
                $yy = round($this->hPrint / 2, 0);
400
            }//fim orientacao
401
            $h = 5;
402
            $w = $maxW - (2 * $x);
403
            $this->pdf->setTextColor(90, 90, 90);
404
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
405
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
406
                //Contingência
407
                $texto = "DAMDFE Emitido em Contingência";
408
                $aFont = ['font' => $this->fontePadrao, 'size' => 48, 'style' => 'B'];
409
                $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
410
                $aFont = ['font' => $this->fontePadrao, 'size' => 30, 'style' => 'B'];
411
                $texto = "devido à problemas técnicos";
412
                $this->pdf->textBox($x, $yy + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
413
            }
414
            $this->pdf->setTextColor(0, 0, 0);
415
        }
416
        return $y + 8;
417
    }// fim headerMDFe
418
419
    /**
420
     * headerMDFeRetrato
421
     *
422
     * @param float $x
423
     * @param float $y
424
     * @param integer $pag
425
     * @return string
426
     */
427
    private function headerMDFeRetrato($x, $y, $pag)
0 ignored issues
show
Unused Code introduced by
The parameter $pag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
428
    {
429
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX is not used, you could remove the assignment.

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

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

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

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

Loading history...
430
        $oldY = $y;
431
        $maxW = $this->wPrint;
432
        //####################################################################################
433
        //coluna esquerda identificação do emitente
434
        //$w = $maxW; //round($maxW*0.41, 0);// 80;
435
        $w = round($maxW * 0.70, 0);
436
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
437
        $w1 = $w;
0 ignored issues
show
Unused Code introduced by
$w1 is not used, you could remove the assignment.

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

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

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

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

Loading history...
438
        $h = 20;
439
        $oldY += $h;
440
        $this->pdf->textBox($x, $y, $w, $h);
441
        if (is_file($this->logomarca)) {
442
            $logoInfo = getimagesize($this->logomarca);
443
            //largura da imagem em mm
444
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
445
            //altura da imagem em mm
446
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
447
            if ($this->logoAlign == 'L') {
448
                // ajusta a dimensão do logo
449
                $nImgW = round($w / 3, 0);
450
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
451
                $xImg = $x + 1;
452
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
453
                //estabelecer posições do texto
454
                $x1 = round($xImg + $nImgW + 1, 0);
455
                $y1 = round($y + 2, 0);
456
                $tw = round(2 * $w / 3, 0);
457
            }
458
            if ($this->logoAlign == 'C') {
459
                $nImgH = round($h / 3, 0);
460
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
461
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
462
                $yImg = $y + 3;
463
                $x1 = $x;
464
                $y1 = round($yImg + $nImgH + 1, 0);
465
                $tw = $w;
466
            }
467
            if ($this->logoAlign == 'R') {
468
                $nImgW = round($w / 3, 0);
469
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
470
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
471
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
472
                $x1 = $x;
473
                $y1 = round($h / 3 + $y, 0);
474
                $tw = round(2 * $w / 3, 0);
475
            }
476
            $this->pdf->image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, 'jpeg');
0 ignored issues
show
Bug introduced by
The variable $xImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $yImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
477
        } else {
478
            $x1 = $x;
479
            $y1 = $y;
480
            $tw = $w;
481
        }
482
483
        if ($this->qrCodMDFe !== null) {
484
            $this->qrCodeDamdfe($y - 3);
485
        }
486
487
        $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B'];
488
        $texto = $this->xNome;
489
        $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $tw does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
490
        if (isset($this->CPF)) {
491
            $cpfcnpj = 'CPF: ' . $this->formatField($this->CPF, "###.###.###-##");
492
        } else {
493
            $cpfcnpj = 'CNPJ: ' . $this->formatField($this->CNPJ, "###.###.###/####-##");
494
        }
495
        $ie = 'IE: ' . $this->formatField($this->IE, '###/#######');
496
        $lgr = 'Logradouro: ' . $this->xLgr;
497
        $nro = 'Nº: ' . $this->nro;
498
        $bairro = 'Bairro: ' . $this->xBairro;
499
        $CEP = $this->CEP;
500
        $CEP = 'CEP: ' . $this->formatField($CEP, "##.###-###");
501
        $mun = 'Municipio: ' . $this->xMun;
502
        $UF = 'UF: ' . $this->UF;
503
        $texto = $cpfcnpj . ' - ' . $ie . "\n";
504
        $texto .= $lgr . ' - ' . $nro . "\n";
505
        $texto .= $bairro . "\n";
506
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
507
        $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
508
        $this->pdf->textBox($x1, $y1 + 4, $tw, 8, $texto, $aFont, 'T', 'L', 0, '');
509
        //##################################################
510
        $w = round($maxW * 0.70, 0);
511
        $y = $h + 9;
512
        $this->pdf->textBox($x, $y, $w, 6);
513
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'I');
514
        $this->pdf->textBox(
515
            $x,
516
            $y,
517
            $w,
518
            8,
519
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
520
            $aFont,
521
            'T',
522
            'C',
523
            0,
524
            ''
525
        );
526
        if ($this->tpAmb != 1) {
527
            $x = 10;
528
            if ($this->orientacao == 'P') {
529
                $yy = round($this->hPrint * 2 / 3, 0);
530
            } else {
531
                $yy = round($this->hPrint / 2, 0);
532
            }
533
            $h = 5;
534
            $w = $maxW - (2 * $x);
535
            $this->pdf->setTextColor(90, 90, 90);
536
            $texto = "SEM VALOR FISCAL";
537
            $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
538
            $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
539
            $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
540
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
541
            $this->pdf->textBox($x, $yy + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
542
            $this->pdf->setTextColor(0, 0, 0);
543
        } else {
544
            $x = 10;
545
            if ($this->orientacao == 'P') {
546
                $yy = round($this->hPrint * 2 / 3, 0);
547
            } else {
548
                $yy = round($this->hPrint / 2, 0);
549
            }//fim orientacao
550
            $h = 5;
551
            $w = $maxW - (2 * $x);
552
            $this->pdf->setTextColor(90, 90, 90);
553
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
554
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
555
                //Contingência
556
                $texto = "DAMDFE Emitido em Contingência";
557
                $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
558
                $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
559
                $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
560
                $texto = "devido à problemas técnicos";
561
                $this->pdf->textBox($x, $yy + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
562
            }
563
            $this->pdf->setTextColor(0, 0, 0);
564
        }
565
        return $y + 8;
566
    }
567
568
    /**
569
     * bodyMDFe
570
     *
571
     * @param float $x
572
     * @param float $y
573
     * @return void
574
     */
575
    private function bodyMDFe($x, $y)
576
    {
577
        if ($this->orientacao == 'P') {
578
            $maxW = $this->wPrint;
579
        } else {
580
            //$maxW = $this->wPrint / 2;
581
            $maxW = $this->wPrint * 0.9;
582
        }
583
        $x2 = ($maxW / 6);
584
        $x1 = $x2;
585
        $this->pdf->textBox($x, $y, $x2 - 22, 12);
586
        $texto = 'Modelo';
587
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
588
        $this->pdf->textBox($x, $y, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
589
        $texto = $this->mod;
590
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
591
        $this->pdf->textBox($x, $y + 4, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
592
593
        if ($this->orientacao == 'P') {
594
            $x1 += $x2 - 47.5;
595
        } else {
596
            $x1 += $x2 - 57.5;
597
        }
598
        $this->pdf->textBox($x1, $y, $x2 - 22, 12);
599
        $texto = 'Série';
600
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
601
        $this->pdf->textBox($x1, $y, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
602
        $texto = $this->serie;
603
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
604
        $this->pdf->textBox($x1, $y + 4, $x2 - 22, 10, $texto, $aFont, 'T', 'C', 0, '', false);
605
606
        $x1 += $x2 - 22;
607
        $this->pdf->textBox($x1, $y, $x2 - 5, 12);
608
        $texto = 'Número';
609
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
610
        $this->pdf->textBox($x1, $y, $x2 - 5, 8, $texto, $aFont, 'T', 'C', 0, '', false);
611
        $texto = $this->formatField(str_pad($this->nMDF, 9, '0', STR_PAD_LEFT), '###.###.###');
612
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
613
        $this->pdf->textBox($x1, $y + 4, $x2 - 5, 10, $texto, $aFont, 'T', 'C', 0, '', false);
614
        $x1 += $x2 - 5;
615
        $this->pdf->textBox($x1, $y, $x2 - 22, 12);
616
        $texto = 'FL';
617
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
618
        $this->pdf->textBox($x1, $y, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
619
        $texto = '1';
620
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
621
        $this->pdf->textBox($x1, $y + 4, $x2 - 22, 10, $texto, $aFont, 'T', 'C', 0, '', false);
622
        $x1 += $x2 - 22;
623
        if ($this->orientacao == 'P') {
624
            $x3 = $x2 + 10.5;
625
        } else {
626
            $x3 = $x2 + 3;
627
        }
628
        $this->pdf->textBox($x1, $y, $x3, 12);
629
        $texto = 'Data e Hora de Emissão';
630
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
631
        $this->pdf->textBox($x1, $y, $x3, 8, $texto, $aFont, 'T', 'C', 0, '', false);
632
        $data = explode('T', $this->dhEmi);
633
        $texto = $this->ymdTodmy($data[0]) . ' - ' . $data[1];
634
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
635
        $this->pdf->textBox($x1, $y + 4, $x3, 10, $texto, $aFont, 'T', 'C', 0, '', false);
636
        $x1 += $x3;
637
638
        $this->pdf->textBox($x1, $y, $x2 - 15, 12);
639
        $texto = 'UF Carreg.';
640
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
641
        $this->pdf->textBox($x1, $y, $x2 - 15, 8, $texto, $aFont, 'T', 'C', 0, '', false);
642
        $texto = $this->UFIni;
643
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
644
        $this->pdf->textBox($x1, $y + 4, $x2 - 15, 10, $texto, $aFont, 'T', 'C', 0, '', false);
645
        $maxW = $this->wPrint;
0 ignored issues
show
Unused Code introduced by
$maxW 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...
646
647
        $x1 += $x2 - 15;
648
        $this->pdf->textBox($x1, $y, $x2 - 16, 12);
649
        $texto = 'UF Descar.';
650
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
651
        $this->pdf->textBox($x1, $y, $x2 - 16, 8, $texto, $aFont, 'T', 'C', 0, '', false);
652
        $texto = $this->UFFim;
653
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
654
        $this->pdf->textBox($x1, $y + 4, $x2 - 16, 10, $texto, $aFont, 'T', 'C', 0, '', false);
655
        $maxW = $this->wPrint;
656
657
        if ($this->aquav) {
658
            $x1 = $x;
659
            $x2 = $maxW;
660
            $y += 14;
661
            $this->pdf->textBox($x1, $y, $x2, 10);
662
            $texto = 'Embarcação';
663
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
664
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
665
            $texto = $this->aquav->getElementsByTagName('cEmbar')->item(0)->nodeValue;
666
            $texto .= ' - ';
667
            $texto .= $this->aquav->getElementsByTagName('xEmbar')->item(0)->nodeValue;
668
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
669
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'L', 0, '', false);
670
        }
671
672
        $x1 = $x;
673
        $x2 = $maxW;
674
        $y += 13;
675
        $this->pdf->textBox($x1, $y, $x2, 43);
676
        if ($this->rodo) {
677
            $texto = 'Modal Rodoviário de Carga';
678
        }
679
        if ($this->aereo) {
680
            $texto = 'Modal Aéreo de Carga';
681
        }
682
        if ($this->aquav) {
683
            $texto = 'Modal Aquaviário de Carga';
684
        }
685
        if ($this->ferrov) {
686
            $texto = 'Modal Ferroviário de Carga';
687
        }
688
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
689
        $this->pdf->textBox($x1, $y + 1, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
690
        $texto = 'CONTROLE DO FISCO';
691
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
692
        $this->pdf->textBox($x1 + ($x2 / 2), $y + 1, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
693
694
        $x1 = $x;
695
        $x2 = ($maxW / 6);
696
        $y += 6;
697
        $this->pdf->textBox($x1, $y, $x2, 12);
698
        $texto = 'Qtd. CT-e';
699
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
700
        $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
701
        $texto = str_pad($this->qCTe, 3, '0', STR_PAD_LEFT);
702
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
703
        $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
704
        $x1 += $x2;
705
        $this->pdf->textBox($x1, $y, $x2, 12);
706
        $texto = 'Qtd. NF-e';
707
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
708
        $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
709
        $texto = str_pad($this->qNFe, 3, '0', STR_PAD_LEFT);
710
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
711
        $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
712
        $x1 += $x2;
713
        $this->pdf->textBox($x1, $y, $x2, 12);
714
715
        if ($this->rodo ||
716
            $this->aereo ||
717
            $this->ferrov) {
718
            $texto = 'Peso Total (Kg)';
719
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
720
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
721
            $texto = number_format($this->qCarga, 4, ',', '.');
722
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
723
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
724
        }
725
726
        if ($this->aquav) {
727
            $texto = 'Qtd. MDF-e Ref.';
728
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
729
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
730
            $texto = str_pad($this->qMDFe, 3, '0', STR_PAD_LEFT);
731
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
732
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
733
734
            $ya = $y + 12;
735
            $this->pdf->textBox($x, $ya, $maxW / 2, 12);
736
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
737
            $texto = 'Peso Total (Kg)';
738
            $this->pdf->textBox($x, $ya, $maxW / 2, 8, $texto, $aFont, 'T', 'L', 0, '');
739
            $texto = number_format($this->qCarga, 4, ',', '.');
740
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
741
            $this->pdf->textBox($x, $ya + 4, $x2, 10, $texto, $aFont, 'T', 'L', 0, '', false);
742
        }
743
744
        // codigo de barras da chave
745
        $x1 += $x2;
746
        //$y = $y + 8;
747
        $this->pdf->textBox($x1, $y, $maxW / 2, 20);
748
        $bH = 16;
749
        $w = $maxW;
0 ignored issues
show
Unused Code introduced by
$w is not used, you could remove the assignment.

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

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

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

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

Loading history...
750
        $this->pdf->setFillColor(0, 0, 0);
751
        $this->pdf->code128($x1 + 5, $y + 2, $this->chMDFe, ($maxW / 2) - 10, $bH);
752
        $this->pdf->setFillColor(255, 255, 255);
753
754
        // protocolo de autorização
755
        $y = $y + 24;
756
        $this->pdf->textBox($x, $y, $maxW / 2, 13);
757
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
758
        $texto = 'Protocolo de Autorização';
759
        $this->pdf->textBox($x, $y, $maxW / 2, 8, $texto, $aFont, 'T', 'L', 0, '');
760
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
761
        if (is_object($this->mdfeProc)) {
762
            $tsHora = $this->convertTime($this->dhRecbto);
763
            $texto = $this->nProt . ' - ' . date('d/m/Y   H:i:s', $tsHora);
764
        } else {
765
            $texto = 'DAMDFE impresso em contingência - ' . date('d/m/Y   H:i:s');
766
        }
767
        $this->pdf->textBox($x, $y + 4, $maxW / 2, 8, $texto, $aFont, 'T', 'C', 0, '');
768
769
        $y -= 4;
770
771
        // chave de acesso
772
        $this->pdf->textBox($x + $maxW / 2, $y, $maxW / 2, 17);
773
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
774
        $tsHora = $this->convertTime($this->dhEvento);
0 ignored issues
show
Unused Code introduced by
$tsHora 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...
775
        $texto = 'Chave de Acesso';
776
        $this->pdf->textBox($x + $maxW / 2, $y, $maxW / 2, 6, $texto, $aFont, 'T', 'L', 0, '');
777
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
778
        $texto = $this->formatField($this->chMDFe, $this->formatoChave);
779
        $this->pdf->textBox($x + $maxW / 2, $y + 4, $maxW / 2, 6, $texto, $aFont, 'T', 'C', 0, '');
780
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
781
        $texto = 'Consulte em https://dfe-portal.sefazvirtual.rs.gov.br/MDFe/consulta';
782
        $this->pdf->textBox($x + $maxW / 2, $y + 10, $maxW / 2, 6, $texto, $aFont, 'T', 'C', 0, '');
783
784
        $x1 = $x;
785
        $y += 20;
786
        $yold = $y;
787
        $x2 = round($maxW / 2, 0);
788
789
        if ($this->rodo) {
790
            $texto = 'Veículo';
791
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
792
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
793
            $y += 5;
794
            $x2 = round($maxW / 4, 0);
795
            $tamanho = 22;
796
            $this->pdf->textBox($x1, $y, $x2, $tamanho);
797
            $texto = 'Placa';
798
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
799
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
800
            $texto = $this->veicTracao->getElementsByTagName("placa")->item(0)->nodeValue;
801
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
802
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
803
            $altura = $y + 4;
804
            /** @var \DOMNodeList $veicReboque */
805
            $veicReboque = $this->veicReboque;
806
            foreach ($veicReboque as $item) {
807
                /** @var \DOMElement $item */
808
                $altura += 4;
809
                $texto = $item->getElementsByTagName('placa')->item(0)->nodeValue;
810
                $this->pdf->textBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
811
            }
812
            $x1 += $x2;
813
            $this->pdf->textBox($x1, $y, $x2, $tamanho);
814
            $texto = 'RNTRC';
815
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
816
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
817
            // RNTRC Não informado
818
            if ($this->rodo->getElementsByTagName("RNTRC")->length > 0) {
819
                $texto = $this->rodo->getElementsByTagName("RNTRC")->item(0)->nodeValue;
820
            } else {
821
                $texto = "";
822
            }
823
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
824
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
825
            $altura = $y + 4;
826
            /** @var \DOMNodeList $veicReboque */
827
            $veicReboque = $this->veicReboque;
828
            foreach ($veicReboque as $item) {
829
                /** @var \DOMElement $item */
830
                $DOMNodeList = $item->getElementsByTagName('RNTRC');
831
                if ($DOMNodeList->length > 0) {
832
                    $altura += 4;
833
                    $texto = $DOMNodeList->item(0)->nodeValue;
834
                    $this->pdf->textBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
835
                }
836
            }
837
            $x1 = $x;
838
            $y += 22;
839
            $x2 = round($maxW / 2, 0);
840
            $valesPedagios = 1;
841
            $temVales = false;
842
            if ($this->valePed != "" && $this->valePed->length > 0) {
843
                $valesPedagios = $this->valePed->length;
844
                $temVales = true;
845
            }
846
            $tamanho = ($valesPedagios * 7.5);
847
            if (!$temVales) {
848
                $valesPedagios = 0;
849
            }
850
            $this->pdf->textBox($x1, $y, $x2, 11 + $tamanho / 2);
851
            $texto = 'Vale Pedágio';
852
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
853
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
854
            $y += 5;
855
            $x2 = ($x2 / 3);
856
            $this->pdf->textBox($x1, $y, $x2 - 3, 6 + ($tamanho / 2));
857
            $texto = 'Responsável CNPJ';
858
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
859
            $this->pdf->textBox($x1, $y, $x2 - 4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
860
            $altura = $y;
861
            for ($i = 0; $i < $valesPedagios; $i++) {
862
                $altura += 4;
863
                $texto = $this->valePed->item($i)->getElementsByTagName('CNPJForn')->item(0)->nodeValue;
864
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
865
                $this->pdf->textBox($x1 + 1, $altura, $x2 - 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
866
            }
867
            $x1 += $x2 - 3;
868
            $this->pdf->textBox($x1, $y, $x2 - 3, 6 + ($tamanho / 2));
869
            $texto = 'Fornecedora CNPJ';
870
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
871
            $this->pdf->textBox($x1, $y, $x2 - 4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
872
            $altura = $y;
873
            for ($i = 0; $i < $valesPedagios; $i++) {
874
                $altura += 4;
875
                $texto = $this->valePed->item($i)->getElementsByTagName('CNPJPg')->item(0)->nodeValue;
876
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
877
                $this->pdf->textBox($x1 + 1, $altura, $x2 - 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
878
            }
879
            $x1 += $x2 - 3;
880
            $this->pdf->textBox($x1, $y, $x2 + 6, 6 + ($tamanho / 2));
881
            $texto = 'Nº Comprovante';
882
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
883
            $this->pdf->textBox($x1, $y, $x2 + 6, 8, $texto, $aFont, 'T', 'L', 0, '', false);
884
            $altura = $y;
885
            for ($i = 0; $i < $valesPedagios; $i++) {
886
                $altura += 4;
887
                $texto = $this->valePed->item($i)->getElementsByTagName('nCompra')->item(0)->nodeValue;
888
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
889
                $this->pdf->textBox($x1 + 1, $altura, $x2 + 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
890
            }
891
            if (!$temVales) {
892
                $altura += 4;
893
            }
894
            $this->condutor = $this->veicTracao->getElementsByTagName('condutor');
0 ignored issues
show
Bug introduced by
The property condutor 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...
895
            $x1 = round($maxW / 2, 0) + 7;
896
            $y = $yold;
897
            $x2 = round($maxW / 2, 0);
898
            $texto = 'Condutor';
899
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
900
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
901
            $y += 5;
902
            $x2 = ($maxW / 6);
903
            $this->pdf->textBox($x1, $y, $x2, 33 + ($tamanho / 2));
904
            $texto = 'CPF';
905
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
906
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
907
            $yold = $y;
908
            for ($i = 0; $i < $this->condutor->length; $i++) {
909
                $y += 4;
910
                $texto = $this->condutor->item($i)->getElementsByTagName('CPF')->item(0)->nodeValue;
911
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
912
                $this->pdf->textBox($x1 + 1, $y, $x2 - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
913
            }
914
            $y = $yold;
915
            $x1 += $x2;
916
            $x2 = $x2 * 2;
917
            $this->pdf->textBox($x1, $y, $x2, 33 + ($tamanho / 2));
918
            $texto = 'Nome';
919
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
920
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
921
            for ($i = 0; $i < $this->condutor->length; $i++) {
922
                $y += 4;
923
                $texto = $this->condutor->item($i)->getElementsByTagName('xNome')->item(0)->nodeValue;
924
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
925
                $this->pdf->textBox($x1 + 1, $y, $x2 - 1, 8, $texto, $aFont, 'T', 'L', 0, '', false);
926
            }
927
        }
928
929
        if ($this->aereo) {
930
            $altura = $y + 4;
931
        }
932
933
        if ($this->aquav) {
934
            $x1 = $x;
935
            $x2 = $maxW;
936
937
            $initial = $y;
938
            $initialA = $y + 2;
939
            $initialB = $y + 2;
940
941
            $texto = 'Carregamento';
942
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
943
            $this->pdf->textBox($x, $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
944
            foreach ($this->aquav->getElementsByTagName('infTermCarreg') as $item) {
945
                $initialA += 4.5;
946
947
                $texto = $item->getElementsByTagName('cTermCarreg')->item(0)->nodeValue;
948
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
949
                $this->pdf->textBox($x1 + 1, $initialA, ($x2 / 2) - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
950
951
                $texto = $item->getElementsByTagName('xTermCarreg')->item(0)->nodeValue;
952
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
953
                $this->pdf->textBox($x1 + 25, $initialA, ($x2 / 2) - 25, 10, $texto, $aFont, 'T', 'L', 0, '', false);
954
955
                if (strlen($texto) > 50) {
956
                    $initialA += 2;
957
                }
958
            }
959
            if ($this->aquav->getElementsByTagName('infTermCarreg')->item(0) != null) {
960
                $this->pdf->textBox($x1, $initial + 6, ($x2 / 2), $initialA - $y);
961
            }
962
963
            $texto = 'Descarregamento';
964
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
965
            $this->pdf->textBox($x1 + ($x2 / 2), $initial + 2, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
966
            foreach ($this->aquav->getElementsByTagName('infTermDescarreg') as $item) {
967
                $initialB += 4.5;
968
969
                $texto = $item->getElementsByTagName('cTermDescarreg')->item(0)->nodeValue;
970
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
971
                $this->pdf->textBox(
972
                    ($x1 + ($x2 / 2)) + 1,
973
                    $initialB,
974
                    ($x2 / 2) - 1,
975
                    10,
976
                    $texto,
977
                    $aFont,
978
                    'T',
979
                    'L',
980
                    0,
981
                    '',
982
                    false
983
                );
984
985
                $texto = $item->getElementsByTagName('xTermDescarreg')->item(0)->nodeValue;
986
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
987
988
                $this->pdf->textBox(
989
                    ($x1 + ($x2 / 2)) + 25,
990
                    $initialB,
991
                    ($x2 / 2) - 25,
992
                    10,
993
                    $texto,
994
                    $aFont,
995
                    'T',
996
                    'L',
997
                    0,
998
                    '',
999
                    false
1000
                );
1001
1002
                if (strlen($texto) > 50) {
1003
                    $initialB += 2;
1004
                }
1005
            }
1006
            if ($this->aquav->getElementsByTagName('infTermDescarreg')->item(0) != null) {
1007
                $this->pdf->textBox(($x1 + ($x2 / 2)), $initial + 6, ($x2 / 2), $initialB - $y);
1008
            }
1009
1010
            $altura = $initialA > $initialB ? $initialA : $initialB;
1011
            $altura += 6;
1012
1013
            $y = $altura + 3;
1014
1015
            $initial = $y;
1016
            $initialA = $y + 2;
1017
            $initialB = $y + 2;
1018
1019
            $texto = 'Unidade de Transporte';
1020
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1021
            $this->pdf->textBox($x, $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
1022
1023
            $texto = 'Unidade de Carga';
1024
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1025
            $this->pdf->textBox($x1 + ($x2 / 4), $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
1026
1027
            foreach ($this->aquav->getElementsByTagName('infUnidCargaVazia') as $item) {
1028
                $initialA += 4.5;
1029
1030
                $texto = $item->getElementsByTagName('idUnidCargaVazia')->item(0)->nodeValue;
1031
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1032
                $this->pdf->textBox($x1 + 1, $initialA, ($x2 / 2) - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
1033
1034
                $texto = $item->getElementsByTagName('tpUnidCargaVazia')->item(0)->nodeValue;
1035
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1036
                $this->pdf->textBox($x1 + ($x2 / 4), $initialA, ($x2 / 2) - 25, 10, $texto, $aFont, 'T', 'L', 0, '', false);
1037
1038
                if (strlen($texto) > 50) {
1039
                    $initialA += 2;
1040
                }
1041
            }
1042
            if ($this->aquav->getElementsByTagName('infUnidCargaVazia')->item(0) != null) {
1043
                $this->pdf->textBox($x1, $initial + 6, ($x2 / 2), $initialA - $y);
1044
            }
1045
1046
            $texto = 'Unidade de Transporte';
1047
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1048
            $this->pdf->textBox($x1 + ($x2 / 2), $initial + 2, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
1049
1050
            $texto = 'Unidade de Carga';
1051
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1052
            $this->pdf->textBox($x1 + ($x2 / 1.33), $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
1053
1054
            foreach ($this->aquav->getElementsByTagName('infUnidTranspVazia') as $item) {
1055
                $initialB += 4.5;
1056
1057
                $texto = $item->getElementsByTagName('idUnidTranspVazia')->item(0)->nodeValue;
1058
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1059
1060
                $this->pdf->textBox(
1061
                    ($x1 + ($x2 / 2)) + 1,
1062
                    $initialB,
1063
                    ($x2 / 2) - 1,
1064
                    10,
1065
                    $texto,
1066
                    $aFont,
1067
                    'T',
1068
                    'L',
1069
                    0,
1070
                    '',
1071
                    false
1072
                );
1073
1074
                $texto = $item->getElementsByTagName('tpUnidTranspVazia')->item(0)->nodeValue;
1075
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1076
                $this->pdf->textBox(
1077
                    ($x1 + ($x2 / 1.33)),
1078
                    $initialB,
1079
                    ($x2 / 2) - 25,
1080
                    10,
1081
                    $texto,
1082
                    $aFont,
1083
                    'T',
1084
                    'L',
1085
                    0,
1086
                    '',
1087
                    false
1088
                );
1089
1090
                if (strlen($texto) > 50) {
1091
                    $initialB += 2;
1092
                }
1093
            }
1094
            if ($this->aquav->getElementsByTagName('infUnidTranspVazia')->item(0) != null) {
1095
                $this->pdf->textBox(($x1 + ($x2 / 2)), $initial + 6, ($x2 / 2), $initialB - $y);
1096
            }
1097
1098
            $altura = $initialA > $initialB ? $initialA : $initialB;
1099
            $altura += 6;
1100
        }
1101
1102
        if ($this->ferrov) {
1103
            $altura = $y + 4;
1104
        }
1105
1106
        return $altura + 10;
0 ignored issues
show
Bug introduced by
The variable $altura 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...
1107
    }
1108
1109
1110
    protected function qrCodeDamdfe($y = 0)
1111
    {
1112
        $margemInterna = $this->margemInterna;
1113
        $barcode = new Barcode();
1114
        $bobj = $barcode->getBarcodeObj(
1115
            'QRCODE,M',
1116
            $this->qrCodMDFe,
1117
            -4,
1118
            -4,
1119
            'black',
1120
            array(-2, -2, -2, -2)
1121
        )->setBackgroundColor('white');
1122
        $qrcode = $bobj->getPngData();
1123
        $wQr = 35;
1124
        $hQr = 35;
1125
        $yQr = ($y + $margemInterna);
1126
        if ($this->orientacao == 'P') {
1127
            $xQr = 160;
1128
        } else {
1129
            $xQr = 235;
1130
        }
1131
        // prepare a base64 encoded "data url"
1132
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
1133
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
1134
    }
1135
1136
1137
    /**
1138
     * footerMDFe
1139
     *
1140
     * @param float $x
1141
     * @param float $y
1142
     */
1143
    private function footerMDFe($x, $y)
1144
    {
1145
        $maxW = $this->wPrint;
1146
        $x2 = $maxW;
1147
        $this->pdf->textBox($x, $y, $x2, 30);
1148
        $texto = 'Observação
1149
        ' . $this->infCpl;
1150
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1151
        $this->pdf->textBox($x, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
1152
        $y = $this->hPrint - 4;
1153
        $texto = "Impresso em  " . date('d/m/Y   H:i:s');
1154
        $w = $this->wPrint - 4;
1155
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
1156
        $this->pdf->textBox($x, $y, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
1157
    }//fim footerCCe
1158
1159
    /**
1160
     * printMDFe
1161
     *
1162
     * @param string $nome
1163
     * @param string $destino
1164
     * @param string $printer
1165
     * @return string
1166
     */
1167
    public function printMDFe($nome = '', $destino = 'I', $printer = '')
1168
    {
1169
        //monta
1170
        $command = '';
1171
        if ($nome == '') {
1172
            $file = $this->pdfDir . 'mdfe.pdf';
1173
        } else {
1174
            $file = $this->pdfDir . $nome;
1175
        }
1176
        if ($destino != 'I' && $destino != 'S' && $destino != 'F') {
1177
            $destino = 'I';
1178
        }
1179
        if ($printer != '') {
1180
            $command = "-P $printer";
1181
        }
1182
1183
        $this->buildMDFe();
1184
        $arq = $this->pdf->output($file, $destino);
1185
        if ($destino == 'S' && $command != '') {
1186
            //aqui pode entrar a rotina de impressão direta
1187
            $command = "lpr $command $file";
1188
            system($command, $retorno);
1189
        }
1190
1191
        return $arq;
1192
    }
1193
1194
    /**
1195
     * Dados brutos do PDF
1196
     * @return string
1197
     */
1198
    public function render()
1199
    {
1200
        return $this->pdf->getPdf();
1201
    }
1202
}
1203