Completed
Push — master ( 838e20...97f8c4 )
by Roberto
09:08 queued 05:56
created

Damdfe::__construct()   F

Complexity

Conditions 16
Paths 6208

Size

Total Lines 122
Code Lines 96

Duplication

Lines 24
Ratio 19.67 %

Code Coverage

Tests 0
CRAP Score 272

Importance

Changes 0
Metric Value
cc 16
eloc 96
nc 6208
nop 8
dl 24
loc 122
ccs 0
cts 113
cp 0
crap 272
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

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

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

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Pdf;
20
use NFePHP\DA\Legacy\Common;
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
    public function __construct(
77
        $xmlfile = '',
78
        $sOrientacao = '',
79
        $sPapel = '',
80
        $sPathLogo = '',
81
        $sDestino = 'I',
82
        $sDirPDF = '',
83
        $fontePDF = '',
84
        $mododebug = 2
85
    ) {
86
        //define o caminho base da instalação do sistema
87
        if (!defined('PATH_ROOT')) {
88
            define('PATH_ROOT', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR);
89
        }
90
        //ajuste do tempo limite de resposta do processo
91
        set_time_limit(1800);
92
        //definição do caminho para o diretorio com as fontes do FDPF
93
        if (!defined('FPDF_FONTPATH')) {
94
            define('FPDF_FONTPATH', 'font/');
95
        }
96
97
        if (is_numeric($mododebug)) {
98
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
99
        }
100 View Code Duplication
        if ($this->debugMode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
            //ativar modo debug
102
            error_reporting(E_ALL);
103
            ini_set('display_errors', 'On');
104
        } else {
105
            //desativar modo debug
106
            error_reporting(0);
107
            ini_set('display_errors', 'Off');
108
        }
109
        $this->orientacao   = $sOrientacao;
110
        $this->papel        = $sPapel;
111
        $this->pdf          = '';
112
        //$this->xml          = $xmlfile;
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...
113
        $this->logomarca    = $sPathLogo;
114
        $this->destino      = $sDestino;
115
        $this->pdfDir       = $sDirPDF;
116
        // verifica se foi passa a fonte a ser usada
117
        if (empty($fontePDF)) {
118
            $this->fontePadrao = 'Times';
119
        } else {
120
            $this->fontePadrao = $fontePDF;
121
        }
122
        //se for passado o xml
123
        if (empty($xmlfile)) {
124
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
125
            $this->errStatus = true;
126
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
127
        }
128
        if (!is_file($xmlfile)) {
129
            $this->errMsg = 'Um caminho para o arquivo xml da MDFe deve ser passado!';
130
            $this->errStatus = true;
131
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
132
        }
133
        $docxml = file_get_contents($xmlfile);
134
        $this->dom = new DomDocument;
135
        $this->dom->loadXML($docxml);
136
        $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...
137
        $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...
138
        $this->emit = $this->infMDFe->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...
139
        $this->CNPJ = $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue;
0 ignored issues
show
Bug introduced by
The property CNPJ does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
140
        $this->IE = $this->emit->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...
141
        $this->xNome = $this->emit->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...
142
        $this->enderEmit = $this->emit->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...
143
        $this->xLgr = $this->enderEmit->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...
144
        $this->nro = $this->enderEmit->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...
145
        $this->xBairro = $this->enderEmit->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...
146
        $this->UF = $this->enderEmit->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...
147
        $this->xMun = $this->enderEmit->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...
148
        $this->CEP = $this->enderEmit->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...
149
        $this->ide = $this->infMDFe->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...
150
        $this->tpAmb = $this->ide->getElementsByTagName("tpAmb")->item(0)->nodeValue;
151
        $this->mod = $this->ide->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...
152
        $this->serie = $this->ide->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...
153
        $this->dhEmi = $this->ide->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...
154
        $this->UFIni = $this->ide->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...
155
        $this->nMDF = $this->ide->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
        $this->tpEmis = $this->ide->getElementsByTagName("tpEmis")->item(0)->nodeValue;
157
        $this->tot = $this->infMDFe->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
        $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 View Code Duplication
        if ($this->tot->getElementsByTagName("qNFe")->item(0) != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
160
            $this->qNFe = $this->tot->getElementsByTagName("qNFe")->item(0)->nodeValue;
161
        }
162
        $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 View Code Duplication
        if ($this->tot->getElementsByTagName("qNF")->item(0) != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
            $this->qNF = $this->tot->getElementsByTagName("qNF")->item(0)->nodeValue;
165
        }
166
        $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 View Code Duplication
        if ($this->tot->getElementsByTagName("qCTe")->item(0) != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
            $this->qCTe = $this->tot->getElementsByTagName("qCTe")->item(0)->nodeValue;
169
        }
170
        $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 View Code Duplication
        if ($this->tot->getElementsByTagName("qCT")->item(0) != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
172
            $this->qCT = $this->tot->getElementsByTagName("qCT")->item(0)->nodeValue;
173
        }
174
        $this->qCarga = $this->tot->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
        $this->infModal = $this->infMDFe->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
        $this->rodo = $this->infModal->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
        $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 View Code Duplication
        if ($this->rodo->getElementsByTagName('CIOT')->item(0) != "") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179
            $this->ciot = $this->rodo->getElementsByTagName('CIOT')->item(0)->nodeValue;
180
        }
