Test Failed
Pull Request — master (#212)
by
unknown
05:23
created

Damdfe::bodyMDFe()   F

Complexity

Conditions 15
Paths 6144

Size

Total Lines 245

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 198
CRAP Score 15.1113

Importance

Changes 0
Metric Value
cc 15
nc 6144
nop 2
dl 0
loc 245
ccs 198
cts 215
cp 0.9209
crap 15.1113
rs 1.3999
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 DateTime;
20
use NFePHP\DA\Legacy\Dom;
21
use NFePHP\DA\Legacy\Common;
22
use NFePHP\DA\Legacy\Pdf;
23
24
class Damdfe extends Common
25
{
26
    //publicas
27
    public $logoAlign = 'L'; //alinhamento do logo
28
    public $yDados = 0;
29
    public $debugMode = 0; //ativa ou desativa o modo de debug
30
    //privadas
31
    protected $pdf; // objeto fpdf()
32
    protected $xml; // string XML NFe
33
    protected $logomarca = ''; // path para logomarca em jpg
34
    protected $errMsg = ''; // mesagens de erro
35
    protected $errStatus = false;// status de erro TRUE um erro ocorreu false sem erros
36
    protected $orientacao = 'P'; //orientação da DANFE P-Retrato ou L-Paisagem
37
    protected $papel = 'A4'; //formato do papel
38
    //destivo do arquivo pdf I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
39
    protected $destino = 'I';
40
    protected $pdfDir = ''; //diretorio para salvar o pdf com a opção de destino = F
41
    protected $fontePadrao = 'Times'; //Nome da Fonte para gerar o DANFE
42
    protected $version = '1.0.0';
43
    protected $wPrint; //largura imprimivel
44
    protected $hPrint; //comprimento imprimivel
45
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
46
    protected $margemInterna = 2;
47
    protected $hMaxLinha = 9;
48
    protected $hBoxLinha = 6;
49
    protected $hLinha = 3;
50
    //variaveis da carta de correção
51
    protected $id;
52
    protected $chMDFe;
53
    protected $tpAmb;
54
    protected $cOrgao;
55
    protected $xCondUso;
56
    protected $dhEvento;
57
    protected $cStat;
58
    protected $xMotivo;
59
    protected $CNPJDest = '';
60
    protected $dhRegEvento;
61
    protected $nProt;
62
    protected $tpEmis;
63
    protected $qrCodMDFe;
64
    //objetos
65
    private $dom;
66
    private $procEventoNFe;
67
    private $evento;
68
    private $infEvento;
69
    private $retEvento;
70
    private $rinfEvento;
71
72
    /**
73
     * __construct
74
     *
75
     * @param string $xmlfile Arquivo XML da MDFe
76 1
     * @param string $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
77
     * @param string $sPapel Tamanho do papel (Ex. A4)
78
     * @param string $sPathLogo Caminho para o arquivo do logo
79
     * @param string $sDestino Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
80
     * @param string $sDirPDF Caminho para o diretorio de armazenamento dos arquivos PDF
81
     * @param string $fonteDAMDFE Nome da fonte alternativa do DAnfe
0 ignored issues
show
Bug introduced by
There is no parameter named $fonteDAMDFE. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
82
     * @param integer $mododebug 0-Não 1-Sim e 2-nada (2 default)
83
     */
84
    public function __construct(
85
        $xmlfile = '',
86
        $sOrientacao = '',
87 1
        $sPapel = '',
88 1
        $sPathLogo = '',
89
        $sDestino = 'I',
90
        $sDirPDF = '',
91 1
        $fontePDF = '',
92
        $mododebug = 2
93 1
    ) {
94 1
        //define o caminho base da instalação do sistema
95
        if (!defined('PATH_ROOT')) {
96
            define('PATH_ROOT', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
97 1
        }
98 1
//ajuste do tempo limite de resposta do processo
99
        set_time_limit(1800);
100 1
//definição do caminho para o diretorio com as fontes do FDPF
101
        if (!defined('FPDF_FONTPATH')) {
102
            define('FPDF_FONTPATH', 'font/');
103
        }
104
105
        if (is_numeric($mododebug)) {
106 1
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
107 1
        }
108
        if ($this->debugMode) {
109 1
            //ativar modo debug
110 1
            error_reporting(E_ALL);
111 1
            ini_set('display_errors', 'On');
112 1
        } else {
113 1
            //desativar modo debug
114 1
            error_reporting(0);
115 1
            ini_set('display_errors', 'Off');
116
        }
117 1
        $this->orientacao = $sOrientacao;
118 1
        $this->papel = $sPapel;
119
        $this->pdf = '';
120
        $this->xml = $xmlfile;
121
        $this->logomarca = $sPathLogo;
122
        $this->destino = $sDestino;
123 1
        $this->pdfDir = $sDirPDF;
124
        // verifica se foi passa a fonte a ser usada
125
        if (empty($fontePDF)) {
126
            $this->fontePadrao = 'Times';
127 1
        } else {
128 1
            $this->fontePadrao = $fontePDF;
129 1
        }
130
        //se for passado o xml
131
        if (empty($xmlfile)) {
132
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
133 1
            $this->errStatus = true;
134 1
        }
135 1
        if (!is_file($xmlfile)) {
136 1
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
137 1
            $this->errStatus = true;
138 1
        }
139 1
140 1
//        $docxml = file_get_contents($xmlfile);
141 1
        $this->dom = new Dom();
142 1
        $this->dom->loadXML($this->xml);
143 1
        $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...
144 1
        $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...
145 1
        $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...
146 1
        $this->CNPJ = $this->dom->getElementsByTagName("CNPJ")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property CNPJ does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
147 1
        $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...
148 1
        $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...
149 1
        $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...
150 1
        $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...
151 1
        $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...
152 1
        $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...
153 1
        $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...
154 1
        $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...
155 1
        $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...
156 1
        $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...
157 1
        $this->tpAmb = $this->dom->getElementsByTagName("tpAmb")->item(0)->nodeValue;
158 1
        $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...
159 1
        $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...
160
        $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...
161
        $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...
162 1
        $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...
163 1
        $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...
164
        $this->tpEmis = $this->dom->getElementsByTagName("tpEmis")->item(0)->nodeValue;
165
        $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...
166 1
        $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...
167 1
        if ($this->dom->getElementsByTagName("qNFe")->item(0) != "") {
168 1
            $this->qNFe = $this->dom->getElementsByTagName("qNFe")->item(0)->nodeValue;
169
        }
170 1
        $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...
171 1
        if ($this->dom->getElementsByTagName("qNF")->item(0) != "") {
172
            $this->qNF = $this->dom->getElementsByTagName("qNF")->item(0)->nodeValue;
173
        }
174 1
        $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...
175 1
        if ($this->dom->getElementsByTagName("qCTe")->item(0) != "") {
176 1
            $this->qCTe = $this->dom->getElementsByTagName("qCTe")->item(0)->nodeValue;
177 1
        }
178 1
        $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...
179
        if ($this->dom->getElementsByTagName("qCT")->item(0) != "") {
180
            $this->qCT = $this->dom->getElementsByTagName("qCT")->item(0)->nodeValue;
181 1
        }
182 1
        $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...
183 1
        $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...
184 1
        $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...
185
        $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...
186
        if ($this->dom->getElementsByTagName('CIOT')->item(0) != "") {
187 1
            $this->ciot = $this->dom->getElementsByTagName('CIOT')->item(0)->nodeValue;
188 1
        }
189 1
        $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...
190 1
        $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...
191 1
        $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...
192
        if ($this->dom->getElementsByTagName("valePed")->item(0) != "") {
193 1
            $this->valePed = $this->dom->getElementsByTagName("valePed")->item(0)->getElementsByTagName("disp");
194 1
        }
195 1
        $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...
196 1
        $this->chMDFe = str_replace(
197
            'MDFe',
198 1
            '',
199
            $this->infMDFe->getAttribute("Id")
200
        );
201
        $this->qrCodMDFe = $this->dom->getElementsByTagName('qrCodMDFe')->item(0) ?
202
            $this->dom->getElementsByTagName('qrCodMDFe')->item(0)->nodeValue : null;
203 1
        if (is_object($this->mdfeProc)) {
204
            $this->nProt = !empty($this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
205 1
                $this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
206 1
            $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...
207
        }
208 1
    }//fim construct
209 1
210 1
    /**
211
     *buildMDFe
212 1
     *
213 1
     */
214 1
    public function buildMDFe()
215 1
    {
216 1
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
217
        if ($this->orientacao == 'P') {
218
            // margens do PDF
219
            $margSup = 7;
220
            $margEsq = 7;
221
            $margDir = 7;
222
            // posição inicial do relatorio
223
            $xInic = 7;
224
            $yInic = 7;
225
            if ($this->papel == 'A4') { //A4 210x297mm
226
                $maxW = 210;
227
                $maxH = 297;
228
            }
229
        } else {
230
            // margens do PDF
231
            $margSup = 7;
232 1
            $margEsq = 7;
233
            $margDir = 7;
234 1
            // posição inicial do relatorio
235
            $xInic = 7;
236 1
            $yInic = 7;
237
            if ($this->papel == 'A4') { //A4 210x297mm
238 1
                $maxH = 210;
239 1
                $maxW = 297;
240 1
            }
241
        }//orientação
242 1
        //largura imprimivel em mm
243
        $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...
244 1
        //comprimento imprimivel em mm
245 1
        $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...
246 1
        // estabelece contagem de paginas
247
        $this->pdf->AliasNbPages();
248 1
        // fixa as margens
249 1
        $this->pdf->SetMargins($margEsq, $margSup, $margDir);
250 1
        $this->pdf->SetDrawColor(0, 0, 0);
251
        $this->pdf->SetFillColor(255, 255, 255);
252 1
        // inicia o documento
253 1
        $this->pdf->Open();
254
        // adiciona a primeira página
255
        $this->pdf->AddPage($this->orientacao, $this->papel);
256
        $this->pdf->SetLineWidth(0.1);
257
        $this->pdf->SetTextColor(0, 0, 0);
258 1
        //montagem da página
259
        $x = $xInic;
260 1
        $y = $yInic;
261 1
        //coloca o cabeçalho Paisagem
262
        if ($this->orientacao == 'P') {
263
            $y = $this->headerMDFeRetrato($x, $y);
264
        } else {
265
            $y = $this->headerMDFePaisagem($x, $y);
266
        }
267
        //coloca os dados da MDFe
268
        $y = $this->bodyMDFe($x, $y);
269
        //coloca os dados da MDFe
270
        $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...
271
    } //fim buildCCe
272
273
    /**
274
     * headerMDFePaisagem
275
     * @param float $x
276
     * @param float $y
277
     * @return string
278
     */
279
    private function headerMDFePaisagem($x, $y)
280
    {
281
        $oldY = $y;
282
        $maxW = $this->wPrint;
283
        //####################################################################################
284
        //coluna esquerda identificação do emitente
285
        $w = $maxW; //round($maxW*0.41, 0);// 80;
286
        $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...
287
        $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...
288
        $h = 30;
289
        $oldY += $h;
290
        $this->pTextBox($x, $y, $w, $h);
291
        if (is_file($this->logomarca)) {
292
            $logoInfo = getimagesize($this->logomarca);
293
            //largura da imagem em mm
294
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
295
            //altura da imagem em mm
296
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
297
            if ($this->logoAlign == 'L') {
298
                $nImgW = round($w / 4.5, 0);
299
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
300
                $xImg = $x + 1;
301
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
302
                //estabelecer posições do texto
303
                $x1 = round($xImg + $nImgW + 1, 0);
304
                $y1 = round($y + 2, 0);
305
                $tw = round(2 * $w / 3, 0);
306
            }
307
            if ($this->logoAlign == 'C') {
308
                $nImgH = round($h / 3, 0);
309
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
310
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
311
                $yImg = $y + 3;
312
                $x1 = $x;
313
                $y1 = round($yImg + $nImgH + 1, 0);
314
                $tw = $w;
315
            }
316
            if ($this->logoAlign == 'R') {
317
                $nImgW = round($w / 3, 0);
318
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
319
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
320
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
321
                $x1 = $x;
322
                $y1 = round($h / 3 + $y, 0);
323
                $tw = round(2 * $w / 3, 0);
324
            }
325
            $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...
326
        } else {
327
            $x1 = $x;
328
            $y1 = round($h / 3 + $y, 0);
329
            $tw = $w;
330
        }
331
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
332
        $razao = $this->xNome;
333
        $cnpj = 'CNPJ: ' . $this->pFormat($this->CNPJ, "###.###.###/####-##");
334
        $ie = 'IE: ' . $this->pFormat($this->IE, '##/########');
335
        $lgr = 'Logradouro: ' . $this->xLgr;
336
        $nro = 'Nº: ' . $this->nro;
337
        $bairro = 'Bairro: ' . $this->xBairro;
338
        $CEP = $this->CEP;
339
        $CEP = 'CEP: ' . $this->pFormat($CEP, "##.###-###");
340
        $UF = 'UF: ' . $this->UF;
341
        $mun = 'Municipio: ' . $this->xMun;
342
343
        $texto = $razao . "\n" . $cnpj . ' - ' . $ie . "\n";
344
        $texto .= $lgr . ' - ' . $nro . "\n";
345
        $texto .= $bairro . "\n";
346
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
347
        $this->pTextBox($x1, $y1 + 5, $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...
348
        $x = $x + $maxW / 2;
349
        $w = $maxW / 2;
350
        $this->pTextBox($x, $y, $w, $h);
351
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'I');
352
        $this->pTextBox(
353
            $x,
354
            $y,
355
            $w,
356
            8,
357
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
358
            $aFont,
359
            'T',
360
            'C',
361
            0,
362
            ''
363
        );
364
        $this->pTextBox($x, $y, $w, 6);
365
        $bH = 13;
366
        $bW = round(($w), 0);
367
        $this->pdf->SetFillColor(0, 0, 0);
368
        $this->pdf->Code128($x + 5, $y + 7.5, $this->chMDFe, $bW - 10, $bH);
369
        $this->pdf->SetFillColor(255, 255, 255);
370
        $y = $y + 22;
371
        $this->pTextBox($x, $y, $w, 8);
372
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
373
        $texto = 'CHAVE DE ACESSO';
374
        $this->pTextBox($x, $y, $maxW, 6, $texto, $aFont, 'T', 'L', 0, '');
375
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
376
        $texto = $this->pFormat($this->chMDFe, $this->formatoChave);
377
        $this->pTextBox($x, $y + 3, $w, 6, $texto, $aFont, 'T', 'C', 0, '');
378
        $y = $y + 11;
379
        $this->pTextBox($x, $y, $w, 12);
380
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
381
        $texto = 'PROTOCOLO DE AUTORIZACAO DE USO';
382
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
383
384
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
385
        if (is_object($this->mdfeProc)) {
386
            $tsHora = $this->pConvertTime($this->dhRecbto);
387
            $texto = $this->nProt . ' - ' . date('d/m/Y   H:i:s', $tsHora);
388
        } else {
389
            $texto = 'DAMDFE impresso em contingência - ' . date('d/m/Y   H:i:s');
390
        }
391
        $this->pTextBox($x, $y + 4, $w, 8, $texto, $aFont, 'T', 'C', 0, '');
392
        if ($this->tpAmb != 1) {
393
            $x = 10;
394
            if ($this->orientacao == 'P') {
395
                $yy = round($this->hPrint * 2 / 3, 0);
396
            } else {
397
                $yy = round($this->hPrint / 2, 0);
398
            }
399
            $h = 5;
400
            $w = $maxW - (2 * $x);
401
            $this->pdf->SetTextColor(90, 90, 90);
402
            $texto = "SEM VALOR FISCAL";
403
            $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
404
            $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
405
            $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
406
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
407
            $this->pTextBox($x, $yy + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
408
            $this->pdf->SetTextColor(0, 0, 0);
409
        } else {
410
            $x = 10;
411
            if ($this->orientacao == 'P') {
412
                $yy = round($this->hPrint * 2 / 3, 0);
413
            } else {
414
                $yy = round($this->hPrint / 2, 0);
415
            }//fim orientacao
416
            $h = 5;
417
            $w = $maxW - (2 * $x);
418
            $this->pdf->SetTextColor(90, 90, 90);
419
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
420
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
421
                //Contingência
422
                $texto = "DAMDFE Emitido em Contingência";
423
                $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
424
                $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
425
                $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
426
                $texto = "devido à problemas técnicos";
427
                $this->pTextBox($x, $yy + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
428
            }
429
            $this->pdf->SetTextColor(0, 0, 0);
430
        }
431
        return $y;
432
    }// fim headerMDFe
433
434 1
    /**
435
     * headerMDFeRetrato
436 1
     *
437 1
     * @param float $x
438 1
     * @param float $y
439
     * @return string
440
     */
441 1
    private function headerMDFeRetrato($x, $y)
442 1
    {
443 1
        $oldY = $y;
444 1
        $maxW = $this->wPrint;
445 1
        //####################################################################################
446 1
        //coluna esquerda identificação do emitente
447 1
        $w = $maxW; //round($maxW*0.41, 0);// 80;
448
        $h = 27;
449
        $oldY += $h;
450
        $this->pTextBox($x, $y, $w, $h);
451
        if (is_file($this->logomarca)) {
452
            $logoInfo = getimagesize($this->logomarca);
453
            //largura da imagem em mm
454
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
455
            //altura da imagem em mm
456
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
457
            switch ($this->logoAlign) {
458
                case 'L':
459
                    $nImgW = round($w / 8, 0);
460
                    $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
461
                    $xImg = $x + 1;
462
                    $yImg = round(($h - $nImgH) / 2, 0) + $y;
463
                    //estabelecer posições do texto
464
                    $x = round($xImg + $nImgW + 1, 0);
465
                    $y = round($y + 2, 0);
466
                    $tw = round(2 * $w / 3, 0);
467
                    break;
468
469
                case 'C':
470
                    $nImgH = round($h / 3, 0);
471
                    $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
472
                    $xImg = round(($w - $nImgW) / 2 + $x, 0);
473
                    $yImg = $y + 3;
474
                    $y = round($yImg + $nImgH + 1, 0);
475
                    $tw = $w;
476
                    break;
477
478
                case 'R':
479
                    $nImgW = round($w / 3, 0);
480
                    $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
481
                    $xImg = round($x + ($w - (1 + $nImgW)), 0);
482
                    $yImg = round(($h - $nImgH) / 2, 0) + $y;
483 1
                    $y = round($h / 3 + $y, 0);
484 1
                    $tw = round(2 * $w / 3, 0);
485 1
                    break;
486
            }
487 1
488 1
            $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...
489 1
        }
490 1
491 1
        if ($this->qrCodMDFe !== null) {
492 1
            $this->pQRDAMDFE($y - 3);
493 1
        }
494 1
495 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 11, 'style' => '');
496 1
        $razao = $this->xNome;
497 1
        $cnpj = 'CNPJ: ' . $this->pFormat($this->CNPJ, "###.###.###/####-##");
498 1
        $ie = 'IE: ' . $this->pFormat($this->IE, '##########');
499 1
        $lgr = 'Logradouro: ' . $this->xLgr;
500 1
        $nro = 'Nº: ' . $this->nro;
501 1
        $bairro = 'Bairro: ' . $this->xBairro;
502 1
        $CEP = $this->CEP;
503
        $CEP = 'CEP: ' . $this->pFormat($CEP, "##.###-###");
504 1
        $mun = 'Municipio: ' . $this->xMun;
505 1
        $UF = 'UF: ' . $this->UF;
506 1
        $texto = $razao . "\n" . $cnpj . ' - ' . $ie . "\n";
507 1
        $texto .= $lgr . ' - ' . $nro . "\n";
508 1
        $texto .= $bairro . "\n";
509 1
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
510 1
        $this->pTextBox($x, $y, $tw, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
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...
511 1
512 1
        //##################################################
513 1
        $y = $h + 8;
514 1
        $this->pTextBox($x - 27, $y, $maxW, 6);
515 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 12, 'style' => 'I');
516 1
        $this->pTextBox(
517 1
            $x - 27,
518
            $y,
519 1
            $maxW,
520 1
            8,
521 1
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
522 1
            $aFont,
523 1
            'T',
524 1
            'C',
525 1
            0,
526 1
            ''
527 1
        );
528 1
        $y = $y + 8;
529 1
        $this->pTextBox($x - 27, $y, $maxW, 20);
530 1
        $bH = 16;
531 1
        $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...
532 1
        $this->pdf->SetFillColor(0, 0, 0);
533 1
        $this->pdf->Code128($x - 22, $y + 2, $this->chMDFe, $maxW - 10, $bH);
534 1
        $this->pdf->SetFillColor(255, 255, 255);
535 1
        $y = $y + 27;
536 1
        $this->pTextBox($x - 27, $y, $maxW, 10);
537 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
538 1
        $tsHora = $this->pConvertTime($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...
539 1
        $texto = 'CHAVE DE ACESSO';
540 1
        $this->pTextBox($x - 27, $y, $maxW, 6, $texto, $aFont, 'T', 'L', 0, '');
541 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
542 1
        $texto = $this->pFormat($this->chMDFe, $this->formatoChave);
543 1
        $this->pTextBox($x - 27, $y + 4, $maxW, 6, $texto, $aFont, 'T', 'C', 0, '');
544
        $y = $y + 12;
545
        $this->pTextBox($x - 27, $y, $maxW, 10);
546
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'I');
547 1
        $texto = 'PROTOCOLO DE AUTORIZACAO DE USO';
548 1
        $this->pTextBox($x - 27, $y, $maxW, 8, $texto, $aFont, 'T', 'L', 0, '');
549 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
550 1
        if (is_object($this->mdfeProc)) {
551 1
            $tsHora = $this->pConvertTime($this->dhRecbto);
552
            $texto = $this->nProt . ' - ' . date('d/m/Y   H:i:s', $tsHora);
553
        } else {
554
            $texto = 'DAMDFE impresso em contingência - ' . date('d/m/Y   H:i:s');
555 1
        }
556 1
        $this->pTextBox($x - 27, $y + 4, $maxW, 8, $texto, $aFont, 'T', 'C', 0, '');
557 1
        if ($this->tpAmb != 1) {
558 1
            $x = 10;
559 1
            if ($this->orientacao == 'P') {
560 1
                $yy = round($this->hPrint * 2 / 3, 0);
561 1
            } else {
562 1
                $yy = round($this->hPrint / 2, 0);
563 1
            }
564 1
            $h = 5;
565
            $w = $maxW - (2 * $x);
566
            $this->pdf->SetTextColor(90, 90, 90);
567
            $texto = "SEM VALOR FISCAL";
568
            $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
569
            $this->pTextBox($x + 7, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
570
            $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
571
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
572
            $this->pTextBox($x + 7, $yy + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
573
            $this->pdf->SetTextColor(0, 0, 0);
574
        } else {
575
            $x = 10;
576
            if ($this->orientacao == 'P') {
577
                $yy = round($this->hPrint * 2 / 3, 0);
578
            } else {
579
                $yy = round($this->hPrint / 2, 0);
580
            }//fim orientacao
581
            $h = 5;
582
            $w = $maxW - (2 * $x);
583
            $this->pdf->SetTextColor(90, 90, 90);
584
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
585
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
586
                //Contingência
587 1
                $texto = "DAMDFE Emitido em Contingência";
588
                $aFont = array('font' => $this->fontePadrao, 'size' => 48, 'style' => 'B');
589
                $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
590
                $aFont = array('font' => $this->fontePadrao, 'size' => 30, 'style' => 'B');
591
                $texto = "devido à problemas técnicos";
592
                $this->pTextBox($x, $yy + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
593
            }
594
            $this->pdf->SetTextColor(0, 0, 0);
595
        }
596
        return $y + 17;
597 1
    }// fim headerMDFe
598
599 1
    /**
600 1
     * bodyMDFe
601
     *
602
     * @param float $x
603
     * @param float $y
604 1
     * @return void
605 1
     */
606 1
    private function bodyMDFe($x, $y)
607 1
    {
608 1
        if ($this->orientacao == 'P') {
609 1
            $maxW = $this->wPrint;
610 1
        } else {
611 1
            $maxW = $this->wPrint / 2;
612 1
        }
613 1
        $x2 = ($maxW / 6);
614 1
        $x1 = $x2;
0 ignored issues
show
Unused Code introduced by
$x1 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...
615 1
        $this->pTextBox($x, $y, $x2 - 7, 12);
616 1
        $texto = 'Modelo';
617 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
618 1
        $this->pTextBox($x, $y, $x2 - 7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
619 1
        $texto = $this->mod;
620 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
621 1
        $this->pTextBox($x, $y + 4, $x2 - 7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
622 1
        $x1 = $x2;
623 1
        $this->pTextBox($x1, $y, $x2 - 7, 12);
624 1
        $texto = 'Série';
625 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
626 1
        $this->pTextBox($x1, $y, $x2 - 7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
627 1
        $texto = $this->serie;
628 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
629 1
        $this->pTextBox($x1, $y + 4, $x2 - 7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
630 1
        $x1 += $x2 - 7;
631 1
        $this->pTextBox($x1, $y, $x2 + 5, 12);
632 1
        $texto = 'Número';
633 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
634 1
        $this->pTextBox($x1, $y, $x2 + 5, 8, $texto, $aFont, 'T', 'L', 0, '', false);
635 1
        $texto = $this->pFormat(str_pad($this->nMDF, 9, '0', STR_PAD_LEFT), '###.###.###');
636 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
637 1
        $this->pTextBox($x1, $y + 4, $x2 + 5, 10, $texto, $aFont, 'T', 'C', 0, '', false);
638 1
        $x1 += $x2 + 5;
639 1
        $this->pTextBox($x1, $y, $x2 - 7, 12);
640 1
        $texto = 'FL';
641 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
642 1
        $this->pTextBox($x1, $y, $x2 - 7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
643 1
        $texto = '1';
644 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
645 1
        $this->pTextBox($x1, $y + 4, $x2 - 7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
646 1
        $x1 += $x2 - 7;
647 1
        $this->pTextBox($x1, $y, $x2 + 11, 12);
648 1
        $texto = 'Data e Hora de Emissão';
649 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
650 1
        $this->pTextBox($x1, $y, $x2 + 11, 8, $texto, $aFont, 'T', 'L', 0, '', false);
651 1
        $data = explode('T', $this->dhEmi);
652 1
        $texto = $this->pYmd2dmy($data[0]) . ' - ' . $data[1];
653 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
654 1
        $this->pTextBox($x1, $y + 4, $x2 + 11, 10, $texto, $aFont, 'T', 'C', 0, '', false);
655
        $x1 += $x2 + 11;
656 1
        $this->pTextBox($x1, $y, $x2 - 15, 12);
657 1
        $texto = 'UF Carreg.';
658 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
659 1
        $this->pTextBox($x1, $y, $x2 - 15, 8, $texto, $aFont, 'T', 'L', 0, '', false);
660 1
        $texto = $this->UFIni;
661 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
662 1
        $this->pTextBox($x1, $y + 4, $x2 - 15, 10, $texto, $aFont, 'T', 'C', 0, '', false);
663 1
        $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...
664 1
665
        $x1 += $x2 - 15;
666
        $this->pTextBox($x1, $y, $x2 - 13, 12);
667
        $texto = 'UF Descar.';
668 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
669 1
        $this->pTextBox($x1, $y, $x2 - 13, 8, $texto, $aFont, 'T', 'L', 0, '', false);
670 1
        $texto = $this->UFFim;
671 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
672 1
        $this->pTextBox($x1, $y + 4, $x2 - 13, 10, $texto, $aFont, 'T', 'C', 0, '', false);
673 1
        $maxW = $this->wPrint;
674 1
675 1
676 1
        $x1 = $x;
677 1
        $x2 = $maxW;
678 1
        $y += 14;
679 1
        $this->pTextBox($x1, $y, $x2, 23);
680 1
        $texto = 'Modal Rodoviário de Carga';
681 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
682 1
        $this->pTextBox($x1, $y + 1, $x2, 8, $texto, $aFont, 'T', 'C', 0, '', false);
683 1
        $x1 = $x;
684 1
        $x2 = ($maxW / 6);
685 1
        $y += 6;
686 1
        $this->pTextBox($x1, $y, $x2, 12);
687 1
        $texto = 'Qtd. CT-e';
688 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
689 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
690 1
        $texto = str_pad($this->qCTe, 3, '0', STR_PAD_LEFT);
691 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
692 1
        $this->pTextBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
693 1
        $x1 += $x2;
694 1
        $this->pTextBox($x1, $y, $x2, 12);
695 1
        $texto = 'Qtd. NF-e';
696 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
697 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
698 1
        $texto = str_pad($this->qNFe, 3, '0', STR_PAD_LEFT);
699 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
700 1
        $this->pTextBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
701 1
        $x1 += $x2;
702 1
        $this->pTextBox($x1, $y, $x2, 12);
703 1
        $texto = 'Peso Total (Kg)';
704 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
705 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
706 1
        $texto = number_format($this->qCarga, 4, ', ', '.');
707 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
708 1
        $this->pTextBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
709 1
        $x1 = $x;
710 1
        $y += 12;
711 1
        $yold = $y;
712 1
        $x2 = round($maxW / 2, 0);
713 1
        $texto = 'Veículo';
714 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
715 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
716 1
        $y += 5;
717 1
        $x2 = round($maxW / 4, 0);
718 1
        $tamanho = 22;
719
        $this->pTextBox($x1, $y, $x2, $tamanho);
720 1
        $texto = 'Placa';
721 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
722
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
723 1
        $texto = $this->veicTracao->getElementsByTagName("placa")->item(0)->nodeValue;
724 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
725 1
        $this->pTextBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
726
        $altura = $y + 4;
727 1
        /** @var \DOMNodeList $veicReboque */
728 1
        $veicReboque = $this->veicReboque;
729 1
        foreach ($veicReboque as $item) {
730 1
            /** @var \DOMElement $item */
731 1
            $altura += 4;
732
            $texto = $item->getElementsByTagName('placa')->item(0)->nodeValue;
733 1
            $this->pTextBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
734 1
        }
735
        $x1 += $x2;
736
        $this->pTextBox($x1, $y, $x2, $tamanho);
737
        $texto = 'RNTRC';
738 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
739 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
740 1
        // RNTRC Não informado
741
        if ($this->rodo->getElementsByTagName("RNTRC")->length > 0) {
742 1
            $texto = $this->rodo->getElementsByTagName("RNTRC")->item(0)->nodeValue;
743 1
        } else {
744
            $texto = "";
745 1
        }
746 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
747
        $this->pTextBox($x1, $y + 4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
748
        $altura = $y + 4;
749 1
        /** @var \DOMNodeList $veicReboque */
750
        $veicReboque = $this->veicReboque;
751
        foreach ($veicReboque as $item) {
752 1
            /** @var \DOMElement $item */
753 1
            $DOMNodeList = $item->getElementsByTagName('RNTRC');
754 1
            if ($DOMNodeList->length > 0) {
755 1
                $altura += 4;
756 1
                $texto = $DOMNodeList->item(0)->nodeValue;
757 1
                $this->pTextBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
758
            }
759
        }
760
        $x1 = $x;
761 1
        $y += 22;
762 1
        $x2 = round($maxW / 2, 0);
763 1
        $valesPedagios = 1;
764
        $temVales = false;
765 1
        if ($this->valePed != "" && $this->valePed->length > 0) {
766 1
            $valesPedagios = $this->valePed->length;
767 1
            $temVales = true;
768 1
        }
769 1
        $tamanho = ($valesPedagios * 7.5);
770 1
        if (!$temVales) {
771 1
            $valesPedagios = 0;
772 1
        }
773 1
        $this->pTextBox($x1, $y, $x2, 11 + $tamanho / 2);
774 1
        $texto = 'Vale Pedágio';
775 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
776 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
777
        $y += 5;
778
        $x2 = ($x2 / 3);
779
        $this->pTextBox($x1, $y, $x2 - 3, 6 + ($tamanho / 2));
780
        $texto = 'Responsável CNPJ';
781
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
782 1
        $this->pTextBox($x1, $y, $x2 - 4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
783 1
        $altura = $y;
784 1
        for ($i = 0; $i < $valesPedagios; $i++) {
785 1
            $altura += 4;
786 1
            $texto = $this->valePed->item($i)->getElementsByTagName('CNPJForn')->item(0)->nodeValue;
787 1
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
788 1
            $this->pTextBox($x1 + 1, $altura, $x2 - 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
789
        }
790
        $x1 += $x2 - 3;
791
        $this->pTextBox($x1, $y, $x2 - 3, 6 + ($tamanho / 2));
792
        $texto = 'Fornecedora CNPJ';
793
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
794 1
        $this->pTextBox($x1, $y, $x2 - 4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
795 1
        $altura = $y;
796 1
        for ($i = 0; $i < $valesPedagios; $i++) {
797 1
            $altura += 4;
798 1
            $texto = $this->valePed->item($i)->getElementsByTagName('CNPJPg')->item(0)->nodeValue;
799 1
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
800 1
            $this->pTextBox($x1 + 1, $altura, $x2 - 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
801
        }
802
        $x1 += $x2 - 3;
803
        $this->pTextBox($x1, $y, $x2 + 6, 6 + ($tamanho / 2));
804
        $texto = 'Nº Comprovante';
805
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
806 1
        $this->pTextBox($x1, $y, $x2 + 6, 8, $texto, $aFont, 'T', 'L', 0, '', false);
807 1
        $altura = $y;
808
        for ($i = 0; $i < $valesPedagios; $i++) {
809 1
            $altura += 4;
810 1
            $texto = $this->valePed->item($i)->getElementsByTagName('nCompra')->item(0)->nodeValue;
811 1
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
812 1
            $this->pTextBox($x1 + 1, $altura, $x2 + 5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
813 1
        }
814 1
        if (!$temVales) {
815 1
            $altura += 4;
816 1
        }
817 1
        $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...
818 1
        $x1 = round($maxW / 2, 0) + 7;
819 1
        $y = $yold;
820 1
        $x2 = round($maxW / 2, 0);
821 1
        $texto = 'Condutor';
822 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
823 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
824 1
        $y += 5;
825 1
        $x2 = ($maxW / 4);
826 1
        $this->pTextBox($x1, $y, $x2, 33 + ($tamanho / 2));
827 1
        $texto = 'CPF';
828
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
829 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
830 1
        $yold = $y;
831 1
        for ($i = 0; $i < $this->condutor->length; $i++) {
832 1
            $y += 4;
833 1
            $texto = $this->condutor->item($i)->getElementsByTagName('CPF')->item(0)->nodeValue;
834 1
            $aFont = array('font' => $this->fontePadrao, 'size' => 10, 'style' => '');
835 1
            $this->pTextBox($x1 + 1, $y, $x2 - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
836 1
        }
837 1
        $y = $yold;
838 1
        $x1 += $x2;
839 1
        $this->pTextBox($x1, $y, $x2, 33 + ($tamanho / 2));
840
        $texto = 'Nome';
841 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
842
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
843
        for ($i = 0; $i < $this->condutor->length; $i++) {
844
            $y += 4;
845
            $texto = $this->condutor->item($i)->getElementsByTagName('xNome')->item(0)->nodeValue;
846
            $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
847
            $this->pTextBox($x1 + 1, $y, $x2 - 1, 8, $texto, $aFont, 'T', 'L', 0, '', false);
848
        }
849 1
        return $altura + 7;
850
    }
851 1
852 1
853 1
    protected function pQRDAMDFE($y = 0)
854
    {
855 1
856 1
        $margemInterna = $this->margemInterna;
857 1
        $barcode = new Barcode();
858 1
        $bobj = $barcode->getBarcodeObj(
859 1
            'QRCODE,M',
860 1
            $this->qrCodMDFe,
861 1
            -4,
862 1
            -4,
863 1
            'black',
864
            array(-2, -2, -2, -2)
865
        )->setBackgroundColor('white');
866
        $qrcode = $bobj->getPngData();
867
        $wQr = 25;
868
        $hQr = 25;
869
        $yQr = ($y + $margemInterna);
870
        $xQr = 170;
871
        // prepare a base64 encoded "data url"
872 1
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
873
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
874
    }
875 1
876 1
877
    /**
878
     * footerMDFe
879 1
     *
880
     * @param float $x
881 1
     * @param float $y
882
     */
883
    private function footerMDFe($x, $y)
884 1
    {
885
        $maxW = $this->wPrint;
886
        $x2 = $maxW;
887
        $this->pTextBox($x, $y, $x2, 30);
888 1
        $texto = 'Observação
889 1
        ' . $this->infCpl;
890 1
        $aFont = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
891
        $this->pTextBox($x, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
892
        $y = $this->hPrint - 4;
893
        $texto = "Impresso em  " . date('d/m/Y   H:i:s');
894
        $w = $this->wPrint - 4;
895
        $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => 'I');
896 1
        $this->pTextBox($x, $y, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
897
    }//fim footerCCe
898
899
    /**
900
     * printMDFe
901
     *
902
     * @param string $nome
903
     * @param string $destino
904
     * @param string $printer
905
     * @return string
906
     */
907
    public function printMDFe($nome = '', $destino = 'I', $printer = '')
908
    {
909
        //monta
910
        $command = '';
911
        if ($nome == '') {
912
            $file = $this->pdfDir . 'mdfe.pdf';
913
        } else {
914
            $file = $this->pdfDir . $nome;
915
        }
916
        if ($destino != 'I' && $destino != 'S' && $destino != 'F') {
917
            $destino = 'I';
918
        }
919
        if ($printer != '') {
920
            $command = "-P $printer";
921
        }
922
923
        $this->buildMDFe();
924
        $arq = $this->pdf->Output($file, $destino);
925
        if ($destino == 'S' && $command != '') {
926
            //aqui pode entrar a rotina de impressão direta
927
            $command = "lpr $command $file";
928
            system($command, $retorno);
929
        }
930
931
        return $arq;
932
    }//fim printMDFe
933
934
    /**
935
     * Dados brutos do PDF
936
     * @return string
937
     */
938
    public function render()
939
    {
940
        return $this->pdf->getPdf();
941
    }
942
}
943