Completed
Pull Request — master (#164)
by
unknown
16:20 queued 06:48
created

Damdfe::printMDFe()   B

Complexity

Conditions 8
Paths 16

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 10.3696

Importance

Changes 0
Metric Value
cc 8
nc 16
nop 3
dl 0
loc 26
ccs 10
cts 15
cp 0.6667
crap 10.3696
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\MDFe;
4
5
/**
6
 * Esta classe gera do PDF do MDFDe, conforme regras e estruturas
7
 * estabelecidas pela SEFAZ.
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @name      Damdfe.php
12
 * @copyright 2009-2016 NFePHP
13
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
14
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
15
 * @author    Leandro C. Lopez <leandro dot castoldi at gmail dot com>
16
 */
17
18
use NFePHP\DA\Legacy\Dom;
19
use NFePHP\DA\Legacy\Common;
20
use NFePHP\DA\Legacy\Pdf;
21
22
class Damdfe extends Common
23
{
24
    //publicas
25
    public $logoAlign='L'; //alinhamento do logo
26
    public $yDados=0;
27
    public $debugMode=0; //ativa ou desativa o modo de debug
28
    //privadas
29
    protected $pdf; // objeto fpdf()
30
    protected $xml; // string XML NFe
31
    protected $logomarca=''; // path para logomarca em jpg
32
    protected $errMsg=''; // mesagens de erro
33
    protected $errStatus=false;// status de erro TRUE um erro ocorreu false sem erros
34
    protected $orientacao='P'; //orientação da DANFE P-Retrato ou L-Paisagem
35
    protected $papel='A4'; //formato do papel
36
    //destivo do arquivo pdf I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
37
    protected $destino = 'I';
38
    protected $pdfDir=''; //diretorio para salvar o pdf com a opção de destino = F
39
    protected $fontePadrao='Times'; //Nome da Fonte para gerar o DANFE
40
    protected $version = '1.0.0';
41
    protected $wPrint; //largura imprimivel
42
    protected $hPrint; //comprimento imprimivel
43
    protected $formatoChave="#### #### #### #### #### #### #### #### #### #### ####";
44
    //variaveis da carta de correção
45
    protected $id;
46
    protected $chMDFe;
47
    protected $tpAmb;
48
    protected $cOrgao;
49
    protected $xCondUso;
50
    protected $dhEvento;
51
    protected $cStat;
52
    protected $xMotivo;
53
    protected $CNPJDest = '';
54
    protected $dhRegEvento;
55
    protected $nProt;
56
    protected $tpEmis;
57
    //objetos
58
    private $dom;
59
    private $procEventoNFe;
0 ignored issues
show
Unused Code introduced by
The property $procEventoNFe is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
60
    private $evento;
0 ignored issues
show
Unused Code introduced by
The property $evento is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
61
    private $infEvento;
0 ignored issues
show
Unused Code introduced by
The property $infEvento is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
62
    private $retEvento;
0 ignored issues
show
Unused Code introduced by
The property $retEvento is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
63
    private $rinfEvento;
0 ignored issues
show
Unused Code introduced by
The property $rinfEvento is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
64
    /**
65
     * __construct
66
     *
67
     * @param string $xmlfile Arquivo XML da MDFe
68
     * @param string $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
69
     * @param string $sPapel Tamanho do papel (Ex. A4)
70
     * @param string $sPathLogo Caminho para o arquivo do logo
71
     * @param string $sDestino Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
72
     * @param string $sDirPDF Caminho para o diretorio de armazenamento dos arquivos PDF
73
     * @param string $fonteDAMDFE Nome da fonte alternativa do DAnfe
0 ignored issues
show
Bug introduced by
There is no parameter named $fonteDAMDFE. Was it maybe removed?

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

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

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

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

Loading history...
74
     * @param integer $mododebug 0-Não 1-Sim e 2-nada (2 default)
75
     */
76 1
    public function __construct(
77
        $xmlfile = '',
78
        $sOrientacao = '',
79
        $sPapel = '',
80
        $sPathLogo = '',
81
        $sDestino = 'I',
82
        $sDirPDF = '',
83
        $fontePDF = '',
84
        $mododebug = 2
85
    ) {
86
        //define o caminho base da instalação do sistema
87 1
        if (!defined('PATH_ROOT')) {
88 1
            define('PATH_ROOT', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR);
89
        }
90
//ajuste do tempo limite de resposta do processo
91 1
        set_time_limit(1800);
92
//definição do caminho para o diretorio com as fontes do FDPF
93 1
        if (!defined('FPDF_FONTPATH')) {
94 1
            define('FPDF_FONTPATH', 'font/');
95
        }
96
97 1
        if (is_numeric($mododebug)) {
98 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...
99
        }
100 1
        if ($this->debugMode) {
101
            //ativar modo debug
102
            error_reporting(E_ALL);
103
            ini_set('display_errors', 'On');
104
        } else {
105
            //desativar modo debug
106 1
            error_reporting(0);
107 1
            ini_set('display_errors', 'Off');
108
        }
109 1
        $this->orientacao   = $sOrientacao;
110 1
        $this->papel        = $sPapel;
111 1
        $this->pdf          = '';
112 1
        $this->xml          = $xmlfile;
113 1
        $this->logomarca    = $sPathLogo;
114 1
        $this->destino      = $sDestino;
115 1
        $this->pdfDir       = $sDirPDF;
116
        // verifica se foi passa a fonte a ser usada
117 1
        if (empty($fontePDF)) {
118 1
            $this->fontePadrao = 'Times';
119
        } else {
120
            $this->fontePadrao = $fontePDF;
121
        }
122
        //se for passado o xml
123 1
        if (empty($xmlfile)) {
124
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
125
            $this->errStatus = true;
126
        }
127 1
        if (!is_file($xmlfile)) {
128 1
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
129 1
            $this->errStatus = true;
130
        }
131
132
//        $docxml = file_get_contents($xmlfile);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
133 1
        $this->dom = new Dom();
134 1
        $this->dom->loadXML($this->xml);
135 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...
136 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...
137 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...
138 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...
139 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...
140 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...
141 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...
142 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...
143 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...
144 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...
145 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...
146 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...
147 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...
148 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...
149 1
        $this->tpAmb = $this->dom->getElementsByTagName("tpAmb")->item(0)->nodeValue;
150 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...
151 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...
152 1
        $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...
153 1
        $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...
154 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...
155 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...
156 1
        $this->tpEmis = $this->dom->getElementsByTagName("tpEmis")->item(0)->nodeValue;
157 1
        $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...
158 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...
159 1
        if ($this->dom->getElementsByTagName("qNFe")->item(0) != "") {
160
            $this->qNFe = $this->dom->getElementsByTagName("qNFe")->item(0)->nodeValue;
161
        }
162 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...
163 1
        if ($this->dom->getElementsByTagName("qNF")->item(0) != "") {
164
            $this->qNF = $this->dom->getElementsByTagName("qNF")->item(0)->nodeValue;
165
        }
166 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...
167 1
        if ($this->dom->getElementsByTagName("qCTe")->item(0) != "") {
168 1
            $this->qCTe = $this->dom->getElementsByTagName("qCTe")->item(0)->nodeValue;
169
        }
170 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...
171 1
        if ($this->dom->getElementsByTagName("qCT")->item(0) != "") {
172
            $this->qCT = $this->dom->getElementsByTagName("qCT")->item(0)->nodeValue;
173
        }
174 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...
175 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...
176 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...
177 1
        $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...
178 1
        if ($this->dom->getElementsByTagName('CIOT')->item(0) != "") {
179
            $this->ciot = $this->dom->getElementsByTagName('CIOT')->item(0)->nodeValue;
180
        }
181 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...
182 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...
183 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...
184 1
        if ($this->dom->getElementsByTagName("valePed")->item(0) != "") {
185
            $this->valePed = $this->dom->getElementsByTagName("valePed")->item(0)->getElementsByTagName("disp");
186
        }
187 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...
188 1
        $this->chMDFe = str_replace(
189 1
            'MDFe',
190 1
            '',
191 1
            $this->infMDFe->getAttribute("Id")
192
        );
193 1
        if (is_object($this->mdfeProc)) {
194 1
            $this->nProt = ! empty($this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
195 1
                    $this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
196 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...
197
        }
198 1
        $this->modal = $this->dom->getElementsByTagName("modal")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property modal 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...
199
        
200 1
        if ($this->modal == '2') {
201
            $this->nac = $this->dom->getElementsByTagName("nac")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property nac 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...
202
            $this->matr = $this->dom->getElementsByTagName("matr")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property matr 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...
203
            $this->nVoo = $this->dom->getElementsByTagName("nVoo")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property nVoo 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...
204
            $this->cAerEmb = $this->dom->getElementsByTagName("cAerEmb")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property cAerEmb 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...
205
            $this->cAerDes = $this->dom->getElementsByTagName("cAerDes")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property cAerDes 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...
206
            $this->dVoo = $this->dom->getElementsByTagName("dVoo")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property dVoo 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
    /**
210
     *buildMDFe
211
     *
212
     */
213 1
    public function buildMDFe()
214
    {
215 1
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
216 1
        if ($this->orientacao == 'P') {
217
            // margens do PDF
218 1
            $margSup = 7;
219 1
            $margEsq = 7;
220 1
            $margDir = 7;
221
            // posição inicial do relatorio
222 1
            $xInic = 7;
223 1
            $yInic = 7;
224 1
            if ($this->papel =='A4') { //A4 210x297mm
225 1
                $maxW = 210;
226 1
                $maxH = 297;
227
            }
228
        } else {
229
            // margens do PDF
230
            $margSup = 7;
231
            $margEsq = 7;
232
            $margDir = 7;
233
            // posição inicial do relatorio
234
            $xInic = 7;
235
            $yInic = 7;
236
            if ($this->papel =='A4') { //A4 210x297mm
237
                $maxH = 210;
238
                $maxW = 297;
239
            }
240
        }//orientação
241
        //largura imprimivel em mm
242 1
        $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...
243
        //comprimento imprimivel em mm
244 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...
245
        // estabelece contagem de paginas
246 1
        $this->pdf->AliasNbPages();
247
        // fixa as margens
248 1
        $this->pdf->SetMargins($margEsq, $margSup, $margDir);
249 1
        $this->pdf->SetDrawColor(0, 0, 0);
250 1
        $this->pdf->SetFillColor(255, 255, 255);
251
        // inicia o documento
252 1
        $this->pdf->Open();
253
        // adiciona a primeira página
254 1
        $this->pdf->AddPage($this->orientacao, $this->papel);
255 1
        $this->pdf->SetLineWidth(0.1);
256 1
        $this->pdf->SetTextColor(0, 0, 0);
257
        //montagem da página
258 1
        $pag = 1;
259 1
        $x = $xInic;
260 1
        $y = $yInic;
261
        //coloca o cabeçalho Paisagem
262 1
        if ($this->orientacao == 'P') {
263 1
            $y = $this->headerMDFeRetrato($x, $y, $pag);
264
        } else {
265
            $y = $this->headerMDFePaisagem($x, $y, $pag);
266
        }
267
        //coloca os dados da MDFe
268 1
        $y = $this->bodyMDFe($x, $y);
269
        //coloca os dados da MDFe
270 1
        $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 1
    } //fim buildCCe
272
    /**
273
     * headerMDFePaisagem
274
     * @param float $x
275
     * @param float $y
276
     * @param integer $pag
277
     * @return string
278
     */
279
    private function headerMDFePaisagem($x, $y, $pag)
0 ignored issues
show
Unused Code introduced by
The parameter $pag is not used and could be removed.

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

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

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

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

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

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

Loading history...
282
        $oldY = $y;
283
        $maxW = $this->wPrint;
284
        //####################################################################################
285
        //coluna esquerda identificação do emitente
286
        $w = $maxW; //round($maxW*0.41, 0);// 80;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
287
        $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...
288
        $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...
289
        $h=30;
290
        $oldY += $h;
291
        $this->pTextBox($x, $y, $w, $h);
292
        if (is_file($this->logomarca)) {
293
            $logoInfo = getimagesize($this->logomarca);
294
            //largura da imagem em mm
295
            $logoWmm = ($logoInfo[0]/72)*25.4;
296
            //altura da imagem em mm
297
            $logoHmm = ($logoInfo[1]/72)*25.4;
298
            if ($this->logoAlign=='L') {
299
                $nImgW = round($w/4.5, 0);
300
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
301
                $xImg = $x+1;
302
                $yImg = round(($h-$nImgH)/2, 0)+$y;
303
                //estabelecer posições do texto
304
                $x1 = round($xImg + $nImgW +1, 0);
305
                $y1 = round($y+2, 0);
306
                $tw = round(2*$w/3, 0);
307
            }
308
            if ($this->logoAlign=='C') {
309
                $nImgH = round($h/3, 0);
310
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
311
                $xImg = round(($w-$nImgW)/2+$x, 0);
312
                $yImg = $y+3;
313
                $x1 = $x;
314
                $y1 = round($yImg + $nImgH + 1, 0);
315
                $tw = $w;
316
            }
317
            if ($this->logoAlign=='R') {
318
                $nImgW = round($w/3, 0);
319
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
320
                $xImg = round($x+($w-(1+$nImgW)), 0);
321
                $yImg = round(($h-$nImgH)/2, 0)+$y;
322
                $x1 = $x;
323
                $y1 = round($h/3+$y, 0);
324
                $tw = round(2*$w/3, 0);
325
            }
326
            $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...
327
        } else {
328
            $x1 = $x;
329
            $y1 = round($h/3+$y, 0);
330
            $tw = $w;
331
        }
332
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
333
        $razao = $this->xNome;
334
        $cnpj = 'CNPJ: '.$this->pFormat($this->CNPJ, "###.###.###/####-##");
335
        $ie = 'IE: '.$this->pFormat($this->IE, '##/########');
336
        $lgr = 'Logradouro: '.$this->xLgr;
337
        $nro = 'Nº: '.$this->nro;
338
        $bairro = 'Bairro: '.$this->xBairro;
339
        $CEP = $this->CEP;
340
        $CEP = 'CEP: '.$this->pFormat($CEP, "##.###-###");
341
        $UF = 'UF: '.$this->UF;
342
        $mun = 'Municipio: '.$this->xMun;
343
        
344
        $texto = $razao . "\n" . $cnpj . ' - ' . $ie . "\n";
345
        $texto .= $lgr . ' - ' . $nro . "\n";
346
        $texto .= $bairro . "\n";
347
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
348
        $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...
349
        $x = $x+$maxW/2;
350
        $w = $maxW / 2;
351
        $this->pTextBox($x, $y, $w, $h);
352
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'I');
353
        $this->pTextBox(
354
            $x,
355
            $y,
356
            $w,
357
            8,
358
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
359
            $aFont,
360
            'T',
361
            'C',
362
            0,
363
            ''
364
        );
365
        $this->pTextBox($x, $y, $w, 6);
366
        $bH = 13;
367
        $bW = round(($w), 0);
368
        $this->pdf->SetFillColor(0, 0, 0);
369
        $this->pdf->Code128($x+5, $y+7.5, $this->chMDFe, $bW-10, $bH);
370
        $this->pdf->SetFillColor(255, 255, 255);
371
        $y = $y + 22;
372
        $this->pTextBox($x, $y, $w, 8);
373
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
374
        $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...
375
        $texto = 'CHAVE DE ACESSO';
376
        $this->pTextBox($x, $y, $maxW, 6, $texto, $aFont, 'T', 'L', 0, '');
377
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
378
        $texto = $this->pFormat($this->chMDFe, $this->formatoChave);
379
        $this->pTextBox($x, $y+3, $w, 6, $texto, $aFont, 'T', 'C', 0, '');
380
        $y = $y + 11;
381
        $this->pTextBox($x, $y, $w, 12);
382
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
383
        $texto = 'PROTOCOLO DE AUTORIZACAO DE USO';
384
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
385
        
386
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
387
        if (is_object($this->mdfeProc)) {
388
            $tsHora = $this->pConvertTime($this->dhRecbto);
389
            $texto = $this->nProt.' - '.date('d/m/Y   H:i:s', $tsHora);
390
        } else {
391
            $texto = 'DAMDFE impresso em contingência - '.date('d/m/Y   H:i:s');
392
        }
393
        $this->pTextBox($x, $y+4, $w, 8, $texto, $aFont, 'T', 'C', 0, '');
394
        if ($this->tpAmb != 1) {
395
            $x = 10;
396
            if ($this->orientacao == 'P') {
397
                $yy = round($this->hPrint*2/3, 0);
398
            } else {
399
                $yy = round($this->hPrint/2, 0);
400
            }
401
            $h = 5;
402
            $w = $maxW-(2*$x);
403
            $this->pdf->SetTextColor(90, 90, 90);
404
            $texto = "SEM VALOR FISCAL";
405
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
406
            $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
407
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
408
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
409
            $this->pTextBox($x, $yy+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
410
            $this->pdf->SetTextColor(0, 0, 0);
411
        } else {
412
            $x = 10;
413
            if ($this->orientacao == 'P') {
414
                $yy = round($this->hPrint*2/3, 0);
415
            } else {
416
                $yy = round($this->hPrint/2, 0);
417
            }//fim orientacao
418
            $h = 5;
419
            $w = $maxW-(2*$x);
420
            $this->pdf->SetTextColor(90, 90, 90);
421
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
422
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
423
                //Contingência
424
                $texto = "DAMDFE Emitido em Contingência";
425
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
426
                $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
427
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
428
                $texto = "devido à problemas técnicos";
429
                $this->pTextBox($x, $yy+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
430
            }
431
            $this->pdf->SetTextColor(0, 0, 0);
432
        }
433
        return $y;
434
    }// fim headerMDFe
435
    
436
    /**
437
     * headerMDFeRetrato
438
     *
439
     * @param float $x
440
     * @param float $y
441
     * @param integer $pag
442
     * @return string
443
     */
444 1
    private function headerMDFeRetrato($x, $y, $pag)
0 ignored issues
show
Unused Code introduced by
The parameter $pag is not used and could be removed.

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

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

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

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

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

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

Loading history...
447 1
        $oldY = $y;
448 1
        $maxW = $this->wPrint;
449
        //####################################################################################
450
        //coluna esquerda identificação do emitente
451 1
        $w = $maxW; //round($maxW*0.41, 0);// 80;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
452 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
0 ignored issues
show
Unused Code introduced by
$aFont is not used, you could remove the assignment.

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

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

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

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

Loading history...
453 1
        $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...
454 1
        $h=20;
455 1
        $oldY += $h;
456 1
        $this->pTextBox($x, $y, $w, $h);
457 1
        if (is_file($this->logomarca)) {
458
            $logoInfo = getimagesize($this->logomarca);
459
            //largura da imagem em mm
460
            $logoWmm = ($logoInfo[0]/72)*25.4;
461
            //altura da imagem em mm
462
            $logoHmm = ($logoInfo[1]/72)*25.4;
463
            if ($this->logoAlign=='L') {
464
                $nImgW = round($w/8, 0);
465
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
466
                $xImg = $x+1;
467
                $yImg = round(($h-$nImgH)/2, 0)+$y;
468
                //estabelecer posições do texto
469
                $x1 = round($xImg + $nImgW +1, 0);
470
                $y1 = round($y+2, 0);
471
                $tw = round(2*$w/3, 0);
472
            }
473
            if ($this->logoAlign=='C') {
474
                $nImgH = round($h/3, 0);
475
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
476
                $xImg = round(($w-$nImgW)/2+$x, 0);
477
                $yImg = $y+3;
478
                $x1 = $x;
479
                $y1 = round($yImg + $nImgH + 1, 0);
480
                $tw = $w;
481
            }
482
            if ($this->logoAlign=='R') {
483
                $nImgW = round($w/3, 0);
484
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
485
                $xImg = round($x+($w-(1+$nImgW)), 0);
486
                $yImg = round(($h-$nImgH)/2, 0)+$y;
487
                $x1 = $x;
488
                $y1 = round($h/3+$y, 0);
489
                $tw = round(2*$w/3, 0);
490
            }
491
            $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...
492
        } else {
493 1
            $x1 = $x+40;
494 1
            $y1 = $y;
495 1
            $tw = $w;
496
        }
497 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
498 1
        $razao = $this->xNome;
499 1
        $cnpj = 'CNPJ: '.$this->pFormat($this->CNPJ, "###.###.###/####-##");
500 1
        $ie = 'IE: '.$this->pFormat($this->IE, '###/#######');
501 1
        $lgr = 'Logradouro: '.$this->xLgr;
502 1
        $nro = 'Nº: '.$this->nro;
503 1
        $bairro = 'Bairro: '.$this->xBairro;
504 1
        $CEP = $this->CEP;
505 1
        $CEP = 'CEP: '.$this->pFormat($CEP, "##.###-###");
506 1
        $mun = 'Municipio: '.$this->xMun;
507 1
        $UF = 'UF: '.$this->UF;
508 1
        $texto = $razao . "\n" . $cnpj . ' - ' . $ie . "\n";
509 1
        $texto .= $lgr . ' - ' . $nro . "\n";
510 1
        $texto .= $bairro . "\n";
511 1
        $texto .= $UF . ' - ' . $mun . ' - ' . $CEP;
512 1
        $this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
513
        //##################################################
514 1
        $y = $h + 8;
515 1
        $this->pTextBox($x, $y, $maxW, 6);
516 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'I');
517 1
        $this->pTextBox(
518
            $x,
519
            $y,
520
            $maxW,
521 1
            8,
522 1
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
523
            $aFont,
524 1
            'T',
525 1
            'C',
526 1
            0,
527 1
            ''
528
        );
529 1
        $y = $y + 8;
530 1
        $this->pTextBox($x, $y, $maxW, 20);
531 1
        $bH = 16;
532 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...
533 1
        $this->pdf->SetFillColor(0, 0, 0);
534 1
        $this->pdf->Code128($x + 5, $y+2, $this->chMDFe, $maxW - 10, $bH);
535 1
        $this->pdf->SetFillColor(255, 255, 255);
536 1
        $y = $y + 22;
537 1
        $this->pTextBox($x, $y, $maxW, 10);
538 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
539 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...
540 1
        $texto = 'CHAVE DE ACESSO';
541 1
        $this->pTextBox($x, $y, $maxW, 6, $texto, $aFont, 'T', 'L', 0, '');
542 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
543 1
        $texto = $this->pFormat($this->chMDFe, $this->formatoChave);
544 1
        $this->pTextBox($x, $y+4, $maxW, 6, $texto, $aFont, 'T', 'C', 0, '');
545 1
        $y = $y + 12;
546 1
        $this->pTextBox($x, $y, $maxW, 10);
547 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
548 1
        $texto = 'PROTOCOLO DE AUTORIZACAO DE USO';
549 1
        $this->pTextBox($x, $y, $maxW, 8, $texto, $aFont, 'T', 'L', 0, '');
550 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
551 1
        if (is_object($this->mdfeProc)) {
552 1
            $tsHora = $this->pConvertTime($this->dhRecbto);
553 1
            $texto = $this->nProt.' - '.date('d/m/Y   H:i:s', $tsHora);
554
        } else {
555
            $texto = 'DAMDFE impresso em contingência - '.date('d/m/Y   H:i:s');
556
        }
557 1
        $this->pTextBox($x, $y+4, $maxW, 8, $texto, $aFont, 'T', 'C', 0, '');
558 1
        if ($this->tpAmb != 1) {
559 1
            $x = 10;
560 1
            if ($this->orientacao == 'P') {
561 1
                $yy = round($this->hPrint*2/3, 0);
562
            } else {
563
                $yy = round($this->hPrint/2, 0);
564
            }
565 1
            $h = 5;
566 1
            $w = $maxW-(2*$x);
567 1
            $this->pdf->SetTextColor(90, 90, 90);
568 1
            $texto = "SEM VALOR FISCAL";
569 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
570 1
            $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
571 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
572 1
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
573 1
            $this->pTextBox($x, $yy+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
574 1
            $this->pdf->SetTextColor(0, 0, 0);
575
        } else {
576
            $x = 10;
577
            if ($this->orientacao == 'P') {
578
                $yy = round($this->hPrint*2/3, 0);
579
            } else {
580
                $yy = round($this->hPrint/2, 0);
581
            }//fim orientacao
582
            $h = 5;
583
            $w = $maxW-(2*$x);
584
            $this->pdf->SetTextColor(90, 90, 90);
585
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
586
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
587
                //Contingência
588
                $texto = "DAMDFE Emitido em Contingência";
589
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
590
                $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
591
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
592
                $texto = "devido à problemas técnicos";
593
                $this->pTextBox($x, $yy+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
594
            }
595
            $this->pdf->SetTextColor(0, 0, 0);
596
        }
597 1
        return $y+12;
598
    }// fim headerMDFe
599
    
600
    /**
601
     * bodyMDFe
602
     *
603
     * @param float $x
604
     * @param float $y
605
     * @return void
606
     */
607 1
    private function bodyMDFe($x, $y)
608
    {
609 1
        if ($this->orientacao == 'P') {
610 1
            $maxW = $this->wPrint;
611
        } else {
612
            $maxW = $this->wPrint / 2;
613
        }
614 1
        $x2 = ($maxW / 6);
615 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...
616 1
        $this->pTextBox($x, $y, $x2-7, 12);
617 1
        $texto = 'Modelo';
618 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
619 1
        $this->pTextBox($x, $y, $x2-7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
620 1
        $texto = $this->mod;
621 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
622 1
        $this->pTextBox($x, $y+4, $x2-7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
623 1
        $x1 = $x2;
624 1
        $this->pTextBox($x1, $y, $x2-7, 12);
625 1
        $texto = 'Série';
626 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
627 1
        $this->pTextBox($x1, $y, $x2-7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
628 1
        $texto = $this->serie;
629 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
630 1
        $this->pTextBox($x1, $y+4, $x2-7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
631 1
        $x1 += $x2-7;
632 1
        $this->pTextBox($x1, $y, $x2+5, 12);
633 1
        $texto = 'Número';
634 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
635 1
        $this->pTextBox($x1, $y, $x2+5, 8, $texto, $aFont, 'T', 'L', 0, '', false);
636 1
        $texto = $this->pFormat(str_pad($this->nMDF, 9, '0', STR_PAD_LEFT), '###.###.###');
637 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
638 1
        $this->pTextBox($x1, $y+4, $x2+5, 10, $texto, $aFont, 'T', 'C', 0, '', false);
639 1
        $x1 += $x2+5;
640 1
        $this->pTextBox($x1, $y, $x2-7, 12);
641 1
        $texto = 'FL';
642 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
643 1
        $this->pTextBox($x1, $y, $x2-7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
644 1
        $texto = '1';
645 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
646 1
        $this->pTextBox($x1, $y+4, $x2-7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
647 1
        $x1 += $x2-7;
648 1
        $this->pTextBox($x1, $y, $x2+11, 12);
649 1
        $texto = 'Data e Hora de Emissão';
650 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
651 1
        $this->pTextBox($x1, $y, $x2+11, 8, $texto, $aFont, 'T', 'L', 0, '', false);
652 1
        $data = explode('T', $this->dhEmi);
653 1
        $texto = $this->pYmd2dmy($data[0]).' - '.$data[1];
654 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
655 1
        $this->pTextBox($x1, $y+4, $x2+11, 10, $texto, $aFont, 'T', 'C', 0, '', false);
656 1
        $x1 += $x2+11;
657 1
        $this->pTextBox($x1, $y, $x2-15, 12);
658 1
        $texto = 'UF Carreg.';
659 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
660 1
        $this->pTextBox($x1, $y, $x2-15, 8, $texto, $aFont, 'T', 'L', 0, '', false);
661 1
        $texto = $this->UFIni;
662 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
663 1
        $this->pTextBox($x1, $y+4, $x2-15, 10, $texto, $aFont, 'T', 'C', 0, '', false);
664 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...
665
666 1
        $x1 += $x2-15;
667 1
        $this->pTextBox($x1, $y, $x2-13, 12);
668 1
        $texto = 'UF Descar.';
669 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
670 1
        $this->pTextBox($x1, $y, $x2-13, 8, $texto, $aFont, 'T', 'L', 0, '', false);
671 1
        $texto = $this->UFFim;
672 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
673 1
        $this->pTextBox($x1, $y+4, $x2-13, 10, $texto, $aFont, 'T', 'C', 0, '', false);
674 1
        $maxW = $this->wPrint;
675
676 1
        $x1 = $x;
677 1
        $x2 = $maxW;
678 1
        $y += 14;
679
680 1
        if ($this->modal == '1') {
681 1
            $this->pTextBox($x1, $y, $x2, 23);
682 1
            $texto = 'Modal Rodoviário de Carga';
683
        } elseif ($this->modal == '2') {
684
            $this->pTextBox($x1, $y, $x2, 18);
685
            $texto = 'Modal Aéreo de Carga';
686
        }
687
688 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
689 1
        $this->pTextBox($x1, $y+1, $x2, 8, $texto, $aFont, 'T', 'C', 0, '', false);
690 1
        $x1 = $x;
691 1
        $x2 = ($maxW / 6);
692 1
        $y += 6;
693 1
        $this->pTextBox($x1, $y, $x2, 12);
694 1
        $texto = 'Qtd. CT-e';
695 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
696 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
697 1
        $texto = str_pad($this->qCTe, 3, '0', STR_PAD_LEFT);
698 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
699 1
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
700 1
        $x1 += $x2;
701 1
        $this->pTextBox($x1, $y, $x2, 12);
702 1
        $texto = 'Qtd. NF-e';
703 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
704 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
705 1
        $texto = str_pad($this->qNFe, 3, '0', STR_PAD_LEFT);
706 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
707 1
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
708 1
        $x1 += $x2;
709 1
        $this->pTextBox($x1, $y, $x2, 12);
710 1
        $texto = 'Peso Total (Kg)';
711 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
712 1
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
713 1
        $texto = number_format($this->qCarga, 4, ', ', '.');
714 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
715 1
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
716
717 1
        $altura = $y;
718 1
        if ($this->modal == '1') {
719 1
            $x1 = $x;
720 1
            $y += 12;
721 1
            $yold = $y;
722 1
            $x2 = round($maxW / 2, 0);
723 1
            $texto = 'Veículo';
724 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
725 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
726 1
            $y += 5;
727 1
            $x2 = round($maxW / 4, 0);
728 1
            $tamanho = 22;
729 1
            $this->pTextBox($x1, $y, $x2, $tamanho);
730 1
            $texto = 'Placa';
731 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
732 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
733 1
            $texto = $this->veicTracao->getElementsByTagName("placa")->item(0)->nodeValue;
734 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
735 1
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
736 1
            $altura = $y + 4;
737
            /** @var \DOMNodeList $veicReboque */
738 1
            $veicReboque = $this->veicReboque;
739 1
            foreach ($veicReboque as $item) {
740
                /** @var \DOMElement $item */
741 1
                $altura += 4;
742 1
                $texto = $item->getElementsByTagName('placa')->item(0)->nodeValue;
743 1
                $this->pTextBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
744
            }
745 1
            $x1 += $x2;
746 1
            $this->pTextBox($x1, $y, $x2, $tamanho);
747 1
            $texto = 'RNTRC';
748 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
749 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
750
            // RNTRC Não informado
751 1
            if ($this->rodo->getElementsByTagName("RNTRC")->length > 0) {
752 1
                $texto = $this->rodo->getElementsByTagName("RNTRC")->item(0)->nodeValue;
753
            } else {
754
                $texto = "";
755
            }
756 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
757 1
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
758 1
            $altura = $y + 4;
759
            /** @var \DOMNodeList $veicReboque */
760 1
            $veicReboque = $this->veicReboque;
761 1
            foreach ($veicReboque as $item) {
762
                /** @var \DOMElement $item */
763 1
                $DOMNodeList = $item->getElementsByTagName('RNTRC');
764 1
                if ($DOMNodeList->length > 0) {
765
                    $altura += 4;
766
                    $texto = $DOMNodeList->item(0)->nodeValue;
767 1
                    $this->pTextBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
768
                }
769
            }
770 1
            $x1 = $x;
771 1
            $y += 22;
772 1
            $x2 = round($maxW / 2, 0);
773 1
            $valesPedagios = 1;
774 1
            $temVales = false;
775 1
            if ($this->valePed != "" && $this->valePed->length > 0) {
776
                $valesPedagios = $this->valePed->length;
777
                $temVales = true;
778
            }
779 1
            $tamanho = ($valesPedagios * 7.5);
780 1
            if (!$temVales) {
781 1
                $valesPedagios = 0;
782
            }
783 1
            $this->pTextBox($x1, $y, $x2, 11+$tamanho/2);
784 1
            $texto = 'Vale Pedágio';
785 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
786 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
787 1
            $y += 5;
788 1
            $x2 = ($x2 / 3);
789 1
            $this->pTextBox($x1, $y, $x2-3, 6+($tamanho/2));
790 1
            $texto = 'Responsável CNPJ';
791 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
792 1
            $this->pTextBox($x1, $y, $x2-4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
793 1
            $altura = $y;
794 1
            for ($i = 0; $i < $valesPedagios; $i++) {
795
                $altura += 4;
796
                $texto = $this->valePed->item($i)->getElementsByTagName('CNPJForn')->item(0)->nodeValue;
797
                $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
798
                $this->pTextBox($x1 + 1, $altura, $x2-5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
799
            }
800 1
            $x1 += $x2-3;
801 1
            $this->pTextBox($x1, $y, $x2-3, 6+($tamanho/2));
802 1
            $texto = 'Fornecedora CNPJ';
803 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
804 1
            $this->pTextBox($x1, $y, $x2-4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
805 1
            $altura = $y;
806 1
            for ($i = 0; $i < $valesPedagios; $i++) {
807
                $altura += 4;
808
                $texto = $this->valePed->item($i)->getElementsByTagName('CNPJPg')->item(0)->nodeValue;
809
                $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
810
                $this->pTextBox($x1 + 1, $altura, $x2-5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
811
            }
812 1
            $x1 += $x2-3;
813 1
            $this->pTextBox($x1, $y, $x2+6, 6+($tamanho/2));
814 1
            $texto = 'Nº Comprovante';
815 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
816 1
            $this->pTextBox($x1, $y, $x2+6, 8, $texto, $aFont, 'T', 'L', 0, '', false);
817 1
            $altura = $y;
818 1
            for ($i = 0; $i < $valesPedagios; $i++) {
819
                $altura += 4;
820
                $texto = $this->valePed->item($i)->getElementsByTagName('nCompra')->item(0)->nodeValue;
821
                $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
822
                $this->pTextBox($x1 + 1, $altura, $x2+5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
823
            }
824 1
            if (!$temVales) {
825 1
                $altura += 4;
826
            }
827 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...
828 1
            $x1 = round($maxW / 2, 0) + 7;
829 1
            $y = $yold;
830 1
            $x2 = round($maxW / 2, 0);
831 1
            $texto = 'Condutor';
832 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
833 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
834 1
            $y += 5;
835 1
            $x2 = ($maxW / 4);
836 1
            $this->pTextBox($x1, $y, $x2, 33+($tamanho/2));
837 1
            $texto = 'CPF';
838 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
839 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
840 1
            $yold = $y;
841 1
            for ($i = 0; $i < $this->condutor->length; $i++) {
842 1
                $y += 4;
843 1
                $texto = $this->condutor->item($i)->getElementsByTagName('CPF')->item(0)->nodeValue;
844 1
                $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
845 1
                $this->pTextBox($x1 + 1, $y, $x2 - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
846
            }
847 1
            $y = $yold;
848 1
            $x1 += $x2;
849 1
            $this->pTextBox($x1, $y, $x2, 33+($tamanho/2));
850 1
            $texto = 'Nome';
851 1
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
852 1
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
853 1
            for ($i = 0; $i < $this->condutor->length; $i++) {
854 1
                $y += 4;
855 1
                $texto = $this->condutor->item($i)->getElementsByTagName('xNome')->item(0)->nodeValue;
856 1
                $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
857 1
                $this->pTextBox($x1 + 1, $y, $x2 - 1, 8, $texto, $aFont, 'T', 'L', 0, '', false);
858
            }
859
        } elseif ($this->modal == '2') {
860
            $x1 = $x;
861
            $y += 12;
862
            $x2 = round($maxW / 2, 0);
863
            $this->pTextBox($x1, $y, $x2, 12);
864
            $texto = 'Marca da aeronave';
865
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
866
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
867
            $texto = $this->nac;
868
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
869
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
870
            $x1 += $x2;
871
            $this->pTextBox($x1, $y, $x2, 12);
872
            $texto = 'Matrícula da aeronave';
873
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
874
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
875
            $texto = $this->matr;
876
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
877
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
878
            $altura = $y + 4;
0 ignored issues
show
Unused Code introduced by
$altura 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...
879
            $x1 = $x;
880
            $y += 12;
881
            $this->pTextBox($x1, $y, $x2, 12);
882
            $texto = 'Número do vôo';
883
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
884
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
885
            $texto = $this->nVoo;
886
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
887
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
888
            $x1 += $x2;
889
            $this->pTextBox($x1, $y, $x2, 12);
890
            $texto = 'Data do vôo';
891
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
892
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
893
            $texto = $this->pYmd2dmy($this->dVoo);
894
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
895
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
896
            $altura = $y + 4;
0 ignored issues
show
Unused Code introduced by
$altura is not used, you could remove the assignment.

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

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

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

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

Loading history...
897
            $x1 = $x;
898
            $y += 12;
899
            $this->pTextBox($x1, $y, $x2, 12);
900
            $texto = 'Aeródromo de embarque';
901
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
902
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
903
            $texto = $this->cAerEmb;
904
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
905
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
906
            $x1 += $x2;
907
            $this->pTextBox($x1, $y, $x2, 12);
908
            $texto = 'Aeródromo de desembarque';
909
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
910
            $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
911
            $texto = $this->cAerDes;
912
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
913
            $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
914
            $altura = $y + 7;
915
        }
916
        
917 1
        return $altura + 7;
918
    }//fim bodyMDFe
919
    /**
920
     * footerMDFe
921
     *
922
     * @param float $x
923
     * @param float $y
924
     */
925 1
    private function footerMDFe($x, $y)
926
    {
927 1
        $maxW = $this->wPrint;
928 1
        $x2 = $maxW;
929 1
        $this->pTextBox($x, $y, $x2, 30);
930
        $texto = 'Observação
931 1
        '.$this->infCpl;
932 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
933 1
        $this->pTextBox($x, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
934 1
        $y = $this->hPrint -4;
935 1
        $texto = "Impresso em  ". date('d/m/Y   H:i:s');
936 1
        $w = $this->wPrint-4;
937 1
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
938 1
        $this->pTextBox($x, $y, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
939 1
    }//fim footerCCe
940
    /**
941
     * printMDFe
942
     *
943
     * @param string $nome
944
     * @param string $destino
945
     * @param string $printer
946
     * @return string
947
     */
948 1
    public function printMDFe($nome = '', $destino = 'I', $printer = '')
949
    {
950
        //monta
951 1
        $command = '';
952 1
        if ($nome == '') {
953
            $file = $this->pdfDir.'mdfe.pdf';
954
        } else {
955 1
            $file = $this->pdfDir.$nome;
956
        }
957 1
        if ($destino != 'I' && $destino != 'S' && $destino != 'F') {
958
            $destino = 'I';
959
        }
960 1
        if ($printer != '') {
961
            $command = "-P $printer";
962
        }
963
964 1
        $this->buildMDFe();
965 1
        $arq = $this->pdf->Output($file, $destino);
966 1
        if ($destino == 'S' && $command != '') {
967
            //aqui pode entrar a rotina de impressão direta
968
            $command = "lpr $command $file";
969
            system($command, $retorno);
970
        }
971
972 1
        return $arq;
973
    }//fim printMDFe
974
975
    /**
976
     * Dados brutos do PDF
977
     * @return string
978
     */
979
    public function render()
980
    {
981
        return $this->pdf->getPdf();
982
    }
983
}
984