181
        $this->veicTracao = $this->rodo->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
        $this->veicReboque = $this->rodo->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
        $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
        if ($this->rodo->getElementsByTagName("valePed")->item(0) != "") {
185
            $this->valePed = $this->rodo->getElementsByTagName("valePed")->item(0)->getElementsByTagName("disp");
186
        }
187
        $this->chMDFe = str_replace(
188
            'MDFe',
189
            '',
190
            $this->infMDFe->getAttribute("Id")
191
        );
192
        if (is_object($this->mdfeProc)) {
193
            $this->nProt = ! empty($this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
194
                    $this->mdfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
195
            $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...
196
        }
197
    }
198
    
199
    /**
200
     *buildMDFe
201
     *
202
     */
203
    private function buildMDFe()
204
    {
205
        $this->pdf = new PdfNFePHP($this->orientacao, 'mm', $this->papel);
206
        if ($this->orientacao == 'P') {
207
            // margens do PDF
208
            $margSup = 7;
209
            $margEsq = 7;
210
            $margDir = 7;
211
            // posição inicial do relatorio
212
            $xInic = 7;
213
            $yInic = 7;
214
            if ($this->papel =='A4') { //A4 210x297mm
215
                $maxW = 210;
216
                $maxH = 297;
217
            }
218
        } else {
219
            // margens do PDF
220
            $margSup = 7;
221
            $margEsq = 7;
222
            $margDir = 7;
223
            // posição inicial do relatorio
224
            $xInic = 7;
225
            $yInic = 7;
226
            if ($this->papel =='A4') { //A4 210x297mm
227
                $maxH = 210;
228
                $maxW = 297;
229
            }
230
        }//orientação
231
        //largura imprimivel em mm
232
        $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...
233
        //comprimento imprimivel em mm
234
        $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...
235
        // estabelece contagem de paginas
236
        $this->pdf->AliasNbPages();
237
        // fixa as margens
238
        $this->pdf->SetMargins($margEsq, $margSup, $margDir);
239
        $this->pdf->SetDrawColor(0, 0, 0);
240
        $this->pdf->SetFillColor(255, 255, 255);
241
        // inicia o documento
242
        $this->pdf->Open();
243
        // adiciona a primeira página
244
        $this->pdf->AddPage($this->orientacao, $this->papel);
245
        $this->pdf->SetLineWidth(0.1);
246
        $this->pdf->SetTextColor(0, 0, 0);
247
        //montagem da página
248
        $pag = 1;
249
        $x = $xInic;
250
        $y = $yInic;
251
        //coloca o cabeçalho Paisagem
252
        if ($this->orientacao == 'P') {
253
            $y = $this->headerMDFeRetrato($x, $y, $pag);
254
        } else {
255
            $y = $this->headerMDFePaisagem($x, $y, $pag);
256
        }
257
        //coloca os dados da MDFe
258
        $y = $this->bodyMDFe($x, $y);
259
        //coloca os dados da MDFe
260
        $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...
261
    }
262
    
263
    /**
264
     * headerMDFePaisagem
265
     * @param float $x
266
     * @param float $y
267
     * @param integer $pag
268
     * @return string
269
     */
270
    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...
