Passed
Push — master ( 311a32...c4fd71 )
by
unknown
01:06 queued 12s
created

Damdfe::headerMDFeRetrato()   F

Complexity

Conditions 15
Paths 864

Size

Total Lines 158

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
cc 15
nc 864
nop 3
dl 0
loc 158
ccs 0
cts 146
cp 0
crap 240
rs 1.5511
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\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
    protected $logoAlign = 'L'; //alinhamento do logo
26
    protected $yDados = 0;
27
    protected $debugmode = false; //ativa ou desativa o modo de debug
28
    protected $pdf; // objeto fpdf()
29
    protected $xml; // string XML NFe
30
    protected $logomarca = ''; // path para logomarca em jpg
31
    protected $errMsg = ''; // mesagens de erro
32
    protected $errStatus = false;// status de erro TRUE um erro ocorreu false sem erros
33
    protected $orientacao = 'P'; //orientação da DANFE P-Retrato ou L-Paisagem
34
    protected $papel = 'A4'; //formato do papel
35
    protected $fontePadrao = 'Times'; //Nome da Fonte para gerar o DANFE
36
    protected $wPrint; //largura imprimivel
37
    protected $hPrint; //comprimento imprimivel
38
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
39
    protected $margemInterna = 2;
40
    protected $id;
41
    protected $chMDFe;
42
    protected $tpAmb;
43
    protected $cOrgao;
44
    protected $xCondUso;
45
    protected $dhEvento;
46
    protected $cStat;
47
    protected $xMotivo;
48
    protected $CNPJDest = '';
49
    protected $dhRegEvento;
50
    protected $nProt;
51
    protected $tpEmis;
52
    protected $qrCodMDFe;
53
    private $dom;
54
    private $creditos;
55
56
    /**
57
     * __construct
58
     *
59
     * @param string $xml Arquivo XML da MDFe
60
     */
61
    public function __construct(
62
        $xml = ''
63
    ) {
64
        $this->debugMode();
65
        $this->loadDoc($xml);
66
    }
67
68
    /**
69
     * Ativa ou desativa o modo debug
70
     *
71
     * @param  bool $activate
72
     * @return bool
73
     */
74
    public function debugMode($activate = null)
75
    {
76
        if (isset($activate) && is_bool($activate)) {
77
            $this->debugmode = $activate;
78
        }
79
        if ($this->debugmode) {
80
            error_reporting(E_ALL);
81
            ini_set('display_errors', 'On');
82
        } else {
83
            error_reporting(0);
84
            ini_set('display_errors', 'Off');
85
        }
86
        return $this->debugmode;
87
    }
88
89
    private function loadDoc($xml)