271
    {
272
        $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...
273
        $oldY = $y;
274
        $maxW = $this->wPrint;
275
        //####################################################################################
276
        //coluna esquerda identificação do emitente
277
        $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...
278
        $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...
279
        $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...
280
        $h=30;
281
        $oldY += $h;
282
        $this->pTextBox($x, $y, $w, $h);
283 View Code Duplication
        if (is_file($this->logomarca)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
284
            $logoInfo = getimagesize($this->logomarca);
285
            //largura da imagem em mm
286
            $logoWmm = ($logoInfo[0]/72)*25.4;
287
            //altura da imagem em mm
288
            $logoHmm = ($logoInfo[1]/72)*25.4;
289
            if ($this->logoAlign=='L') {
290
                $nImgW = round($w/4.5, 0);
291
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
292
                $xImg = $x+1;
293
                $yImg = round(($h-$nImgH)/2, 0)+$y;
294
                //estabelecer posições do texto
295
                $x1 = round($xImg + $nImgW +1, 0);
296
                $y1 = round($y+2, 0);
297
                $tw = round(2*$w/3, 0);
298
            }
299
            if ($this->logoAlign=='C') {
300
                $nImgH = round($h/3, 0);
301
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
302
                $xImg = round(($w-$nImgW)/2+$x, 0);
303
                $yImg = $y+3;
304
                $x1 = $x;
305
                $y1 = round($yImg + $nImgH + 1, 0);
306
                $tw = $w;
307
            }
308
            if ($this->logoAlign=='R') {
309
                $nImgW = round($w/3, 0);
310
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
311
                $xImg = round($x+($w-(1+$nImgW)), 0);
312
                $yImg = round(($h-$nImgH)/2, 0)+$y;
313
                $x1 = $x;
314
                $y1 = round($h/3+$y, 0);
315
                $tw = round(2*$w/3, 0);
316
            }
317
            $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...
318
        } else {
319
            $x1 = $x;
320
            $y1 = round($h/3+$y, 0);
321
            $tw = $w;
322
        }
323
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
324
        $razao = $this->xNome;
325
        $cnpj = 'CNPJ: '.$this->pFormat($this->CNPJ, "###.###.###/####-##");
326
        $ie = 'IE: '.$this->pFormat($this->IE, '##/########');
327
        $lgr = 'Logradouro: '.$this->xLgr;
328
        $nro = 'Nº: '.$this->nro;
329
        $bairro = 'Bairro: '.$this->xBairro;
330
        $CEP = $this->CEP;
331
        $CEP = 'CEP: '.$this->pFormat($CEP, "##.###-###");
332
        $mun = 'Municipio: '.$this->xMun;
333
        $UF = 'UF: '.$this->UF;
334
        
335
        $texto = $razao . "\n" . $cnpj . ' - ' . $ie . "\n";
336
        $texto .= $lgr . ' - ' . $nro . "\n";
337
        $texto .= $bairro . "\n";
338
        $texto .= $mun . ' - ' . $UF . ' - ' . $CEP;
339
        $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...
340
        $x = $x+$maxW/2;
341
        $w = $maxW / 2;
342
        $this->pTextBox($x, $y, $w, $h);
343
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'I');
344
        $this->pTextBox(
345
            $x,
346
            $y,
347
            $w,
348
            8,
349
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
350
            $aFont,
351
            'T',
352
            'C',
353
            0,
354
            ''
355
        );
356
        $this->pTextBox($x, $y, $w, 6);
357
        $bH = 13;
358
        $bW = round(($w), 0);
359
        $this->pdf->SetFillColor(0, 0, 0);
360
        $this->pdf->Code128($x+5, $y+7.5, $this->chMDFe, $bW-10, $bH);
361
        $this->pdf->SetFillColor(255, 255, 255);
362
        $y = $y + 22;
363
        $this->pTextBox($x, $y, $w, 8);
364
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
365
        $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...
366
        $texto = 'CHAVE DE ACESSO';
367
        $this->pTextBox($x, $y, $maxW, 6, $texto, $aFont, 'T', 'L', 0, '');
368
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
369
        $texto = $this->pFormat($this->chMDFe, $this->formatoChave);
370
        $this->pTextBox($x, $y+3, $w, 6, $texto, $aFont, 'T', 'C', 0, '');
371
        $y = $y + 11;
372
        $this->pTextBox($x, $y, $w, 12);
373
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
374
        $texto = 'PROTOCOLO DE AUTORIZACAO DE USO';
375
        $this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
376
        
377
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
378 View Code Duplication
        if (is_object($this->mdfeProc)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
379
            $tsHora = $this->pConvertTime($this->dhRecbto);
380
            $texto = $this->nProt.' - '.date('d/m/Y   H:i:s', $tsHora);
381
        } else {
382
            $texto = 'DAMDFE impresso em contingência - '.date('d/m/Y   H:i:s');
383
        }
384
        $this->pTextBox($x, $y+4, $w, 8, $texto, $aFont, 'T', 'C', 0, '');
385 View Code Duplication
        if ($this->tpAmb != 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
386
            $x = 10;
387
            if ($this->orientacao == 'P') {
388
                $yy = round($this->hPrint*2/3, 0);
389
            } else {
390
                $yy = round($this->hPrint/2, 0);
391
            }
392
            $h = 5;
393
            $w = $maxW-(2*$x);
394
            $this->pdf->SetTextColor(90, 90, 90);
395
            $texto = "SEM VALOR FISCAL";
396
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
397
            $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
398
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
399
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
400
            $this->pTextBox($x, $yy+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
401
            $this->pdf->SetTextColor(0, 0, 0);
402
        } else {
403
            $x = 10;
404
            if ($this->orientacao == 'P') {
405
                $yy = round($this->hPrint*2/3, 0);
406
            } else {
407
                $yy = round($this->hPrint/2, 0);
408
            }//fim orientacao
409
            $h = 5;
410
            $w = $maxW-(2*$x);
411
            $this->pdf->SetTextColor(90, 90, 90);
412
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
413
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
414
                //Contingência
415
                $texto = "DAMDFE Emitido em Contingência";
416
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
417
                $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
418
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
419
                $texto = "devido à problemas técnicos";
420
                $this->pTextBox($x, $yy+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
421
            }
422
            $this->pdf->SetTextColor(0, 0, 0);
423
        }
424
        return $y;
425
    }
426
    
427
    /**
428
     * headerMDFeRetrato
429
     *
430
     * @param float $x
431
     * @param float $y
432
     * @param integer $pag
433
     * @return string
434
     */
435
    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...
436
    {
437
        $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...
438
        $oldY = $y;
439
        $maxW = $this->wPrint;
440
        //####################################################################################
441
        //coluna esquerda identificação do emitente
442
        $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...
443
        $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...
444
        $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...
445
        $h=20;
446
        $oldY += $h;
447
        $this->pTextBox($x, $y, $w, $h);
448 View Code Duplication
        if (is_file($this->logomarca)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
449
            $logoInfo = getimagesize($this->logomarca);
450
            //largura da imagem em mm
451
            $logoWmm = ($logoInfo[0]/72)*25.4;
452
            //altura da imagem em mm
453
            $logoHmm = ($logoInfo[1]/72)*25.4;
454
            if ($this->logoAlign=='L') {
455
                $nImgW = round($w/4.5, 0);
456
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
457
                $xImg = $x+1;
458
                $yImg = round(($h-$nImgH)/2, 0)+$y;
459
                //estabelecer posições do texto
460
                $x1 = round($xImg + $nImgW +1, 0);
461
                $y1 = round($y+2, 0);
462
                $tw = round(2*$w/3, 0);
463
            }
464
            if ($this->logoAlign=='C') {
465
                $nImgH = round($h/3, 0);
466
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
467
                $xImg = round(($w-$nImgW)/2+$x, 0);
468
                $yImg = $y+3;
469
                $x1 = $x;
470
                $y1 = round($yImg + $nImgH + 1, 0);
471
                $tw = $w;
472
            }
473
            if ($this->logoAlign=='R') {
474
                $nImgW = round($w/3, 0);
475
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
476
                $xImg = round($x+($w-(1+$nImgW)), 0);
477
                $yImg = round(($h-$nImgH)/2, 0)+$y;
478
                $x1 = $x;
479
                $y1 = round($h/3+$y, 0);
480
                $tw = round(2*$w/3, 0);
481
            }
482
            $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...
483
        } else {
484
            $x1 = $x;
485
            $y1 = round($h/3+$y, 0);
486
            $tw = $w;
487
        }
488
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
489
        $razao = $this->xNome;
490
        $cnpj = 'CNPJ: '.$this->pFormat($this->CNPJ, "###.###.###/####-##");
491
        $ie = 'IE: '.$this->pFormat($this->IE, '##/########');
492
        $lgr = 'Logradouro: '.$this->xLgr;
493
        $nro = 'Nº: '.$this->nro;
494
        $bairro = 'Bairro: '.$this->xBairro;
495
        $CEP = $this->CEP;
496
        $CEP = 'CEP: '.$this->pFormat($CEP, "##.###-###");
497
        $mun = 'Municipio: '.$this->xMun;
498
        $UF = 'UF: '.$this->UF;
499
        $texto = $razao . "\n" . $cnpj . ' - ' . $ie . "\n";
500
        $texto .= $lgr . ' - ' . $nro . "\n";
501
        $texto .= $bairro . "\n";
502
        $texto .= $mun . ' - ' . $UF . ' - ' . $CEP;
503
        $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...
504
        //##################################################
505
        $y = $h + 8;
506
        $this->pTextBox($x, $y, $maxW, 6);
507
        $aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'I');