90
    {
91
        $this->xml = $xml;
92
        if (!empty($xml)) {
93
            $this->dom = new Dom();
94
            $this->dom->loadXML($this->xml);
95
            $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...
96
            if (empty($this->dom->getElementsByTagName("infMDFe")->item(0))) {
97
                throw new \Exception('Isso não é um MDF-e.');
98
            }
99
            $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...
100
            $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...
101
            if ($this->getTagValue($this->ide, "mod") != '58') {
102
                throw new \Exception("O xml deve ser MDF-e modelo 58.");
103
            }
104
            $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...
105
            if ($this->emit->getElementsByTagName("CPF")->item(0)) {
106
                $this->CPF = $this->emit->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...
107
            } else {
108
                $this->CNPJ = $this->emit->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...
109
            }
110
            $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...
111
            $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...
112
            $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...
113
            $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...
114
            $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...
115
            $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...
116
            $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...
117
            $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...
118
            $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...
119
            $this->tpAmb = $this->dom->getElementsByTagName("tpAmb")->item(0)->nodeValue;
120
            $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...
121
            $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...
122
            $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...
123
            $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...
124
            $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...
125
            $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...
126
            $this->tpEmis = $this->dom->getElementsByTagName("tpEmis")->item(0)->nodeValue;
127
            $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...
128
            $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...
129
            if ($this->dom->getElementsByTagName("qMDFe")->item(0) != "") {
130
                $this->qMDFe = $this->dom->getElementsByTagName("qMDFe")->item(0)->nodeValue;
131
            }
132
            $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...
133
            if ($this->dom->getElementsByTagName("qNFe")->item(0) != "") {
134
                $this->qNFe = $this->dom->getElementsByTagName("qNFe")->item(0)->nodeValue;
135
            }
136
            $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...
137
            if ($this->dom->getElementsByTagName("qNF")->item(0) != "") {
138
                $this->qNF = $this->dom->getElementsByTagName("qNF")->item(0)->nodeValue;
139
            }
140
            $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...
141
            if ($this->dom->getElementsByTagName("qCTe")->item(0) != "") {
142
                $this->qCTe = $this->dom->getElementsByTagName("qCTe")->item(0)->nodeValue;
143
            }
144
            $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...
145
            if ($this->dom->getElementsByTagName("qCT")->item(0) != "") {
146
                $this->qCT = $this->dom->getElementsByTagName("qCT")->item(0)->nodeValue;
147
            }
148
            $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...
149
            $this->cUnid = $this->dom->getElementsByTagName("cUnid")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property cUnid 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->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...
151
            $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...
152
            $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...
153
            $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...
154
            $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...
155
            $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...
156
            if ($this->dom->getElementsByTagName('CIOT')->item(0) != "") {
157
                $this->ciot = $this->dom->getElementsByTagName('CIOT')->item(0)->nodeValue;
158
            }
159
            $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...
160
            $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...
161
            $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...
162
            if ($this->dom->getElementsByTagName("valePed")->item(0) != "") {
163
                $this->valePed = $this->dom->getElementsByTagName("valePed")->item(0)->getElementsByTagName("disp");
164
            }
165
            $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...
166
            $this->chMDFe = str_replace(
167
                'MDFe',
168
                '',
169
                $this->infMDFe->getAttribute("Id")
170
            );
171
            $this->qrCodMDFe = $this->dom->getElementsByTagName('qrCodMDFe')->item(0) ?
172
                $this->dom->getElementsByTagName('qrCodMDFe')->item(0)->nodeValue : 'SEM INFORMAÇÃO DE QRCODE';
173
            if (is_object($this->mdfeProc)) {
174
                $this->nProt = !empty($this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
175
                    $this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
176
                $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...
177
            }
178
        }
179
    }
180
181
    /**
182
     * buildMDFe
183
     */
184
    public function buildMDFe()
185
    {
186
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
187
        if ($this->orientacao == 'P') {
188
            // margens do PDF
189
            $margSup = 7;
190
            $margEsq = 7;
191
            $margDir = 7;
192
            // posição inicial do relatorio
193
            $xInic = 7;
194
            $yInic = 7;
195
            if ($this->papel == 'A4') { //A4 210x297mm
196
                $maxW = 210;
197
                $maxH = 297;
198
            }
199
        } else {
200
            // margens do PDF
201
            $margSup = 7;
202
            $margEsq = 7;
203
            $margDir = 7;
204
            // posição inicial do relatorio
205
            $xInic = 7;
206
            $yInic = 7;
207
            if ($this->papel == 'A4') { //A4 210x297mm
208
                $maxH = 210;
209
                $maxW = 297;
210
            }
211
        }//orientação
212
        //largura imprimivel em mm
213
        $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...
214
        //comprimento imprimivel em mm
215
        $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...
216
        // estabelece contagem de paginas
217
        $this->pdf->aliasNbPages();
218
        // fixa as margens
219
        $this->pdf->setMargins($margEsq, $margSup, $margDir);
220
        $this->pdf->setDrawColor(0, 0, 0);
221
        $this->pdf->setFillColor(255, 255, 255);
222
        // inicia o documento
223
        $this->pdf->open();
224
        // adiciona a primeira página
225
        $this->pdf->addPage($this->orientacao, $this->papel);
226
        $this->pdf->setLineWidth(0.1);
227
        $this->pdf->setTextColor(0, 0, 0);
228
        //montagem da página
229
        $pag = 1;
230
        $x = $xInic;
231
        $y = $yInic;
232
        //coloca o cabeçalho Paisagem
233
        if ($this->orientacao == 'P') {
234
            $y = $this->headerMDFeRetrato($x, $y, $pag);
235
        } else {
236
            $y = $this->headerMDFePaisagem($x, $y, $pag);
237
        }
238
        //coloca os dados da MDFe
239
        $y = $this->bodyMDFe($x, $y);
240
        //coloca os dados da MDFe
241
        $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...
242
    }
243
244
    /**
245
     * headerMDFePaisagem
246
     *
247
     * @param  float   $x
248
     * @param  float   $y
249
     * @param  integer $pag
250
     * @return string
251
     */
252
    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...
253
    {
254
        $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...
255
        $oldY = $y;
256
        $maxW = $this->wPrint;
257
        //####################################################################################
258
        //coluna esquerda identificação do emitente
259
        //$w = $maxW; //round($maxW*0.41, 0);// 80;
260
        $w = round($maxW * 0.70, 0);
261
        $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...
262
        $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...
263
        $h = 30;
264
        $oldY += $h;
265
        $this->pdf->textBox($x, $y, $w, $h);
266
        if (is_file($this->logomarca)) {
267
            $logoInfo = getimagesize($this->logomarca);
268
            //largura da imagem em mm
269
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
270
            //altura da imagem em mm
271
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
272
            if ($this->logoAlign == 'L') {
273
                $nImgW = round($w / 3, 0);
274
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
275
                $xImg = $x + 1;
276
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
277
                //estabelecer posições do texto
278
                $x1 = round($xImg + $nImgW + 1, 0);
279
                $y1 = round($y + 2, 0);
280
                $tw = round(2 * $w / 3, 0);
281
            }
282
            if ($this->logoAlign == 'C') {
283
                $nImgH = round($h / 3, 0);
284
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
285
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
286
                $yImg = $y + 3;
287
                $x1 = $x;
288
                $y1 = round($yImg + $nImgH + 1, 0);
289
                $tw = $w;
290
            }
291
            if ($this->logoAlign == 'R') {
292
                $nImgW = round($w / 3, 0);
293
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
294
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
295
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
296
                $x1 = $x;
297
                $y1 = round($h / 3 + $y, 0);
298
                $tw = round(2 * $w / 3, 0);
299
            }
300
            $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...
301
        } else {
302
            $x1 = $x;
303
            $y1 = round($h / 3 + $y, 0);
304
            $tw = $w;
305
        }
306
        $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...
307
        $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...
308
        if (isset($this->CPF)) {
309
            $cpfcnpj = 'CPF: ' . $this->formatField($this->CPF, "###.###.###-##");
310
        } else {
311
            $cpfcnpj = 'CNPJ: ' . $this->formatField($this->CNPJ, "###.###.###/####-##");
312
        }
313
        $ie = 'IE: ' . $this->formatField($this->IE, '##/########');
314
        $lgr = 'Logradouro: ' . $this->xLgr;
315
        $nro = 'Nº: ' . $this->nro;
316
        $bairro = 'Bairro: ' . $this->xBairro;
317
        $CEP = $this->CEP;
318
        $CEP = 'CEP: ' . $this->formatField($CEP, "##.###-###");
319
        $UF = 'UF: ' . $this->UF;
320
        $mun = 'Municipio: ' . $this->xMun;
321
322
        $texto = $cpfcnpj . ' - ' . $ie . "\n";
323
        $texto .= $lgr . ' - ' . $nro . "\n";
324
        $texto .= $bairro . "\n";
325
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
326
        $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
327
        $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...
328
        //##################################################
329
        $w = round($maxW * 0.70, 0);
330
        $y = $h + 9;
331
        $this->pdf->textBox($x, $y, $w, 6);
332
        $aFont = ['font' => $this->fontePadrao, 'size' => 12, 'style' => 'I'];
333
        $this->pdf->textBox(
334
            $x,
335
            $y,
336
            $w,
337
            8,
338
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
339
            $aFont,
340
            'T',
341
            'C',
342
            0,
343
            ''
344
        );
345
346
        if ($this->tpAmb != 1) {
347
            $x = 10;
348
            if ($this->orientacao == 'P') {
349
                $yy = round($this->hPrint * 2 / 3, 0);
350
            } else {
351
                $yy = round($this->hPrint / 2, 0);
352
            }
353
            $h = 5;
354
            $w = $maxW - (2 * $x);
355
            $this->pdf->setTextColor(90, 90, 90);
356
            $texto = "SEM VALOR FISCAL";
357
            $aFont = ['font' => $this->fontePadrao, 'size' => 48, 'style' => 'B'];
358
            $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
359
            $aFont = ['font' => $this->fontePadrao, 'size' => 30, 'style' => 'B'];
360
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
361
            $this->pdf->textBox($x, $yy + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
362
            $this->pdf->setTextColor(0, 0, 0);
363
        } else {
364
            $x = 10;
365
            if ($this->orientacao == 'P') {
366
                $yy = round($this->hPrint * 2 / 3, 0);
367
            } else {
368
                $yy = round($this->hPrint / 2, 0);
369
            }
370
            $h = 5;
371
            $w = $maxW - (2 * $x);
372
            $this->pdf->setTextColor(90, 90, 90);
373
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
374
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
375
                //Contingência
376
                $texto = "DAMDFE Emitido em Contingência";
377
                $aFont = ['font' => $this->fontePadrao, 'size' => 48, 'style' => 'B'];
378
                $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
379
                $aFont = ['font' => $this->fontePadrao, 'size' => 30, 'style' => 'B'];
380
                $texto = "devido à problemas técnicos";
381
                $this->pdf->textBox($x, $yy + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
382
            }
383
            $this->pdf->setTextColor(0, 0, 0);
384
        }
385
        return $y + 8;
386
    }
387
388
    /**
389
     * headerMDFeRetrato
390
     *
391
     * @param  float   $x
392
     * @param  float   $y
393
     * @param  integer $pag
394
     * @return string
395
     */
396
    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...
397
    {
398
        $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...
399
        $oldY = $y;
400
        $maxW = $this->wPrint;
401
        //####################################################################################
402
        //coluna esquerda identificação do emitente
403
        //$w = $maxW; //round($maxW*0.41, 0);// 80;
404
        $w = round($maxW * 0.70, 0);
405
        $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...
406
        $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...
407
        $h = 20;
408
        $oldY += $h;
409
        $this->pdf->textBox($x, $y, $w, $h);
410
        if (is_file($this->logomarca)) {
411
            $logoInfo = getimagesize($this->logomarca);
412
            //largura da imagem em mm
413
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
414
            //altura da imagem em mm
415
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
416
            if ($this->logoAlign == 'L') {
417
                // ajusta a dimensão do logo
418
                $nImgW = round((round($maxW * 0.50, 0)) / 3, 0);
419
                $nImgH = round(($h - $y) - 2, 0) + $y;
420
                $xImg = $x + 1;
421
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
422
                //estabelecer posições do texto
423
                $x1 = round($xImg + $nImgW + 4, 0);
424
                $y1 = round($y + 2, 0);
425
                $tw = round(2 * $w / 3, 0);
426
            }
427
            if ($this->logoAlign == 'C') {
428
                $nImgH = round($h / 3, 0);
429
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
430
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
431
                $yImg = $y + 3;
432
                $x1 = $x;
433
                $y1 = round($yImg + $nImgH + 1, 0);
434
                $tw = $w;
435
            }
436
            if ($this->logoAlign == 'R') {
437
                $nImgW = round($w / 3, 0);
438
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
439
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
440
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
441
                $x1 = $x;
442
                $y1 = round($h / 3 + $y, 0);
443
                $tw = round(2 * $w / 3, 0);
444
            }
445
            $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...
446
        } else {
447
            $x1 = $x;
448
            $y1 = $y;
449
            $tw = $w;
450
        }
451
452
        if ($this->qrCodMDFe !== null) {
453
            $this->qrCodeDamdfe($y - 3);
454
        }
455
456
        $aFont = ['font' => $this->fontePadrao, 'size' => 10, 'style' => 'B'];
457
        $texto = $this->xNome;
458
        $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...
459
        if (isset($this->CPF)) {
460
            $cpfcnpj = 'CPF: ' . $this->formatField($this->CPF, "###.###.###-##");
461
        } else {
462
            $cpfcnpj = 'CNPJ: ' . $this->formatField($this->CNPJ, "###.###.###/####-##");
463
        }
464
        $ie = 'IE: ' . $this->formatField($this->IE, '###/#######');
465
        $lgr = 'Logradouro: ' . $this->xLgr;
466
        $nro = 'Nº: ' . $this->nro;
467
        $bairro = 'Bairro: ' . $this->xBairro;
468
        $CEP = $this->CEP;
469
        $CEP = 'CEP: ' . $this->formatField($CEP, "##.###-###");
470
        $mun = 'Municipio: ' . $this->xMun;
471
        $UF = 'UF: ' . $this->UF;
472
        $texto = $cpfcnpj . ' - ' . $ie . "\n";
473
        $texto .= $lgr . ' - ' . $nro . "\n";
474
        $texto .= $bairro . "\n";
475
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
476
        $aFont = ['font' => $this->fontePadrao, 'size' => 8, 'style' => ''];
477
        $this->pdf->textBox($x1, $y1 + 4, $tw, 8, $texto, $aFont, 'T', 'L', 0, '');
478
        //##################################################
479
        $w = round($maxW * 0.70, 0);
480
        $y = $h + 9;
481
        $this->pdf->textBox($x, $y, $w, 6);
482
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'I');
483
        $this->pdf->textBox(
484
            $x,
485
            $y,
486
            $w,
487
            8,
488
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
489
            $aFont,
490
            'T',
491
            'C',
492
            0,
493
            ''
494
        );
495
        if ($this->tpAmb != 1) {
496
            $x = 10;
497
            if ($this->orientacao == 'P') {
498
                $yy = round($this->hPrint * 2 / 3, 0);
499
            } else {
500
                $yy = round($this->hPrint / 2, 0);
501
            }
502
            $h = 5;
503
            $w = $maxW - (2 * $x);
504
            $this->pdf->setTextColor(90, 90, 90);
505
            $texto = "SEM VALOR FISCAL";
506
            $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
507
            $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
508
            $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
509
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
510
            $this->pdf->textBox($x, $yy + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
511
            $this->pdf->setTextColor(0, 0, 0);
512
        } else {
513
            $x = 10;
514
            if ($this->orientacao == 'P') {
515
                $yy = round($this->hPrint * 2 / 3, 0);
516
            } else {
517
                $yy = round($this->hPrint / 2, 0);
518
            }
519
            $h = 5;
520
            $w = $maxW - (2 * $x);
521
            $this->pdf->setTextColor(90, 90, 90);
522
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
523
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
524
                //Contingência
525
                $texto = "DAMDFE Emitido em Contingência";
526
                $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
527
                $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
528
                $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
529
                $texto = "devido à problemas técnicos";
530
                $this->pdf->textBox($x, $yy + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
531
            }
532
            $this->pdf->setTextColor(0, 0, 0);
533
        }
534
        $cStat = $this->dom->getElementsByTagName("cStat");
535
        if ($cStat) {
536
            if ($cStat->item(0)->nodeValue == '101') {
537
                $x = 10;
538
                if ($this->orientacao == 'P') {
539
                    $yy = round($this->hPrint * 2 / 3, 0);
540
                } else {
541
                    $yy = round($this->hPrint / 2, 0);
542
                }
543
                $h = 5;
544
                $w = $maxW - (2 * $x);
545
                $this->pdf->setTextColor(90, 90, 90);
546
                $texto = "MDFe CANCELADO";
547
                $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
548
                $this->pdf->textBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
549
                $this->pdf->setTextColor(0, 0, 0);
550
            }
551
        }
552
        return $y + 8;
553
    }
554
555
    /**
556
     * bodyMDFe
557
     *
558
     * @param  float $x
559
     * @param  float $y
560
     * @return void
561
     */
562
    private function bodyMDFe($x, $y)
563
    {
564
        if ($this->orientacao == 'P') {
565
            $maxW = $this->wPrint;
566
        } else {
567
            //$maxW = $this->wPrint / 2;
568
            $maxW = $this->wPrint * 0.9;
569
        }
570
        $x2 = ($maxW / 6);
571
        $x1 = $x2;
572
        $this->pdf->textBox($x, $y, $x2 - 22, 12);
573
        $texto = 'Modelo';
574
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
575
        $this->pdf->textBox($x, $y, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
576
        $texto = $this->mod;
577
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
578
        $this->pdf->textBox($x, $y + 4, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
579
580
        if ($this->orientacao == 'P') {
581
            $x1 += $x2 - 47.5;
582
        } else {
583
            $x1 += $x2 - 57.5;
584
        }
585
        $this->pdf->textBox($x1, $y, $x2 - 22, 12);
586
        $texto = 'Série';
587
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
588
        $this->pdf->textBox($x1, $y, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
589
        $texto = $this->serie;
590
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
591
        $this->pdf->textBox($x1, $y + 4, $x2 - 22, 10, $texto, $aFont, 'T', 'C', 0, '', false);
592
593
        $x1 += $x2 - 22;
594
        $this->pdf->textBox($x1, $y, $x2 - 5, 12);
595
        $texto = 'Número';
596
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
597
        $this->pdf->textBox($x1, $y, $x2 - 5, 8, $texto, $aFont, 'T', 'C', 0, '', false);
598
        $texto = $this->formatField(str_pad($this->nMDF, 9, '0', STR_PAD_LEFT), '###.###.###');
599
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
600
        $this->pdf->textBox($x1, $y + 4, $x2 - 5, 10, $texto, $aFont, 'T', 'C', 0, '', false);
601
        $x1 += $x2 - 5;
602
        $this->pdf->textBox($x1, $y, $x2 - 22, 12);
603
        $texto = 'FL';
604
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
605
        $this->pdf->textBox($x1, $y, $x2 - 22, 8, $texto, $aFont, 'T', 'C', 0, '', false);
606
        $texto = '1';
607
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
608
        $this->pdf->textBox($x1, $y + 4, $x2 - 22, 10, $texto, $aFont, 'T', 'C', 0, '', false);
609
        $x1 += $x2 - 22;
610
        if ($this->orientacao == 'P') {
611
            $x3 = $x2 + 10.5;
612
        } else {
613
            $x3 = $x2 + 3;
614
        }
615
        $this->pdf->textBox($x1, $y, $x3, 12);
616
        $texto = 'Data e Hora de Emissão';
617
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
618
        $this->pdf->textBox($x1, $y, $x3, 8, $texto, $aFont, 'T', 'C', 0, '', false);
619
        $data = explode('T', $this->dhEmi);
620
        $texto = $this->ymdTodmy($data[0]) . ' - ' . $data[1];
621
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
622
        $this->pdf->textBox($x1, $y + 4, $x3, 10, $texto, $aFont, 'T', 'C', 0, '', false);
623
        $x1 += $x3;
624
625
        $this->pdf->textBox($x1, $y, $x2 - 15, 12);
626
        $texto = 'UF Carreg.';
627
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
628
        $this->pdf->textBox($x1, $y, $x2 - 15, 8, $texto, $aFont, 'T', 'C', 0, '', false);
629
        $texto = $this->UFIni;
630
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
631
        $this->pdf->textBox($x1, $y + 4, $x2 - 15, 10, $texto, $aFont, 'T', 'C', 0, '', false);
632
        $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...
633
634
        $x1 += $x2 - 15;
635
        $this->pdf->textBox($x1, $y, $x2 - 16, 12);
636
        $texto = 'UF Descar.';
637
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
638
        $this->pdf->textBox($x1, $y, $x2 - 16, 8, $texto, $aFont, 'T', 'C', 0, '', false);
639
        $texto = $this->UFFim;
640
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
641
        $this->pdf->textBox($x1, $y + 4, $x2 - 16, 10, $texto, $aFont, 'T', 'C', 0, '', false);
642
        $maxW = $this->wPrint;
643
644
        if ($this->aquav) {
645
            $x1 = $x;
646
            $x2 = $maxW;
647
            $y += 14;
648
            $this->pdf->textBox($x1, $y, $x2, 10);
649
            $texto = 'Embarcação';
650
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
651
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
652
            $texto = $this->aquav->getElementsByTagName('cEmbar')->item(0)->nodeValue;
653
            $texto .= ' - ';
654
            $texto .= $this->aquav->getElementsByTagName('xEmbar')->item(0)->nodeValue;
655
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
656
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'L', 0, '', false);
657
        }
658
659
        $x1 = $x;
660
        $x2 = $maxW;
661
        $y += 13;
662
        $this->pdf->textBox($x1, $y, $x2, 43);
663
        if ($this->rodo) {
664
            $texto = 'Modal Rodoviário de Carga';
665
        }
666
        if ($this->aereo) {
667
            $texto = 'Modal Aéreo de Carga';
668
        }
669
        if ($this->aquav) {
670
            $texto = 'Modal Aquaviário de Carga';
671
        }
672
        if ($this->ferrov) {
673
            $texto = 'Modal Ferroviário de Carga';
674
        }
675
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'B');
676
        $this->pdf->textBox($x1, $y + 1, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
677
        $texto = 'CONTROLE DO FISCO';
678
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
679
        $this->pdf->textBox($x1 + ($x2 / 2), $y + 1, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
680
681
        $x1 = $x;
682
        $x2 = ($maxW / 6);
683
        $y += 6;
684
        $this->pdf->textBox($x1, $y, $x2, 12);
685
        $texto = 'Qtd. CT-e';
686
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
687
        $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
688
        $texto = str_pad($this->qCTe, 3, '0', STR_PAD_LEFT);
689
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
690
        $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
691
        $x1 += $x2;
692
        $this->pdf->textBox($x1, $y, $x2, 12);
693
        $texto = 'Qtd. NF-e';
694
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
695
        $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
696
        $texto = str_pad($this->qNFe, 3, '0', STR_PAD_LEFT);
697
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
698
        $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
699
        $x1 += $x2;
700
        $this->pdf->textBox($x1, $y, $x2, 12);
701
702
        if ($this->rodo
703
            || $this->aereo
704
            || $this->ferrov
705
        ) {
706
            if ($this->cUnid == 01) {
707
                $texto = 'Peso Total (Kg)';
708
            } else {
709
                $texto = 'Peso Total (Ton)';
710
            }
711
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
712
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
713
            $texto = number_format($this->qCarga, 4, ',', '.');
714
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
715
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
716
        }
717
718
        if ($this->aquav) {
719
            $texto = 'Qtd. MDF-e Ref.';
720
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
721
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
722
            $texto = str_pad($this->qMDFe, 3, '0', STR_PAD_LEFT);
723
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
724
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
725
726
            $ya = $y + 12;
727
            $this->pdf->textBox($x, $ya, $maxW / 2, 12);
728
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
729
            if ($this->cUnid == 01) {
730
                $texto = 'Peso Total (Kg)';
731
            } else {
732
                $texto = 'Peso Total (Ton)';
733
            }
734
            $this->pdf->textBox($x, $ya, $maxW / 2, 8, $texto, $aFont, 'T', 'L', 0, '');
735
            $texto = number_format($this->qCarga, 4, ',', '.');
736
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
737
            $this->pdf->textBox($x, $ya + 4, $x2, 10, $texto, $aFont, 'T', 'L', 0, '', false);
738
        }
739
740
        // codigo de barras da chave
741
        $x1 += $x2;
742
        //$y = $y + 8;
743
        $this->pdf->textBox($x1, $y, $maxW / 2, 20);
744
        $bH = 16;
745
        $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...
746
        $this->pdf->setFillColor(0, 0, 0);
747
        $this->pdf->code128($x1 + 5, $y + 2, $this->chMDFe, ($maxW / 2) - 10, $bH);
748
        $this->pdf->setFillColor(255, 255, 255);
749
750
        // protocolo de autorização
751
        $y = $y + 24;
752
        $this->pdf->textBox($x, $y, $maxW / 2, 13);
753
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
754
        $texto = 'Protocolo de Autorização';
755
        $this->pdf->textBox($x, $y, $maxW / 2, 8, $texto, $aFont, 'T', 'L', 0, '');
756
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
757
        if (is_object($this->mdfeProc)) {
758
            $tsHora = $this->toTimestamp($this->dhRecbto);
759
            $texto = $this->nProt . ' - ' . date('d/m/Y   H:i:s', $tsHora);
760
        } else {
761
            $texto = 'DAMDFE impresso em contingência - ' . date('d/m/Y   H:i:s');
762
        }
763
        $this->pdf->textBox($x, $y + 4, $maxW / 2, 8, $texto, $aFont, 'T', 'C', 0, '');
764
765
        $y -= 4;
766
767
        // chave de acesso
768
        $this->pdf->textBox($x + $maxW / 2, $y, $maxW / 2, 17);
769
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
770
        $tsHora = $this->toTimestamp($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...
771
        $texto = 'Chave de Acesso';
772
        $this->pdf->textBox($x + $maxW / 2, $y, $maxW / 2, 6, $texto, $aFont, 'T', 'L', 0, '');
773
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
774
        $texto = $this->formatField($this->chMDFe, $this->formatoChave);
775
        $this->pdf->textBox($x + $maxW / 2, $y + 4, $maxW / 2, 6, $texto, $aFont, 'T', 'C', 0, '');
776
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => 'B');
777
        $texto = 'Consulte em https://dfe-portal.sefazvirtual.rs.gov.br/MDFe/consulta';
778
        $this->pdf->textBox($x + $maxW / 2, $y + 10, $maxW / 2, 6, $texto, $aFont, 'T', 'C', 0, '');
779
780
        $x1 = $x;
781
        $y += 20;
782
        $yold = $y;
783
        $x2 = round($maxW / 2, 0);
784
785
        if ($this->rodo) {
786
            $texto = 'Veículo';
787
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
788
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
789
            $y += 5;
790
            $x2 = round($maxW / 4, 0);
791
            $tamanho = 22;
792
            $this->pdf->textBox($x1, $y, $x2, $tamanho);
793
            $texto = 'Placa';
794
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
795
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
796
            $texto = $this->veicTracao->getElementsByTagName("placa")->item(0)->nodeValue;
797
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
798
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
799
            $altura = $y + 4;
800
            /**
801
*
802
             *
803
 * @var \DOMNodeList $veicReboque
804
*/
805
            $veicReboque = $this->veicReboque;
806
            foreach ($veicReboque as $item) {
807
                /**
808
*
809
                 *
810
 * @var \DOMElement $item
811
*/
812
                $altura += 4;
813
                $texto = $item->getElementsByTagName('placa')->item(0)->nodeValue;
814
                $this->pdf->textBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
815
            }
816
            $x1 += $x2;
817
            $this->pdf->textBox($x1, $y, $x2, $tamanho);
818
            $texto = 'RNTRC';
819
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
820
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
821
            // RNTRC Não informado
822
            if ($this->rodo->getElementsByTagName("RNTRC")->length > 0) {
823
                $texto = $this->rodo->getElementsByTagName("RNTRC")->item(0)->nodeValue;
824
            } else {
825
                $texto = "";
826
            }
827
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
828
            $this->pdf->textBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
829
            $altura = $y + 4;
830
            /**
831
 * @var \DOMNodeList $veicTracao
832
*/
833
            $veicTracao = $this->veicTracao->getElementsByTagName('prop');
834
            foreach ($veicTracao as $item) {
835
                /**
836
 * @var \DOMElement $item
837
*/
838
                $DOMNodeList = $item->getElementsByTagName('RNTRC');
839
                if ($DOMNodeList->length > 0) {
840
                    $altura += 4;
841
                    $texto = $DOMNodeList->item(0)->nodeValue;
842
                    $this->pdf->textBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
843
                }
844
            }
845
            /**
846
*
847
             *
848
 * @var \DOMNodeList $veicReboque
849
*/
850
            $veicReboque = $this->veicReboque;
851
            foreach ($veicReboque as $item) {
852
                /**
853
*
854
                 *
855
 * @var \DOMElement $item
856
*/
857
                $DOMNodeList = $item->getElementsByTagName('RNTRC');
858
                if ($DOMNodeList->length > 0) {
859
                    $altura += 4;
860
                    $texto = $DOMNodeList->item(0)->nodeValue;
861
                    $this->pdf->textBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
862
                }
863
            }
864
            $x1 = $x;
865
            $y += 22;
866
            $x2 = round($maxW / 2, 0);
867
            $valesPedagios = 1;
868
            $temVales = false;
869
            if ($this->valePed != "" && $this->valePed->length > 0) {
870
                $valesPedagios = $this->valePed->length;
871
                $temVales = true;
872
            }
873
            $tamanho = ($valesPedagios * 7.5);
874
            if (!$temVales) {
875
                $valesPedagios = 0;
876
            }
877
            $this->pdf->textBox($x1, $y, $x2, 11 + $tamanho / 2);
878
            $texto = 'Vale Pedágio';
879
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
880
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
881
            $y += 5;
882
            $x2 = ($x2 / 3);
883
            $this->pdf->textBox($x1, $y, $x2 - 3, 6 + ($tamanho / 2));
884
            $texto = 'Responsável CNPJ';
885
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
886
            $this->pdf->textBox($x1, $y, $x2 - 4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
887
            $altura = $y;
888
            for ($i = 0; $i < $valesPedagios; $i++) {
889
                $altura += 4;
890
                $texto = $this->valePed->item($i)->getElementsByTagName('CNPJForn')->item(0)->nodeValue;
891
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
892
                $this->pdf->textBox($x1 + 1, $altura, $x2 - 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
893
            }
894
            $x1 += $x2 - 3;
895
            $this->pdf->textBox($x1, $y, $x2 - 3, 6 + ($tamanho / 2));
896
            $texto = 'Fornecedora CNPJ';
897
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
898
            $this->pdf->textBox($x1, $y, $x2 - 4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
899
            $altura = $y;
900
            for ($i = 0; $i < $valesPedagios; $i++) {
901
                $altura += 4;
902
                $texto = $this->valePed->item($i)->getElementsByTagName('CNPJPg')->item(0)->nodeValue;
903
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
904
                $this->pdf->textBox($x1 + 1, $altura, $x2 - 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
905
            }
906
            $x1 += $x2 - 3;
907
            $this->pdf->textBox($x1, $y, $x2 + 6, 6 + ($tamanho / 2));
908
            $texto = 'Nº Comprovante';
909
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
910
            $this->pdf->textBox($x1, $y, $x2 + 6, 8, $texto, $aFont, 'T', 'L', 0, '', false);
911
            $altura = $y;
912
            for ($i = 0; $i < $valesPedagios; $i++) {
913
                $altura += 4;
914
                $texto = $this->valePed->item($i)->getElementsByTagName('nCompra')->item(0)->nodeValue;
915
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
916
                $this->pdf->textBox($x1 + 1, $altura, $x2 + 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
917
            }
918
            if (!$temVales) {
919
                $altura += 4;
920
            }
921
            $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...
922
            $x1 = round($maxW / 2, 0) + 7;
923
            $y = $yold;
924
            $x2 = round($maxW / 2, 0);
925
            $texto = 'Condutor';
926
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
927
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
928
            $y += 5;
929
            $x2 = ($maxW / 6);
930
            $this->pdf->textBox($x1, $y, $x2, 33 + ($tamanho / 2));
931
            $texto = 'CPF';
932
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
933
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
934
            $yold = $y;
935
            for ($i = 0; $i < $this->condutor->length; $i++) {
936
                $y += 4;
937
                $texto = $this->condutor->item($i)->getElementsByTagName('CPF')->item(0)->nodeValue;
938
                $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
939
                $this->pdf->textBox($x1 + 1, $y, $x2 - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
940
            }
941
            $y = $yold;
942
            $x1 += $x2;
943
            $x2 = $x2 * 2;
944
            $this->pdf->textBox($x1, $y, $x2, 33 + ($tamanho / 2));
945
            $texto = 'Nome';
946
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
947
            $this->pdf->textBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
948
            for ($i = 0; $i < $this->condutor->length; $i++) {
949
                $y += 4;
950
                $texto = $this->condutor->item($i)->getElementsByTagName('xNome')->item(0)->nodeValue;
951
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
952
                $this->pdf->textBox($x1 + 1, $y, $x2 - 1, 8, $texto, $aFont, 'T', 'L', 0, '', false);
953
            }
954
        }
955
956
        if ($this->aereo) {
957
            $altura = $y + 4;
958
        }
959
960
        if ($this->aquav) {
961
            $x1 = $x;
962
            $x2 = $maxW;
963
964
            $initial = $y;
965
            $initialA = $y + 2;
966
            $initialB = $y + 2;
967
968
            $texto = 'Carregamento';
969
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
970
            $this->pdf->textBox($x, $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
971
            foreach ($this->aquav->getElementsByTagName('infTermCarreg') as $item) {
972
                $initialA += 4.5;
973
974
                $texto = $item->getElementsByTagName('cTermCarreg')->item(0)->nodeValue;
975
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
976
                $this->pdf->textBox($x1 + 1, $initialA, ($x2 / 2) - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
977
978
                $texto = $item->getElementsByTagName('xTermCarreg')->item(0)->nodeValue;
979
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
980
                $this->pdf->textBox($x1 + 25, $initialA, ($x2 / 2) - 25, 10, $texto, $aFont, 'T', 'L', 0, '', false);
981
982
                if (strlen($texto) > 50) {
983
                    $initialA += 2;
984
                }
985
            }
986
            if ($this->aquav->getElementsByTagName('infTermCarreg')->item(0) != null) {
987
                $this->pdf->textBox($x1, $initial + 6, ($x2 / 2), $initialA - $y);
988
            }
989
990
            $texto = 'Descarregamento';
991
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
992
            $this->pdf->textBox($x1 + ($x2 / 2), $initial + 2, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
993
            foreach ($this->aquav->getElementsByTagName('infTermDescarreg') as $item) {
994
                $initialB += 4.5;
995
996
                $texto = $item->getElementsByTagName('cTermDescarreg')->item(0)->nodeValue;
997
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
998
                $this->pdf->textBox(
999
                    ($x1 + ($x2 / 2)) + 1,
1000
                    $initialB,
1001
                    ($x2 / 2) - 1,
1002
                    10,
1003
                    $texto,
1004
                    $aFont,
1005
                    'T',
1006
                    'L',
1007
                    0,
1008
                    '',
1009
                    false
1010
                );
1011
1012
                $texto = $item->getElementsByTagName('xTermDescarreg')->item(0)->nodeValue;
1013
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1014
1015
                $this->pdf->textBox(
1016
                    ($x1 + ($x2 / 2)) + 25,
1017
                    $initialB,
1018
                    ($x2 / 2) - 25,
1019
                    10,
1020
                    $texto,
1021
                    $aFont,
1022
                    'T',
1023
                    'L',
1024
                    0,
1025
                    '',
1026
                    false
1027
                );
1028
1029
                if (strlen($texto) > 50) {
1030
                    $initialB += 2;
1031
                }
1032
            }
1033
            if ($this->aquav->getElementsByTagName('infTermDescarreg')->item(0) != null) {
1034
                $this->pdf->textBox(($x1 + ($x2 / 2)), $initial + 6, ($x2 / 2), $initialB - $y);
1035
            }
1036
1037
            $altura = $initialA > $initialB ? $initialA : $initialB;
1038
            $altura += 6;
1039
1040
            $y = $altura + 3;
1041
1042
            $initial = $y;
1043
            $initialA = $y + 2;
1044
            $initialB = $y + 2;
1045
1046
            $texto = 'Unidade de Transporte';
1047
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1048
            $this->pdf->textBox($x, $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 / 4), $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
1053
1054
            foreach ($this->aquav->getElementsByTagName('infUnidCargaVazia') as $item) {
1055
                $initialA += 4.5;
1056
1057
                $texto = $item->getElementsByTagName('idUnidCargaVazia')->item(0)->nodeValue;
1058
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1059
                $this->pdf->textBox($x1 + 1, $initialA, ($x2 / 2) - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
1060
1061
                $texto = $item->getElementsByTagName('tpUnidCargaVazia')->item(0)->nodeValue;
1062
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1063
                $this->pdf->textBox(
1064
                    $x1 + ($x2 / 4),
1065
                    $initialA,
1066
                    ($x2 / 2) - 25,
1067
                    10,
1068
                    $texto,
1069
                    $aFont,
1070
                    'T',
1071
                    'L',
1072
                    0,
1073
                    '',
1074
                    false
1075
                );
1076
1077
                if (strlen($texto) > 50) {
1078
                    $initialA += 2;
1079
                }
1080
            }
1081
            if ($this->aquav->getElementsByTagName('infUnidCargaVazia')->item(0) != null) {
1082
                $this->pdf->textBox($x1, $initial + 6, ($x2 / 2), $initialA - $y);
1083
            }
1084
1085
            $texto = 'Unidade de Transporte';
1086
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1087
            $this->pdf->textBox($x1 + ($x2 / 2), $initial + 2, $x2 / 2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
1088
1089
            $texto = 'Unidade de Carga';
1090
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
1091
            $this->pdf->textBox($x1 + ($x2 / 1.33), $initial + 2, ($x2 / 2), 8, $texto, $aFont, 'T', 'L', 0, '', false);
1092
1093
            foreach ($this->aquav->getElementsByTagName('infUnidTranspVazia') as $item) {
1094
                $initialB += 4.5;
1095
1096
                $texto = $item->getElementsByTagName('idUnidTranspVazia')->item(0)->nodeValue;
1097
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1098
1099
                $this->pdf->textBox(
1100
                    ($x1 + ($x2 / 2)) + 1,
1101
                    $initialB,
1102
                    ($x2 / 2) - 1,
1103
                    10,
1104
                    $texto,
1105
                    $aFont,
1106
                    'T',
1107
                    'L',
1108
                    0,
1109
                    '',
1110
                    false
1111
                );
1112
1113
                $texto = $item->getElementsByTagName('tpUnidTranspVazia')->item(0)->nodeValue;
1114
                $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1115
                $this->pdf->textBox(
1116
                    ($x1 + ($x2 / 1.33)),
1117
                    $initialB,
1118
                    ($x2 / 2) - 25,
1119
                    10,
1120
                    $texto,
1121
                    $aFont,
1122
                    'T',
1123
                    'L',
1124
                    0,
1125
                    '',
1126
                    false
1127
                );
1128
1129
                if (strlen($texto) > 50) {
1130
                    $initialB += 2;
1131
                }
1132
            }
1133
            if ($this->aquav->getElementsByTagName('infUnidTranspVazia')->item(0) != null) {
1134
                $this->pdf->textBox(($x1 + ($x2 / 2)), $initial + 6, ($x2 / 2), $initialB - $y);
1135
            }
1136
1137
            $altura = $initialA > $initialB ? $initialA : $initialB;
1138
            $altura += 6;
1139
        }
1140
1141
        if ($this->ferrov) {
1142
            $altura = $y + 4;
1143
        }
1144
1145
        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...
1146
    }
1147
1148
1149
    protected function qrCodeDamdfe($y = 0)
1150
    {
1151
        $margemInterna = $this->margemInterna;
1152
        $barcode = new Barcode();
1153
        $bobj = $barcode->getBarcodeObj(
1154
            'QRCODE,M',
1155
            $this->qrCodMDFe,
1156
            -4,
1157
            -4,
1158
            'black',
1159
            array(-2, -2, -2, -2)
1160
        )->setBackgroundColor('white');
1161
        $qrcode = $bobj->getPngData();
1162
        $wQr = 35;
1163
        $hQr = 35;
1164
        $yQr = ($y + $margemInterna);
1165
        if ($this->orientacao == 'P') {
1166
            $xQr = 160;
1167
        } else {
1168
            $xQr = 235;
1169
        }
1170
        // prepare a base64 encoded "data url"
1171
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
1172
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
1173
    }
1174
1175
1176
    /**
1177
     * footerMDFe
1178
     *
1179
     * @param float $x
1180
     * @param float $y
1181
     */
1182
    private function footerMDFe($x, $y)
1183
    {
1184
        $maxW = $this->wPrint;
1185
        $x2 = $maxW;
1186
        $this->pdf->textBox($x, $y, $x2, 30);
1187
        $texto = 'Observação
1188
        ' . $this->infCpl;
1189
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
1190
        $this->pdf->textBox($x, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
1191
        $y = $this->hPrint - 4;
1192
        $texto = "Impresso em  " . date('d/m/Y H:i:s');
1193
        $w = $this->wPrint - 4;
1194
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
1195
        $this->pdf->textBox($x, $y, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
1196
        $texto = $this->creditos .  "  Powered by NFePHP®";
1197
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1198
    }
1199
1200
    public function monta(
1201
        $logo = '',
1202
        $orientacao = 'P',
1203
        $papel = 'A4',
1204
        $logoAlign = 'L'
1205
    ) {
1206
        $this->pdf = '';
1207
        $this->logomarca = $logo;
1208
        $this->orientacao = $orientacao;
1209
        $this->papel = $papel;
1210
        $this->logoAlign = $logoAlign;
1211
        $this->buildMDFe();
1212
    }
1213
1214
    /**
1215
     * Dados brutos do PDF
1216
     *
1217
     * @return string
1218
     */
1219
    public function render()
1220
    {
1221
        if (empty($this->pdf)) {
1222
            $this->monta();
1223
        }
1224
        return $this->pdf->getPdf();
1225
    }
1226
    
1227
    /**
1228
     * Add the credits to the integrator in the footer message
1229
     *
1230
     * @param string $message
1231
     */
1232
    public function creditsIntegratorFooter($message = '')
1233
    {
1234
        $this->creditos = trim($message);
1235
    }
1236
}
1237