508
        $this->pTextBox(
509
            $x,
510
            $y,
511
            $maxW,
512
            8,
513
            'DAMDFE - Documento Auxiliar de Manifesto Eletronico de Documentos Fiscais',
514
            $aFont,
515
            'T',
516
            'C',
517
            0,
518
            ''
519
        );
520
        $y = $y + 8;
521
        $this->pTextBox($x, $y, $maxW, 20);
522
        $bH = 16;
523
        $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...
524
        $this->pdf->SetFillColor(0, 0, 0);
525
        $this->pdf->Code128($x + 5, $y+2, $this->chMDFe, $maxW - 10, $bH);
526
        $this->pdf->SetFillColor(255, 255, 255);
527
        $y = $y + 22;
528
        $this->pTextBox($x, $y, $maxW, 10);
529
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
530
        $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...
531
        $texto = 'CHAVE DE ACESSO';
532
        $this->pTextBox($x, $y, $maxW, 6, $texto, $aFont, 'T', 'L', 0, '');
533
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
534
        $texto = $this->pFormat($this->chMDFe, $this->formatoChave);
535
        $this->pTextBox($x, $y+4, $maxW, 6, $texto, $aFont, 'T', 'C', 0, '');
536
        $y = $y + 12;
537
        $this->pTextBox($x, $y, $maxW, 10);
538
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I');
539
        $texto = 'PROTOCOLO DE AUTORIZACAO DE USO';
540
        $this->pTextBox($x, $y, $maxW, 8, $texto, $aFont, 'T', 'L', 0, '');
541
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
542 View Code Duplication
        if (is_object($this->mdfeProc)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
543
            $tsHora = $this->pConvertTime($this->dhRecbto);
544
            $texto = $this->nProt.' - '.date('d/m/Y   H:i:s', $tsHora);
545
        } else {
546
            $texto = 'DAMDFE impresso em contingência - '.date('d/m/Y   H:i:s');
547
        }
548
        $this->pTextBox($x, $y+4, $maxW, 8, $texto, $aFont, 'T', 'C', 0, '');
549 View Code Duplication
        if ($this->tpAmb != 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
550
            $x = 10;
551
            if ($this->orientacao == 'P') {
552
                $yy = round($this->hPrint*2/3, 0);
553
            } else {
554
                $yy = round($this->hPrint/2, 0);
555
            }
556
            $h = 5;
557
            $w = $maxW-(2*$x);
558
            $this->pdf->SetTextColor(90, 90, 90);
559
            $texto = "SEM VALOR FISCAL";
560
            $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
561
            $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
562
            $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
563
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
564
            $this->pTextBox($x, $yy+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
565
            $this->pdf->SetTextColor(0, 0, 0);
566
        } else {
567
            $x = 10;
568
            if ($this->orientacao == 'P') {
569
                $yy = round($this->hPrint*2/3, 0);
570
            } else {
571
                $yy = round($this->hPrint/2, 0);
572
            }//fim orientacao
573
            $h = 5;
574
            $w = $maxW-(2*$x);
575
            $this->pdf->SetTextColor(90, 90, 90);
576
            //indicar FALTA DO PROTOCOLO se MDFe não for em contingência
577
            if (($this->tpEmis == 2 || $this->tpEmis == 5)) {
578
                //Contingência
579
                $texto = "DAMDFE Emitido em Contingência";
580
                $aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B');
581
                $this->pTextBox($x, $yy, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
582
                $aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B');
583
                $texto = "devido à problemas técnicos";
584
                $this->pTextBox($x, $yy+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
585
            }
586
            $this->pdf->SetTextColor(0, 0, 0);
587
        }
588
        return $y+12;
589
    }
590
    
591
    /**
592
     * bodyMDFe
593
     *
594
     * @param float $x
595
     * @param float $y
596
     * @return void
597
     */
598
    private function bodyMDFe($x, $y)
599
    {
600
        if ($this->orientacao == 'P') {
601
            $maxW = $this->wPrint;
602
        } else {
603
            $maxW = $this->wPrint / 2;
604
        }
605
        $x2 = ($maxW / 6);
606
        $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...
607
        $this->pTextBox($x, $y, $x2-7, 12);
608
        $texto = 'Modelo';
609
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
610
        $this->pTextBox($x, $y, $x2-7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
611
        $texto = $this->mod;
612
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
613
        $this->pTextBox($x, $y+4, $x2-7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
614
        $x1 = $x2;
615
        $this->pTextBox($x1, $y, $x2-7, 12);
616
        $texto = 'Série';
617
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
618
        $this->pTextBox($x1, $y, $x2-7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
619
        $texto = $this->serie;
620
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
621
        $this->pTextBox($x1, $y+4, $x2-7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
622
        $x1 += $x2-7;
623
        $this->pTextBox($x1, $y, $x2+5, 12);
624
        $texto = 'Número';
625
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
626
        $this->pTextBox($x1, $y, $x2+5, 8, $texto, $aFont, 'T', 'L', 0, '', false);
627
        $texto = $this->pFormat(str_pad($this->nMDF, 9, '0', STR_PAD_LEFT), '###.###.###');
628
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
629
        $this->pTextBox($x1, $y+4, $x2+5, 10, $texto, $aFont, 'T', 'C', 0, '', false);
630
        $x1 += $x2+5;
631
        $this->pTextBox($x1, $y, $x2-7, 12);
632
        $texto = 'FL';
633
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
634
        $this->pTextBox($x1, $y, $x2-7, 8, $texto, $aFont, 'T', 'L', 0, '', false);
635
        $texto = '1';
636
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
637
        $this->pTextBox($x1, $y+4, $x2-7, 10, $texto, $aFont, 'T', 'C', 0, '', false);
638
        $x1 += $x2-7;
639
        $this->pTextBox($x1, $y, $x2+11, 12);
640
        $texto = 'Data e Hora de Emissão';
641
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
642
        $this->pTextBox($x1, $y, $x2+11, 8, $texto, $aFont, 'T', 'L', 0, '', false);
643
        $data = explode('T', $this->dhEmi);
644
        $texto = $this->pYmd2dmy($data[0]).' - '.$data[1];
645
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
646
        $this->pTextBox($x1, $y+4, $x2+11, 10, $texto, $aFont, 'T', 'C', 0, '', false);
647
        $x1 += $x2+11;
648
        $this->pTextBox($x1, $y, $x2+5, 12);
649
        $texto = 'UF Carregamento';
650
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
651
        $this->pTextBox($x1, $y, $x2+5, 8, $texto, $aFont, 'T', 'L', 0, '', false);
652
        $texto = $this->UFIni;
653
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
654
        $this->pTextBox($x1, $y+4, $x2+5, 10, $texto, $aFont, 'T', 'C', 0, '', false);
655
        $maxW = $this->wPrint;
656
        $x1 = $x;
657
        $x2 = $maxW;
658
        $y += 14;
659
        $this->pTextBox($x1, $y, $x2, 23);
660
        $texto = 'Modal Rodoviário de Carga';
661
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
662
        $this->pTextBox($x1, $y+1, $x2, 8, $texto, $aFont, 'T', 'C', 0, '', false);
663
        $x1 = $x;
664
        $x2 = ($maxW / 6);
665
        $y += 6;
666
        $this->pTextBox($x1, $y, $x2, 12);
667
        $texto = 'CIOT';
668
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
669
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
670
        $texto = str_pad($this->ciot, 3, '0', STR_PAD_LEFT);
671
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
672
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
673
        $x1 += $x2;
674
        $this->pTextBox($x1, $y, $x2, 12);
675
        $texto = 'Qtd. CT-e';
676
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
677
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
678
        $texto = str_pad($this->qCTe, 3, '0', STR_PAD_LEFT);
679
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
680
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
681
        $x1 += $x2;
682
        $this->pTextBox($x1, $y, $x2, 12);
683
        $texto = 'Qtd. CTRC';
684
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
685
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
686
        $texto = str_pad($this->qCT, 3, '0', STR_PAD_LEFT);
687
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
688
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
689
        $x1 += $x2;
690
        $this->pTextBox($x1, $y, $x2, 12);
691
        $texto = 'Qtd. NF-e';
692
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
693
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
694
        $texto = str_pad($this->qNFe, 3, '0', STR_PAD_LEFT);
695
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
696
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
697
        $x1 += $x2;
698
        $this->pTextBox($x1, $y, $x2, 12);
699
        $texto = 'Qtd. NF';
700
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
701
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
702
        $texto = str_pad($this->qNF, 3, '0', STR_PAD_LEFT);
703
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
704
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
705
        $x1 += $x2;
706
        $this->pTextBox($x1, $y, $x2, 12);
707
        $texto = 'Peso Total (Kg)';
708
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
709
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
710
        $texto = number_format($this->qCarga, 4, ', ', '.');
711
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
712
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
713
        $x1 = $x;
714
        $y += 12;
715
        $yold = $y;
716
        $x2 = round($maxW / 2, 0);
717
        $texto = 'Veículo';
718
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
719
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
720
        $y += 5;
721
        $x2 = round($maxW / 4, 0);
722
        $tamanho = 22;
723
        $this->pTextBox($x1, $y, $x2, $tamanho);
724
        $texto = 'Placa';
725
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
726
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
727
        $texto = $this->veicTracao->getElementsByTagName("placa")->item(0)->nodeValue;
728
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
729
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
730
        $altura = $y + 4;
731 View Code Duplication
        for ($i = 0; $i < $this->veicReboque->length; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
732
            $altura += 4;
733
            $texto = $this->veicReboque->item($i)->getElementsByTagName('placa')->item(0)->nodeValue;
734
            $this->pTextBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
735
        }
736
        $x1 += $x2;
737
        $this->pTextBox($x1, $y, $x2, $tamanho);
738
        $texto = 'RNTRC';
739
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
740
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
741
        $texto = $this->rodo->getElementsByTagName("RNTRC")->item(0)->nodeValue;
742
        $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
743
        $this->pTextBox($x1, $y+4, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
744
        $altura = $y + 4;
745 View Code Duplication
        for ($i = 0; $i < $this->veicReboque->length; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
746
            $altura += 4;
747
            $texto = $this->veicReboque->item($i)->getElementsByTagName('RNTRC')->item(0)->nodeValue;
748
            $this->pTextBox($x1, $altura, $x2, 10, $texto, $aFont, 'T', 'C', 0, '', false);
749
        }
750
        $x1 = $x;
751
        $y += 22;
752
        $x2 = round($maxW / 2, 0);
753
        $valesPedagios = 1;
754
        $temVales = false;
755
        if ($this->valePed != "" && $this->valePed->length > 0) {
756
            $valesPedagios = $this->valePed->length;
757
            $temVales = true;
758
        }
759
        $tamanho = ($valesPedagios * 7.5);
760
        if (!$temVales) {
761
            $valesPedagios = 0;
762
        }
763
        $this->pTextBox($x1, $y, $x2, 11+$tamanho/2);
764
        $texto = 'Vale Pedágio';
765
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
766
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
767
        $y += 5;
768
        $x2 = ($x2 / 3);
769
        $this->pTextBox($x1, $y, $x2-3, 6+($tamanho/2));
770
        $texto = 'Responsável CNPJ';
771
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
772
        $this->pTextBox($x1, $y, $x2-4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
773
        $altura = $y;
774 View Code Duplication
        for ($i = 0; $i < $valesPedagios; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
775
            $altura += 4;
776
            $texto = $this->valePed->item($i)->getElementsByTagName('CNPJForn')->item(0)->nodeValue;
777
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
778
            $this->pTextBox($x1 + 1, $altura, $x2-5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
779
        }
780
        $x1 += $x2-3;
781
        $this->pTextBox($x1, $y, $x2-3, 6+($tamanho/2));
782
        $texto = 'Fornecedora CNPJ';
783
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
784
        $this->pTextBox($x1, $y, $x2-4, 8, $texto, $aFont, 'T', 'L', 0, '', false);
785
        $altura = $y;
786 View Code Duplication
        for ($i = 0; $i < $valesPedagios; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
787
            $altura += 4;
788
            $texto = $this->valePed->item($i)->getElementsByTagName('CNPJPg')->item(0)->nodeValue;
789
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
790
            $this->pTextBox($x1 + 1, $altura, $x2-5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
791
        }
792
        $x1 += $x2-3;
793
        $this->pTextBox($x1, $y, $x2+6, 6+($tamanho/2));
794
        $texto = 'Nº Comprovante';
795
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
796
        $this->pTextBox($x1, $y, $x2+6, 8, $texto, $aFont, 'T', 'L', 0, '', false);
797
        $altura = $y;
798 View Code Duplication
        for ($i = 0; $i < $valesPedagios; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
799
            $altura += 4;
800
            $texto = $this->valePed->item($i)->getElementsByTagName('nCompra')->item(0)->nodeValue;
801
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
802
            $this->pTextBox($x1 + 1, $altura, $x2+5, 10, $texto, $aFont, 'T', 'L', 0, '', false);
803
        }
804
        if (!$temVales) {
805
            $altura += 4;
806
        }
807
        $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...
808
        $x1 = round($maxW / 2, 0) + 7;
809
        $y = $yold;
810
        $x2 = round($maxW / 2, 0);
811
        $texto = 'Condutor';
812
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
813
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
814
        $y += 5;
815
        $x2 = ($maxW / 4);
816
        $this->pTextBox($x1, $y, $x2, 33+($tamanho/2));
817
        $texto = 'CPF';
818
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
819
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
820
        $yold = $y;
821 View Code Duplication
        for ($i = 0; $i < $this->condutor->length; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
822
            $y += 4;
823
            $texto = $this->condutor->item($i)->getElementsByTagName('CPF')->item(0)->nodeValue;
824
            $aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'');
825
            $this->pTextBox($x1 + 1, $y, $x2 - 1, 10, $texto, $aFont, 'T', 'L', 0, '', false);
826
        }
827
        $y = $yold;
828
        $x1 += $x2;
829
        $this->pTextBox($x1, $y, $x2, 33+($tamanho/2));
830
        $texto = 'Nome';
831
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
832
        $this->pTextBox($x1, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
833 View Code Duplication
        for ($i = 0; $i < $this->condutor->length; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
834
            $y += 4;
835
            $texto = $this->condutor->item($i)->getElementsByTagName('xNome')->item(0)->nodeValue;
836
            $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
837
            $this->pTextBox($x1 + 1, $y, $x2 - 1, 8, $texto, $aFont, 'T', 'L', 0, '', false);
838
        }
839
        return $altura + 7;
840
    }
841
    
842
    /**
843
     * footerMDFe
844
     *
845
     * @param float $x
846
     * @param float $y
847
     */
848
    private function footerMDFe($x, $y)
849
    {
850
        $maxW = $this->wPrint;
851
        $x2 = $maxW;
852
        $this->pTextBox($x, $y, $x2, 30);
853
        $texto = 'Observações ';
854
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
855
        $this->pTextBox($x, $y, $x2, 8, $texto, $aFont, 'T', 'L', 0, '', false);
856
        $y = $this->hPrint -4;
857
        $texto = "Impresso em  ". date('d/m/Y   H:i:s');
858
        $w = $this->wPrint-4;
859
        $aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I');
860
        $this->pTextBox($x, $y, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
861
    }
862
    
863
    /**
864
     * printMDFe
865
     *
866
     * @param string $nome
867
     * @param string $destino
868
     * @param string $printer
869
     * @return string
870
     */
871
    public function printMDFe($nome = '', $destino = 'I', $printer = '')
872
    {
873
        //monta
874
        $command = '';
875
        if ($nome == '') {
876
            $file = $this->pdfDir.'mdfe.pdf';
877
        } else {
878
            $file = $this->pdfDir.$nome;
879
        }
880
        if (($destino != 'I' || $destino != 'S') && $destino != 'F') {
881
            $destino = 'I';
882
        }
883
        if ($printer != '') {
884
            $command = "-P $printer";
885
        }
886
        $this->buildMDFe();
887
        $arq = $this->pdf->Output($file, $destino);
888
        if ($destino == 'S') {
889
            //aqui pode entrar a rotina de impressão direta
890
            $command = "lpr $command $file";
0 ignored issues
show
Unused Code introduced by
$command 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...
891
            system($comando, $retorno);
0 ignored issues
show
Bug introduced by
The variable $comando does not exist. Did you forget to declare it?

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

Loading history...
892
        }
893
        return $arq;
894
    }
895
}
896