Passed
Push — master ( 0a879f...5386e2 )
by Roberto
01:44 queued 14s
created

Danfce::pFiscalDANFE()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 51
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 42
nc 4
nop 3
dl 0
loc 51
ccs 0
cts 46
cp 0
crap 12
rs 9.4109
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
/**
6
 * Classe para a impressão em PDF do Documento Auxiliar de NFe Consumidor
7
 * NOTA: Esta classe não é a indicada para quem faz uso de impressoras térmicas ESCPOS
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @copyright 2009-2016 NFePHP
12
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
13
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
14
 * @author    Roberto Spadim <roberto at spadim dot com dot br>
15
 */
16
use Exception;
17
use NFePHP\DA\Legacy\Dom;
18
use NFePHP\DA\Legacy\Pdf;
19
use NFePHP\DA\Legacy\Common;
20
use Com\Tecnick\Barcode\Barcode;
21
use DateTime;
22
23
class Danfce extends Common
24
{
25
    protected $papel;
26
    protected $xml; // string XML NFe
27
    protected $logomarca=''; // path para logomarca em jpg
28
    protected $formatoChave="#### #### #### #### #### #### #### #### #### #### ####";
29
    protected $debugMode=0; //ativa ou desativa o modo de debug
30
    protected $tpImp; //ambiente
31
    protected $fontePadrao='Times';
32
    protected $nfeProc;
33
    protected $nfe;
34
    protected $infNFe;
35
    protected $ide;
36
    protected $enderDest;
37
    protected $ICMSTot;
38
    protected $imposto;
39
    protected $emit;
40
    protected $enderEmit;
41
    protected $qrCode;
42
    protected $det;
43
    protected $infAdic;
44
    protected $textoAdic;
45
    protected $pag;
46
    protected $dest;
47
    protected $imgQRCode;
48
    protected $urlQR = '';
49
    protected $pdf;
50
    protected $margemInterna = 2;
51
    protected $hMaxLinha = 9;
52
    protected $hBoxLinha = 6;
53
    protected $hLinha = 3;
54
    /*
55
     * Retorna a sigla da UF
56
     * @var string
57
     */
58
    protected $UFSigla = [
59
        '12' => 'AC',
60
        '27' => 'AL',
61
        '13' => 'AM',
62
        '16' => 'AP',
63
        '29' => 'BA',
64
        '23' => 'CE',
65
        '53' => 'DF',
66
        '32' => 'ES',
67
        '52' => 'GO',
68
        '31' => 'MG',
69
        '50' => 'MS',
70
        '51' => 'MT',
71
        '21' => 'MA',
72
        '15' => 'PA',
73
        '25' => 'PB',
74
        '26' => 'PE',
75
        '22' => 'PI',
76
        '41' => 'PR',
77
        '33' => 'RJ',
78
        '11' => 'RO',
79
        '24' => 'RN',
80
        '14' => 'RR',
81
        '43' => 'RS',
82
        '42' => 'SC',
83
        '28' => 'SE',
84
        '35' => 'SP',
85
        '17' => 'TO'
86
    ];
87
    /*
88
     * Fonte: http://nfce.encat.org/consumidor/consulte-sua-nota/
89
     * URL referente a pagina de consulta da NFCe pela chave de acesso
90
     * @var string
91
     */
92
    protected $urlConsulta = [
93
        '1' => [
94
            'AC' => 'www.sefaznet.ac.gov.br/nfce/consulta',
95
            'AL' => 'http://nfce.sefaz.al.gov.br/consultaNFCe.htm',
96
            'AP' => 'https://www.sefaz.ap.gov.br/sate/seg/SEGf_AcessarFuncao.jsp?cdFuncao=FIS_1261',
97
            'AM' => 'sistemas.sefaz.am.gov.br/nfceweb/formConsulta.do',
98
            'BA' => 'nfe.sefaz.ba.gov.br/servicos/nfce/default.aspx',
99
            'CE' => '',
100
            'DF' => 'http://dec.fazenda.df.gov.br/NFCE/',
101
            'ES' => 'http://app.sefaz.es.gov.br/ConsultaNFCe',
102
            'GO' => '',
103
            'MA' => 'http://www.nfce.sefaz.ma.gov.br/portal/consultaNFe.do?method=preFilterCupom&',
104
            'MT' => 'http://www.sefaz.mt.gov.br/nfce/consultanfce',
105
            'MS' => 'http://www.dfe.ms.gov.br/nfce',
106
            'MG' => '',
107
            'PA' => 'https://appnfc.sefa.pa.gov.br/portal/view/consultas/nfce/consultanfce.seam',
108
            'PB' => 'www.receita.pb.gov.br/nfce',
109
            'PR' => 'http://www.fazenda.pr.gov.br',
110
            'PE' => '',
111
            'PI' => 'http://webas.sefaz.pi.gov.br/nfceweb/consultarNFCe.jsf',
112
            'RJ' => 'www.nfce.fazenda.rj.gov.br/consulta',
113
            'RN' => 'http://nfce.set.rn.gov.br/consultarNFCe.aspx',
114
            'RS' => 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx',
115
            'RO' => 'http://www.nfce.sefin.ro.gov.br',
116
            'RR' => 'https://www.sefaz.rr.gov.br/nfce/servlet/wp_consulta_nfce',
117
            'SC' => '',
118
            'SP' => 'https://www.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaPublica.aspx',
119
            'SE' => 'http://www.nfce.se.gov.br/portal/portalNoticias.jsp',
120
            'TO' => ''
121
        ],
122
        '2' => [
123
            'AC' => 'http://hml.sefaznet.ac.gov.br/nfce/consulta',
124
            'AL' => 'http://nfce.sefaz.al.gov.br/consultaNFCe.htm',
125
            'AP' => 'https://www.sefaz.ap.gov.br/sate1/seg/SEGf_AcessarFuncao.jsp?cdFuncao=FIS_1261',
126
            'AM' => 'homnfce.sefaz.am.gov.br/nfceweb/formConsulta.do',
127
            'BA' => 'http://hnfe.sefaz.ba.gov.br/servicos/nfce/default.aspx',
128
            'CE' => 'http://nfceh.sefaz.ce.gov.br/pages/consultaNota.jsf',
129
            'DF' => 'http://dec.fazenda.df.gov.br/NFCE/',
130
            'ES' => 'http://homologacao.sefaz.es.gov.br/ConsultaNFCe',
131
            'GO' => '',
132
            'MA' => 'http://www.hom.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp',
133
            'MT' => 'http://homologacao.sefaz.mt.gov.br/nfce/consultanfce',
134
            'MS' => 'http://www.dfe.ms.gov.br/nfce',
135
            'MG' => '',
136
            'PA' => 'https://appnfc.sefa.pa.gov.br/portal-homologacao/view/consultas/nfce/consultanfce.seam',
137
            'PB' => '',
138
            'PR' => 'http://www.fazenda.pr.gov.br',
139
            'PE' => '',
140
            'PI' => 'http://webas.sefaz.pi.gov.br/nfceweb-homologacao/consultarNFCe.jsf',
141
            'RJ' => 'www.nfce.fazenda.rj.gov.br/consulta',
142
            'RN' => 'http://nfce.set.rn.gov.br/consultarNFCe.aspx',
143
            'RS' => 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx',
144
            'RO' => 'http://www.nfce.sefin.ro.gov.br',
145
            'RR' => 'http://200.174.88.103:8080/nfce/servlet/wp_consulta_nfce',
146
            'SC' => '',
147
            'SP' => 'https://www.homologacao.nfce.fazenda.sp.gov.br/NFCeConsultaPublica/Paginas/ConsultaPublica.aspx',
148
            'SE' => 'http://www.hom.nfe.se.gov.br/portal/portalNoticias.jsp',
149
            'TO' => ''
150
        ],
151
    ];
152
    /**
153
     * __contruct
154
     *
155
     * @param string $docXML
156
     * @param string $sPathLogo
157
     * @param string $mododebug
158
     * @param string $idToken
159
     * @param string $Token
0 ignored issues
show
Bug introduced by
There is no parameter named $Token. 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...
160
     */
161
    public function __construct(
162
        $docXML = '',
163
        $sPathLogo = '',
164
        $mododebug = 0,
165
        // habilita os erros do sistema
166
        $idToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $idToken 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...
167
        $emitToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $emitToken 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...
168
        $urlQR = ''
0 ignored issues
show
Unused Code introduced by
The parameter $urlQR 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...
169
    ) {
170
        if (is_numeric($mododebug)) {
171
            $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...
172
        }
173
        if ($this->debugMode) {
174
            //ativar modo debug
175
            error_reporting(E_ALL);
176
            ini_set('display_errors', 'On');
177
        } else {
178
            //desativar modo debug
179
            error_reporting(0);
180
            ini_set('display_errors', 'Off');
181
        }
182
        $this->xml = $docXML;
183
        $this->logomarca = $sPathLogo;
184
        if (empty($fonteDANFE)) {
0 ignored issues
show
Bug introduced by
The variable $fonteDANFE seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
185
            $this->fontePadrao = 'Times';
186
        } else {
187
            $this->fontePadrao = $fonteDANFE;
188
        }
189
        if (!empty($this->xml)) {
190
            $this->dom = new Dom();
0 ignored issues
show
Bug introduced by
The property dom does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
191
            $this->dom->loadXML($this->xml);
192
            $this->nfeProc    = $this->dom->getElementsByTagName("nfeProc")->item(0);
193
            $this->nfe        = $this->dom->getElementsByTagName("NFe")->item(0);
194
            $this->infNFe     = $this->dom->getElementsByTagName("infNFe")->item(0);
195
            $this->ide        = $this->dom->getElementsByTagName("ide")->item(0);
196
            $this->emit       = $this->dom->getElementsByTagName("emit")->item(0);
197
            $this->enderEmit  = $this->dom->getElementsByTagName("enderEmit")->item(0);
198
            $this->det        = $this->dom->getElementsByTagName("det");
199
            $this->dest       = $this->dom->getElementsByTagName("dest")->item(0);
200
            $this->imposto    = $this->dom->getElementsByTagName("imposto")->item(0);
201
            $this->ICMSTot    = $this->dom->getElementsByTagName("ICMSTot")->item(0);
202
            $this->tpImp      = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue;
203
            $this->infAdic    = $this->dom->getElementsByTagName("infAdic")->item(0);
204
            
205
            //se for o layout 4.0 busca pelas tags de detalhe do pagamento
206
            //senao, busca pelas tags de pagamento principal
207
            if ($this->infNFe->getAttribute("versao") == "4.00") {
208
                $this->pag = $this->dom->getElementsByTagName("detPag");
209
            } else {
210
                $this->pag = $this->dom->getElementsByTagName("pag");
211
            }
212
        }
213
        $this->qrCode = $this->dom->getElementsByTagName('qrCode')->item(0)->nodeValue;
214
        if ($this->pSimpleGetValue($this->ide, "mod") != '65') {
215
            throw new nfephpException("O xml do DANFE deve ser uma NFC-e modelo 65");
216
        }
217
    }
218
    
219
    public function getPapel()
220
    {
221
        return $this->papel;
222
    }
223
    
224
    public function setPapel($aPap)
225
    {
226
        $this->papel = $aPap;
227
    }
228
    
229
    public function monta(
230
        $orientacao = 'P',
231
        $papel = '',
232
        $logoAlign = 'C',
233
        $classPdf = false,
234
        $depecNumReg = ''
235
    ) {
236
        $this->montaDANFE($orientacao, $papel, $logoAlign, $classPdf, $depecNumReg);
237
    }
238
    
239
    public function montaDANFE(
240
        $orientacao = 'P',
241
        $papel = '',
0 ignored issues
show
Unused Code introduced by
The parameter $papel 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...
242
        $logoAlign = 'C',
243
        $classPdf = false,
244
        $depecNumReg = ''
245
    ) {
246
        $qtdItens = $this->det->length;
247
        $qtdPgto = $this->pag->length;
248
        $hMaxLinha = $this->hMaxLinha;
249
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha 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...
250
        $hLinha = $this->hLinha;
251
        $tamPapelVert = 160 + 16 + (($qtdItens - 1) * $hMaxLinha) + ($qtdPgto * $hLinha);
252
        // verifica se existe informações adicionais
253
        $this->textoAdic = '';
254
        if (isset($this->infAdic)) {
255
            $this->textoAdic .= !empty($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue) ?
256
            'Inf. Contribuinte: '.
257
            trim($this->pAnfavea($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue)) : '';
258
            if (!empty($this->textoAdic)) {
259
                $tempPDF = new Pdf(); // cria uma instancia temporaria da class pdf
260
                $tempPDF->SetFont('Times', '', '8'); // seta a font do PDF
261
                $linhasCount = $tempPDF->WordWrap($this->textoAdic, 76);
0 ignored issues
show
Documentation introduced by
$this->textoAdic is of type string, but the function expects a object<NFePHP\DA\Legacy\type>.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
76 is of type integer, but the function expects a object<NFePHP\DA\Legacy\type>.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
262
                //seta a quantidade de linhas que o texto vai ocupar
263
                //e deixa uma folga para a margem bottom
264
                $tamPapelVert += $linhasCount + ceil(2.9 * $linhasCount);
265
            }
266
        }
267
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
268
        if ($orientacao == '') {
269
            $orientacao = 'P';
270
        }
271
        $this->orientacao = $orientacao;
0 ignored issues
show
Bug introduced by
The property orientacao 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...
272
        $this->papel = array(80,$tamPapelVert);
273
        $this->logoAlign = $logoAlign;
0 ignored issues
show
Bug introduced by
The property logoAlign 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...
274
        //$this->situacao_externa = $situacaoExterna;
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...
275
        $this->numero_registro_dpec = $depecNumReg;
0 ignored issues
show
Bug introduced by
The property numero_registro_dpec 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...
276
        //instancia a classe pdf
277
        if ($classPdf) {
278
            $this->pdf = $classPdf;
279
        } else {
280
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer|do...,"1":"double|integer"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
281
        }
282
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
283
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
284
        //apenas para controle se necessário ser maior do que a margem superior
285
        $margSup = 2;
286
        $margEsq = 2;
287
        $margInf = 2;
288
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
289
        $xInic = $margEsq;
290
        $yInic = $margSup;
291
        $maxW = 80;
292
        $maxH = $tamPapelVert;
293
        //total inicial de paginas
294
        $totPag = 1;
0 ignored issues
show
Unused Code introduced by
$totPag 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...
295
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
296
        $this->wPrint = $maxW-($margEsq*2);
0 ignored issues
show
Bug introduced by
The property wPrint 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...
297
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
298
        //superior e inferior
299
        $this->hPrint = $maxH-$margSup-$margInf;
0 ignored issues
show
Bug introduced by
The property hPrint 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...
300
        // estabelece contagem de paginas
301
        $this->pdf->aliasNbPages();
302
        $this->pdf->setMargins($margEsq, $margSup); // fixa as margens
303
        $this->pdf->setDrawColor(0, 0, 0);
304
        $this->pdf->setFillColor(255, 255, 255);
305
        $this->pdf->open(); // inicia o documento
306
        $this->pdf->addPage($this->orientacao, $this->papel); // adiciona a primeira página
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer|do...,"1":"double|integer"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
307
        $this->pdf->setLineWidth(0.1); // define a largura da linha
308
        $this->pdf->setTextColor(0, 0, 0);
309
        $this->pTextBox(0, 0, $maxW, $maxH); // POR QUE PRECISO DESA LINHA?
310
        $hcabecalho = 27;//para cabeçalho (dados emitente mais logomarca)  (FIXO)
311
        $hcabecalhoSecundario = 10;//para cabeçalho secundário (cabeçalho sefaz) (FIXO)
312
        $hprodutos = $hLinha + ($qtdItens*$hMaxLinha) ;//box poduto
313
        $hTotal = 12; //box total (FIXO)
314
        $hpagamentos = $hLinha + ($qtdPgto*$hLinha);//para pagamentos
315
        $hmsgfiscal = 21;// para imposto (FIXO)
316
        if (!isset($this->dest)) {
317
            $hcliente = 6;// para cliente (FIXO)
318
        } else {
319
            $hcliente = 12;
320
        }// para cliente (FIXO)};
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
321
        $hQRCode = 50;// para qrcode (FIXO)
322
        $hCabecItens = 4;//cabeçalho dos itens
323
        
324
        $hUsado = $hCabecItens;
0 ignored issues
show
Unused Code introduced by
$hUsado 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...
325
        $w2 = round($this->wPrint*0.31, 0);
0 ignored issues
show
Unused Code introduced by
$w2 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...
326
        $totPag = 1;
327
        $pag = 1;
328
        $x = $xInic;
329
        //COLOCA CABEÇALHO
330
        $y = $yInic;
331
        $y = $this->pCabecalhoDANFE($x, $y, $hcabecalho, $pag, $totPag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pCabecalhoDANFE($...becalho, $pag, $totPag) (which targets NFePHP\DA\NFe\Danfce::pCabecalhoDANFE()) 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...
332
        //COLOCA CABEÇALHO SECUNDÁRIO
333
        $y = $hcabecalho;
334
        $y = $this->pCabecalhoSecundarioDANFE($x, $y, $hcabecalhoSecundario);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pCabecalhoSecunda... $hcabecalhoSecundario) (which targets NFePHP\DA\NFe\Danfce::pCabecalhoSecundarioDANFE()) 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...
335
        //COLOCA PRODUTOS
336
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario;
337
        $y = $this->pProdutosDANFE($x, $y, $hprodutos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pProdutosDANFE($x, $y, $hprodutos) (which targets NFePHP\DA\NFe\Danfce::pProdutosDANFE()) 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...
338
        //COLOCA TOTAL
339
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos;
340
        $y = $this->pTotalDANFE($x, $y, $hTotal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pTotalDANFE($x, $y, $hTotal) (which targets NFePHP\DA\NFe\Danfce::pTotalDANFE()) 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...
341
        //COLOCA PAGAMENTOS
342
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal;
343
        $y = $this->pPagamentosDANFE($x, $y, $hpagamentos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pPagamentosDANFE($x, $y, $hpagamentos) (which targets NFePHP\DA\NFe\Danfce::pPagamentosDANFE()) 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...
344
        //COLOCA MENSAGEM FISCAL
345
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal+ $hpagamentos;
346
        $y = $this->pFiscalDANFE($x, $y, $hmsgfiscal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pFiscalDANFE($x, $y, $hmsgfiscal) (which targets NFePHP\DA\NFe\Danfce::pFiscalDANFE()) 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...
347
        //COLOCA CONSUMIDOR
348
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal;
349
        $y = $this->pConsumidorDANFE($x, $y, $hcliente);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pConsumidorDANFE($x, $y, $hcliente) (which targets NFePHP\DA\NFe\Danfce::pConsumidorDANFE()) 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...
350
        //COLOCA QRCODE
351
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos
352
            + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente;
353
        $y = $this->pQRDANFE($x, $y, $hQRCode);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pQRDANFE($x, $y, $hQRCode) (which targets NFePHP\DA\NFe\Danfce::pQRDANFE()) 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...
354
        
355
        //adiciona as informações opcionais
356
        if (!empty($this->textoAdic)) {
357
            $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos
358
            + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente + $hQRCode;
359
            $hInfAdic = 0;
360
            $y = $this->pInfAdic($x, $y, $hInfAdic);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pInfAdic($x, $y, $hInfAdic) (which targets NFePHP\DA\NFe\Danfce::pInfAdic()) 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...
361
        }
362
        
363
        //retorna o ID na NFe
364
        if ($classPdf!==false) {
365
            $aR = [
366
             'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
367
             'classe_PDF'=>$this->pdf
368
            ];
369
            return $aR;
370
        } else {
371
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
372
        }
373
    }
374
    
375
    protected function pCabecalhoDANFE($x = 0, $y = 0, $h = 0, $pag = '1', $totPag = '1')
0 ignored issues
show
Unused Code introduced by
The parameter $x 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...
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...
Unused Code introduced by
The parameter $totPag 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...
376
    {
377
        $emitRazao  = $this->pSimpleGetValue($this->emit, "xNome");
378
        $emitCnpj   = $this->pSimpleGetValue($this->emit, "CNPJ");
379
        $emitCnpj   = $this->pFormat($emitCnpj, "##.###.###/####-##");
380
        $emitIE     = $this->pSimpleGetValue($this->emit, "IE");
381
        $emitIM     = $this->pSimpleGetValue($this->emit, "IM");
382
        $emitFone = $this->pSimpleGetValue($this->enderEmit, "fone");
383
        $foneLen = strlen($emitFone);
384
        if ($foneLen>0) {
385
            $ddd = substr($emitFone, 0, 2);
386
            $fone1 = substr($emitFone, -8);
387
            $digito9 = ' ';
388
            if ($foneLen == 11) {
389
                $digito9 = substr($emitFone, 2, 1);
390
            }
391
            $emitFone = ' - ('.$ddd.') '.$digito9. ' ' . substr($fone1, 0, 4) . '-' . substr($fone1, -4);
392
        } else {
393
            $emitFone = '';
394
        }
395
        $emitLgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
396
        $emitNro = $this->pSimpleGetValue($this->enderEmit, "nro");
397
        $emitCpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", "");
398
        $emitBairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
399
        $emitCEP = $this->pFormat($this->pSimpleGetValue($this->enderEmit, "CEP"), "#####-###");
400
        $emitMun = $this->pSimpleGetValue($this->enderEmit, "xMun");
401
        $emitUF = $this->pSimpleGetValue($this->enderEmit, "UF");
402
        // CONFIGURAÇÃO DE POSIÇÃO
403
        $margemInterna = $this->margemInterna;
404
        $maxW = $this->wPrint;
405
        $h = $h-($margemInterna);
406
        //COLOCA LOGOMARCA
407
        if (is_file($this->logomarca)) {
408
            $xImg = $margemInterna;
409
            $yImg = $margemInterna + 1;
410
            $this->pdf->Image($this->logomarca, $xImg, $yImg, 30, 22.5);
411
            $xRs = ($maxW*0.4) + $margemInterna;
412
            $wRs = ($maxW*0.6);
413
            $alignEmit = 'L';
414
        } else {
415
            $xRs = $margemInterna;
416
            $wRs = ($maxW*1);
417
            $alignEmit = 'L';
418
        }
419
        //COLOCA RAZÃO SOCIAL
420
        $texto = $emitRazao;
421
        $texto = $texto . "\nCNPJ:" . $emitCnpj;
422
        $texto = $texto . "\nIE:" . $emitIE;
423
        if (!empty($emitIM)) {
424
            $texto = $texto . " - IM:" . $emitIM;
425
        }
426
        $texto = $texto . "\n" . $emitLgr . "," . $emitNro . " " . $emitCpl . "," . $emitBairro
427
                . ". CEP:" . $emitCEP . ". " . $emitMun . "-" . $emitUF . $emitFone;
428
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
429
        $this->pTextBox($xRs, $y, $wRs, $h, $texto, $aFont, 'C', $alignEmit, 0, '', false);
430
    }
431
    
432
    protected function pCabecalhoSecundarioDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
433
    {
434
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
435
        $maxW = $this->wPrint;
436
        $w = ($maxW*1);
437
        $hBox1 = 7;
438
        $texto = "DANFE NFC-e\nDocumento Auxiliar da Nota Fiscal de Consumidor Eletrônica";
439
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
440
        $this->pTextBox($x, $y, $w, $hBox1, $texto, $aFont, 'C', 'C', 0, '', false);
441
        $hBox2 = 4;
442
        $yBox2 = $y + $hBox1;
443
        $texto = "\nNFC-e não permite aproveitamento de crédito de ICMS";
444
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
445
        $this->pTextBox($x, $yBox2, $w, $hBox2, $texto, $aFont, 'C', 'C', 0, '', false);
446
    }
447
    
448
    protected function pProdutosDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
449
    {
450
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
451
        $maxW = $this->wPrint;
452
        $qtdItens = $this->det->length;
453
        $w = ($maxW*1);
454
        $hLinha = $this->hLinha;
455
        $aFontCabProdutos = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
456
        $wBoxCod = $w*0.17;
457
        $texto = "CÓDIGO";
458
        $this->pTextBox($x, $y, $wBoxCod, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
459
        $wBoxDescricao = $w*0.43;
460
        $xBoxDescricao = $wBoxCod + $x;
461
        $texto = "DESCRICÃO";
462
        $this->pTextBox(
463
            $xBoxDescricao,
464
            $y,
465
            $wBoxDescricao,
466
            $hLinha,
467
            $texto,
468
            $aFontCabProdutos,
469
            'T',
470
            'L',
471
            0,
472
            '',
473
            false
474
        );
475
        $wBoxQt = $w*0.08;
476
        $xBoxQt = $wBoxDescricao + $xBoxDescricao;
477
        $texto = "QT";
478
        $this->pTextBox($xBoxQt, $y, $wBoxQt, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
479
        $wBoxUn = $w*0.06;
480
        $xBoxUn = $wBoxQt + $xBoxQt;
481
        $texto = "UN";
482
        $this->pTextBox($xBoxUn, $y, $wBoxUn, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
483
        $wBoxVl = $w*0.13;
484
        $xBoxVl = $wBoxUn + $xBoxUn;
485
        $texto = "VALOR";
486
        $this->pTextBox($xBoxVl, $y, $wBoxVl, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
487
        $wBoxTotal = $w*0.13;
488
        $xBoxTotal = $wBoxVl + $xBoxVl;
489
        $texto = "TOTAL";
490
        $this->pTextBox($xBoxTotal, $y, $wBoxTotal, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
491
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha 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...
492
        $hMaxLinha = $this->hMaxLinha;
493
        $cont = 0;
494
        $aFontProdutos = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
495
        if ($qtdItens > 0) {
496
            foreach ($this->det as $detI) {
497
                $thisItem   = $detI;
498
                $prod       = $thisItem->getElementsByTagName("prod")->item(0);
499
                $nitem      = $thisItem->getAttribute("nItem");
0 ignored issues
show
Unused Code introduced by
$nitem 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...
500
                $cProd      = $this->pSimpleGetValue($prod, "cProd");
501
                $xProd      = $this->pSimpleGetValue($prod, "xProd");
502
                $qCom       = number_format($this->pSimpleGetValue($prod, "qCom"), 2, ",", ".");
503
                $uCom       = $this->pSimpleGetValue($prod, "uCom");
504
                $vUnCom     = number_format($this->pSimpleGetValue($prod, "vUnCom"), 2, ",", ".");
505
                $vProd      = number_format($this->pSimpleGetValue($prod, "vProd"), 2, ",", ".");
506
                //COLOCA PRODUTO
507
                $yBoxProd = $y + $hLinha + ($cont*$hMaxLinha);
508
                //COLOCA PRODUTO CÓDIGO
509
                $wBoxCod = $w*0.17;
510
                $texto = $cProd;
511
                $this->pTextBox($x, $yBoxProd, $wBoxCod, $hMaxLinha, $texto, $aFontProdutos, 'C', 'C', 0, '', false);
512
                //COLOCA PRODUTO DESCRIÇÃO
513
                $wBoxDescricao = $w*0.43;
514
                $xBoxDescricao = $wBoxCod + $x;
515
                $texto = $xProd;
516
                $this->pTextBox(
517
                    $xBoxDescricao,
518
                    $yBoxProd,
519
                    $wBoxDescricao,
520
                    $hMaxLinha,
521
                    $texto,
522
                    $aFontProdutos,
523
                    'C',
524
                    'L',
525
                    0,
526
                    '',
527
                    false
528
                );
529
                //COLOCA PRODUTO QUANTIDADE
530
                $wBoxQt = $w*0.08;
531
                $xBoxQt = $wBoxDescricao + $xBoxDescricao;
532
                $texto = $qCom;
533
                $this->pTextBox(
534
                    $xBoxQt,
535
                    $yBoxProd,
536
                    $wBoxQt,
537
                    $hMaxLinha,
538
                    $texto,
539
                    $aFontProdutos,
540
                    'C',
541
                    'C',
542
                    0,
543
                    '',
544
                    false
545
                );
546
                //COLOCA PRODUTO UNIDADE
547
                $wBoxUn = $w*0.06;
548
                $xBoxUn = $wBoxQt + $xBoxQt;
549
                $texto = $uCom;
550
                $this->pTextBox(
551
                    $xBoxUn,
552
                    $yBoxProd,
553
                    $wBoxUn,
554
                    $hMaxLinha,
555
                    $texto,
556
                    $aFontProdutos,
557
                    'C',
558
                    'C',
559
                    0,
560
                    '',
561
                    false
562
                );
563
                //COLOCA PRODUTO VL UNITÁRIO
564
                $wBoxVl = $w*0.13;
565
                $xBoxVl = $wBoxUn + $xBoxUn;
566
                $texto = $vUnCom;
567
                $this->pTextBox(
568
                    $xBoxVl,
569
                    $yBoxProd,
570
                    $wBoxVl,
571
                    $hMaxLinha,
572
                    $texto,
573
                    $aFontProdutos,
574
                    'C',
575
                    'R',
576
                    0,
577
                    '',
578
                    false
579
                );
580
                //COLOCA PRODUTO VL TOTAL
581
                $wBoxTotal = $w*0.13;
582
                $xBoxTotal = $wBoxVl + $xBoxVl;
583
                $texto = $vProd;
584
                $this->pTextBox(
585
                    $xBoxTotal,
586
                    $yBoxProd,
587
                    $wBoxTotal,
588
                    $hMaxLinha,
589
                    $texto,
590
                    $aFontProdutos,
591
                    'C',
592
                    'R',
593
                    0,
594
                    '',
595
                    false
596
                );
597
                
598
                $cont++;
599
            }
600
        }
601
    }
602
    
603
    protected function pTotalDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
604
    {
605
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
606
        $maxW = $this->wPrint;
607
        $hLinha = 3;
608
        $wColEsq = ($maxW*0.7);
609
        $wColDir = ($maxW*0.3);
610
        $xValor = $x + $wColEsq;
611
        $qtdItens = $this->det->length;
612
        $vProd = $this->pSimpleGetValue($this->ICMSTot, "vProd");
613
        $vNF = $this->pSimpleGetValue($this->ICMSTot, "vNF");
614
        $vDesc  = $this->pSimpleGetValue($this->ICMSTot, "vDesc");
615
        $vFrete = $this->pSimpleGetValue($this->ICMSTot, "vFrete");
616
        $vTotTrib = $this->pSimpleGetValue($this->ICMSTot, "vTotTrib");
617
        $texto = "Qtd. Total de Itens";
618
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
619
        $this->pTextBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
620
        $texto = $qtdItens;
621
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
622
        $this->pTextBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
623
        $yTotal = $y + ($hLinha);
624
        $texto = "Total de Produtos";
625
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
626
        $this->pTextBox($x, $yTotal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
627
        $texto = "R$ " . number_format($vProd, 2, ",", ".");
628
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
629
        $this->pTextBox($xValor, $yTotal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
630
        $yDesconto = $y + ($hLinha*2);
631
        $texto = "Descontos";
632
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
633
        $this->pTextBox($x, $yDesconto, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
634
        $texto = "R$ " . $vDesc;
635
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
636
        $this->pTextBox($xValor, $yDesconto, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
637
        $yFrete= $y + ($hLinha*3);
638
        $texto = "Frete";
639
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
640
        $this->pTextBox($x, $yFrete, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
641
        $texto = "R$ " . $vFrete;
642
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
643
        $this->pTextBox($xValor, $yFrete, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
644
        $yTotalFinal = $y + ($hLinha*4);
645
        $texto = "Total";
646
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
647
        $this->pTextBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
648
        $texto = "R$ " . $vNF;
649
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
650
        $this->pTextBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
651
        $yTotalFinal = $y + ($hLinha*5);
652
        $texto = "Informação dos Tributos Totais Incidentes";
653
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
654
        $this->pTextBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
655
        $texto = "R$ " . $vTotTrib;
656
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
657
        $this->pTextBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
658
    }
659
    
660
    protected function pPagamentosDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
661
    {
662
        $y += 6;
663
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

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

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

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

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

Loading history...
664
        $maxW = $this->wPrint;
665
        $qtdPgto = $this->pag->length;
666
        $w = ($maxW*1);
667
        $hLinha = $this->hLinha;
668
        $wColEsq = ($maxW*0.7);
669
        $wColDir = ($maxW*0.3);
0 ignored issues
show
Unused Code introduced by
$wColDir 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...
670
        $xValor = $x + $wColEsq;
0 ignored issues
show
Unused Code introduced by
$xValor 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...
671
        $aFontPgto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
672
        $wBoxEsq = $w*0.7;
673
        $texto = "FORMA DE PAGAMENTO";
674
        $this->pTextBox($x, $y, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
675
        $wBoxDir = $w*0.3;
676
        $xBoxDescricao = $x + $wBoxEsq;
677
        $texto = "VALOR PAGO";
678
        $this->pTextBox($xBoxDescricao, $y, $wBoxDir, $hLinha, $texto, $aFontPgto, 'T', 'R', 0, '', false);
679
        $cont = 0;
680
        if ($qtdPgto > 0) {
681
            foreach ($this->pag as $pagI) {
682
                $tPag = $this->pSimpleGetValue($pagI, "tPag");
683
                $tPagNome = $this->tipoPag($tPag);
684
                $tPnome = $tPagNome;
0 ignored issues
show
Unused Code introduced by
$tPnome 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...
685
                $vPag = number_format($this->pSimpleGetValue($pagI, "vPag"), 2, ",", ".");
686
                $card = $pagI->getElementsByTagName("card")->item(0);
687
                $cardCNPJ = '';
0 ignored issues
show
Unused Code introduced by
$cardCNPJ 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...
688
                $tBand = '';
0 ignored issues
show
Unused Code introduced by
$tBand 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...
689
                $tBandNome = '';
0 ignored issues
show
Unused Code introduced by
$tBandNome 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...
690
                if (isset($card)) {
691
                    $cardCNPJ = $this->pSimpleGetValue($card, "CNPJ");
0 ignored issues
show
Unused Code introduced by
$cardCNPJ 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...
692
                    $tBand    = $this->pSimpleGetValue($card, "tBand");
693
                    $cAut = $this->pSimpleGetValue($card, "cAut");
0 ignored issues
show
Unused Code introduced by
$cAut 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...
694
                    $tBandNome = self::getCardName($tBand);
0 ignored issues
show
Unused Code introduced by
$tBandNome 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...
695
                }
696
                //COLOCA PRODUTO
697
                $yBoxProd = $y + $hLinha + ($cont*$hLinha);
698
                //COLOCA PRODUTO CÓDIGO
699
                $texto = $tPagNome;
700
                $this->pTextBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
701
                //COLOCA PRODUTO DESCRIÇÃO
702
                $xBoxDescricao = $wBoxEsq + $x;
703
                $texto = "R$ " . $vPag;
704
                $this->pTextBox(
705
                    $xBoxDescricao,
706
                    $yBoxProd,
707
                    $wBoxDir,
708
                    $hLinha,
709
                    $texto,
710
                    $aFontPgto,
711
                    'C',
712
                    'R',
713
                    0,
714
                    '',
715
                    false
716
                );
717
                $cont++;
718
            }
719
        }
720
    }
721
    
722
    protected function pFiscalDANFE($x = 0, $y = 0, $h = 0)
723
    {
724
        $y += 6;
725
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
726
        $maxW = $this->wPrint;
727
        $w = ($maxW*1);
728
        $hLinha = $this->hLinha;
729
        $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
730
        $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
731
        $digVal = $this->pSimpleGetValue($this->nfe, "DigestValue");
0 ignored issues
show
Unused Code introduced by
$digVal 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...
732
        $chNFe = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
733
        $tpAmb = $this->pSimpleGetValue($this->ide, 'tpAmb');
734
        
735
        if ($this->pNotaCancelada()) {
736
            //101 Cancelamento
737
            $this->pdf->SetTextColor(255, 0, 0);
738
            $texto = "NFCe CANCELADA";
739
            $this->pTextBox($x, $y - 25, $w, $h, $texto, $aFontTit, 'C', 'C', 0, '');
740
            $this->pdf->SetTextColor(0, 0, 0);
741
        }
742
        
743
        if ($this->pNotaDenegada()) {
744
            //uso denegado
745
            $this->pdf->SetTextColor(255, 0, 0);
746
            $texto = "NFCe CANCELADA";
747
            $this->pTextBox($x, $y - 25, $w, $h, $texto, $aFontTit, 'C', 'C', 0, '');
748
            $this->pdf->SetTextColor(0, 0, 0);
749
        }
750
        
751
        $cUF = $this->pSimpleGetValue($this->ide, 'cUF');
752
        $nNF = $this->pSimpleGetValue($this->ide, 'nNF');
753
        $serieNF = str_pad($this->pSimpleGetValue($this->ide, "serie"), 3, "0", STR_PAD_LEFT);
754
        $dhEmi = $this->pSimpleGetValue($this->ide, "dhEmi");
755
        $urlChave = $this->urlConsulta[$tpAmb][$this->UFSigla[$cUF]];
756
        $texto = "ÁREA DE MENSAGEM FISCAL";
757
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
758
        $yTex1 = $y + ($hLinha*1);
759
        $hTex1 = $hLinha*2;
760
        $texto = "Número " . $nNF . " Série " . $serieNF . " " .$dhEmi . " - Via Consumidor";
761
        $this->pTextBox($x, $yTex1, $w, $hTex1, $texto, $aFontTex, 'C', 'C', 0, '', false);
762
        $yTex2 = $y + ($hLinha*3);
763
        $hTex2 = $hLinha*2;
764
        $texto = "Consulte pela Chave de Acesso em " . $urlChave;
765
        $this->pTextBox($x, $yTex2, $w, $hTex2, $texto, $aFontTex, 'C', 'C', 0, '', false);
766
        $texto = "CHAVE DE ACESSO";
767
        $yTit2 = $y + ($hLinha*5);
768
        $this->pTextBox($x, $yTit2, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
769
        $yTex3 = $y + ($hLinha*6);
770
        $texto = $chNFe;
771
        $this->pTextBox($x, $yTex3, $w, $hLinha, $texto, $aFontTex, 'C', 'C', 0, '', false);
772
    }
773
    
774
    protected function pConsumidorDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
775
    {
776
        $y += 6;
777
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
778
        $maxW = $this->wPrint;
779
        $w = ($maxW*1);
780
        $hLinha = $this->hLinha;
781
        $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
782
        $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
783
        $texto = "CONSUMIDOR";
784
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
785
        if (isset($this->dest)) {
786
            $considEstrangeiro = !empty($this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue)
787
                    ? $this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue
788
                    : '';
789
            $consCPF = !empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue)
790
                    ? $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue
791
                    : '';
792
            $consCNPJ = !empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)
793
                    ? $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue
794
                    : '';
795
            $cDest = $consCPF.$consCNPJ.$considEstrangeiro; //documentos do consumidor
0 ignored issues
show
Unused Code introduced by
$cDest 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...
796
            $enderDest = $this->dest->getElementsByTagName("enderDest")->item(0);
797
            $consNome = $this->pSimpleGetValue($this->dest, "xNome");
798
            $consLgr = $this->pSimpleGetValue($enderDest, "xLgr");
799
            $consNro = $this->pSimpleGetValue($enderDest, "nro");
800
            $consCpl = $this->pSimpleGetValue($enderDest, "xCpl", " - ");
801
            $consBairro = $this->pSimpleGetValue($enderDest, "xBairro");
802
            $consCEP = $this->pFormat($this->pSimpleGetValue($enderDest, "CEP"));
803
            $consMun = $this->pSimpleGetValue($enderDest, "xMun");
804
            $consUF = $this->pSimpleGetValue($enderDest, "UF");
805
            $considEstrangeiro = $this->pSimpleGetValue($this->dest, "idEstrangeiro");
806
            $consCPF = $this->pSimpleGetValue($this->dest, "CPF");
807
            $consCNPJ = $this->pSimpleGetValue($this->dest, "CNPJ");
808
            $consDoc = "";
809
            if (!empty($consCNPJ)) {
810
                $consDoc = "CNPJ: $consCNPJ";
811
            } elseif (!empty($consCPF)) {
812
                $consDoc = "CPF: $consCPF";
813
            } elseif (!empty($considEstrangeiro)) {
814
                $consDoc = "id: $considEstrangeiro";
815
            }
816
            $consEnd = "";
817
            if (!empty($consLgr)) {
818
                $consEnd = $consLgr
819
                    . ","
820
                    . $consNro
821
                    . " "
822
                    . $consCpl
823
                    . ","
824
                    . $consBairro
825
                    . ". CEP:"
826
                    . $consCEP
827
                    . ". "
828
                    . $consMun
829
                    . "-"
830
                    . $consUF;
831
            }
832
            $yTex1 = $y + $hLinha;
833
            $texto = $consNome;
834
            if (!empty($consDoc)) {
835
                $texto .= " - ". $consDoc . "\n" . $consEnd;
836
                $this->pTextBox($x, $yTex1, $w, $hLinha*3, $texto, $aFontTex, 'C', 'C', 0, '', false);
837
            }
838
        } else {
839
            $yTex1 = $y + $hLinha;
840
            $texto = "Consumidor não identificado";
841
            $this->pTextBox($x, $yTex1, $w, $hLinha, $texto, $aFontTex, 'C', 'C', 0, '', false);
842
        }
843
    }
844
    
845
    protected function pQRDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
846
    {
847
        $y += 6;
848
        $margemInterna = $this->margemInterna;
849
        $maxW = $this->wPrint;
850
        $w = ($maxW*1);
851
        $hLinha = $this->hLinha;
0 ignored issues
show
Unused Code introduced by
$hLinha 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...
852
        $hBoxLinha = $this->hBoxLinha;
853
        $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
0 ignored issues
show
Unused Code introduced by
$aFontTit 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...
854
        $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
855
        $dhRecbto = '';
856
        $nProt = '';
857
        if (isset($this->nfeProc)) {
858
            $nProt = $this->pSimpleGetValue($this->nfeProc, "nProt");
859
            $dhRecbto  = $this->pSimpleGetValue($this->nfeProc, "dhRecbto");
860
        }
861
        $barcode = new Barcode();
862
        $bobj = $barcode->getBarcodeObj(
863
            'QRCODE,M',
864
            $this->qrCode,
865
            -4,
866
            -4,
867
            'black',
868
            array(-2, -2, -2, -2)
869
        )->setBackgroundColor('white');
870
        $qrcode = $bobj->getPngData();
871
        $wQr = 50;
872
        $hQr = 50;
873
        $yQr = ($y+$margemInterna);
874
        $xQr = ($w/2) - ($wQr/2);
875
        // prepare a base64 encoded "data url"
876
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
877
        $info = getimagesize($pic);
0 ignored issues
show
Unused Code introduced by
$info 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...
878
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
879
        $dt = new DateTime($dhRecbto);
880
        $yQr = ($yQr+$hQr+$margemInterna);
881
        $this->pTextBox($x, $yQr, $w, $hBoxLinha, "Protocolo de Autorização: " . $nProt . "\n"
882
            . $dt->format('d/m/Y H:i:s'), $aFontTex, 'C', 'C', 0, '', false);
883
    }
884
   
885
    protected function pInfAdic($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
886
    {
887
        $y += 17;
888
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna 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...
889
        $maxW = $this->wPrint;
890
        $w = ($maxW * 1);
891
        $hLinha = $this->hLinha;
892
        $aFontTit = array('font' => $this->fontePadrao, 'size' => 8, 'style' => 'B');
893
        $aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => '');
894
        // seta o textbox do titulo
895
        $texto = "INFORMAÇÃO ADICIONAL";
896
        $heigthText = $this->pTextBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
897
        // atribui o text adicional
898
        $texto = $this->textoAdic;
899
        // seta a quantidade de linhas que o texto vai ocupar
900
        $linhasCount = $this->pdf->WordWrap($texto, $w) + 1;
0 ignored issues
show
Documentation introduced by
$texto is of type string, but the function expects a object<NFePHP\DA\Legacy\type>.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$w is of type integer|double, but the function expects a object<NFePHP\DA\Legacy\type>.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
901
        // atribui a quantidade de linhas do texto adicional conforme o tamanho do texto
902
        $y += $heigthText + $linhasCount + floor($linhasCount * 0.3);
903
        // seta o textbox do texto adicional
904
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $aFontTex, 'C', 'L', 0, '', false);
905
    }
906
    
907
    /**
908
     * printDANFE
909
     * Esta função envia a DANFE em PDF criada para o dispositivo informado.
910
     * O destino da impressão pode ser :
911
     * I-browser
912
     * D-browser com download
913
     * F-salva em um arquivo local com o nome informado
914
     * S-retorna o documento como uma string e o nome é ignorado.
915
     * Para enviar o pdf diretamente para uma impressora indique o
916
     * nome da impressora e o destino deve ser 'S'.
917
     *
918
     * @param  string $nome    Path completo com o nome do arquivo pdf
919
     * @param  string $destino Direção do envio do PDF
920
     * @param  string $printer Identificação da impressora no sistema
921
     * @return string Caso o destino seja S o pdf é retornado como uma string
922
     * @todo   Rotina de impressão direta do arquivo pdf criado
923
     */
924
    public function printDANFE($nome = '', $destino = 'I', $printer = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer 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...
925
    {
926
        $arq = $this->pdf->Output($nome, $destino);
927
        if ($destino == 'S') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
928
            //aqui pode entrar a rotina de impressão direta
929
        }
930
        return $arq;
931
    }
932
    /**
933
     * Dados brutos do PDF
934
     * @return string
935
     */
936
    public function render()
937
    {
938
        return $this->pdf->getPdf();
939
    }
940
    
941
    /**
942
     * anfavea
943
     * Função para transformar o campo cdata do padrão ANFAVEA para
944
     * texto imprimível
945
     *
946
     * @param  string $cdata campo CDATA
947
     * @return string conteúdo do campo CDATA como string
948
     */
949
    protected function pAnfavea($cdata = '')
950
    {
951
        if ($cdata == '') {
952
            return '';
953
        }
954
        //remove qualquer texto antes ou depois da tag CDATA
955
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
956
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
957
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
958
        $cdata = str_replace("> <", "><", $cdata);
959
        $len = strlen($cdata);
960
        $startPos = strpos($cdata, '<');
961
        if ($startPos === false) {
962
            return $cdata;
963
        }
964
        for ($x=$len; $x>0; $x--) {
965
            if (substr($cdata, $x, 1) == '>') {
966
                $endPos = $x;
967
                break;
968
            }
969
        }
970
        if ($startPos > 0) {
971
            $parte1 = substr($cdata, 0, $startPos);
972
        } else {
973
            $parte1 = '';
974
        }
975
        $parte2 = substr($cdata, $startPos, $endPos-$startPos+1);
0 ignored issues
show
Bug introduced by
The variable $endPos 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...
976
        if ($endPos < $len) {
977
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
978
        } else {
979
            $parte3 = '';
980
        }
981
        $texto = trim($parte1).' '.trim($parte3);
982
        if (strpos($parte2, '<CDATA>') === false) {
983
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
984
        } else {
985
            $cdata = $parte2;
986
        }
987
        //carrega o xml CDATA em um objeto DOM
988
        $dom = new Dom();
989
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
990
        //$xml = $dom->saveXML();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
991
        //grupo CDATA infADprod
992
        $id = $dom->getElementsByTagName('id')->item(0);
993
        $div = $dom->getElementsByTagName('div')->item(0);
994
        $entg = $dom->getElementsByTagName('entg')->item(0);
995
        $dest = $dom->getElementsByTagName('dest')->item(0);
996
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
997
        $ref = $dom->getElementsByTagName('ref')->item(0);
998
        if (isset($id)) {
999
            if ($id->hasAttributes()) {
1000
                foreach ($id->attributes as $attr) {
1001
                    $name = $attr->nodeName;
1002
                    $value = $attr->nodeValue;
1003
                    $texto .= " $name : $value";
1004
                }
1005
            }
1006
        }
1007
        if (isset($div)) {
1008
            if ($div->hasAttributes()) {
1009
                foreach ($div->attributes as $attr) {
1010
                    $name = $attr->nodeName;
1011
                    $value = $attr->nodeValue;
1012
                    $texto .= " $name : $value";
1013
                }
1014
            }
1015
        }
1016
        if (isset($entg)) {
1017
            if ($entg->hasAttributes()) {
1018
                foreach ($entg->attributes as $attr) {
1019
                    $name = $attr->nodeName;
1020
                    $value = $attr->nodeValue;
1021
                    $texto .= " $name : $value";
1022
                }
1023
            }
1024
        }
1025
        if (isset($dest)) {
1026
            if ($dest->hasAttributes()) {
1027
                foreach ($dest->attributes as $attr) {
1028
                    $name = $attr->nodeName;
1029
                    $value = $attr->nodeValue;
1030
                    $texto .= " $name : $value";
1031
                }
1032
            }
1033
        }
1034
        if (isset($ctl)) {
1035
            if ($ctl->hasAttributes()) {
1036
                foreach ($ctl->attributes as $attr) {
1037
                    $name = $attr->nodeName;
1038
                    $value = $attr->nodeValue;
1039
                    $texto .= " $name : $value";
1040
                }
1041
            }
1042
        }
1043
        if (isset($ref)) {
1044
            if ($ref->hasAttributes()) {
1045
                foreach ($ref->attributes as $attr) {
1046
                    $name = $attr->nodeName;
1047
                    $value = $attr->nodeValue;
1048
                    $texto .= " $name : $value";
1049
                }
1050
            }
1051
        }
1052
        //grupo CADATA infCpl
1053
        $t = $dom->getElementsByTagName('transmissor')->item(0);
1054
        $r = $dom->getElementsByTagName('receptor')->item(0);
1055
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
1056
        'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
1057
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
1058
        'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
1059
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
1060
        'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
1061
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
1062
        'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
1063
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
1064
        if (isset($t)) {
1065
            if ($t->hasAttributes()) {
1066
                $texto .= " Transmissor ";
1067
                foreach ($t->attributes as $attr) {
1068
                    $name = $attr->nodeName;
1069
                    $value = $attr->nodeValue;
1070
                    $texto .= " $name : $value";
1071
                }
1072
            }
1073
        }
1074
        if (isset($r)) {
1075
            if ($r->hasAttributes()) {
1076
                $texto .= " Receptor ";
1077
                foreach ($r->attributes as $attr) {
1078
                    $name = $attr->nodeName;
1079
                    $value = $attr->nodeValue;
1080
                    $texto .= " $name : $value";
1081
                }
1082
            }
1083
        }
1084
        return $texto;
1085
    }
1086
    
1087
    /**
1088
     * str2Hex
1089
     * Converte string para haxadecimal ASCII
1090
     *
1091
     * @param  string $str
1092
     * @return string
1093
     */
1094
    protected static function str2Hex($str)
1095
    {
1096
        if ($str == '') {
1097
            return '';
1098
        }
1099
        $hex = "";
1100
        $iCount = 0;
1101
        do {
1102
            $hex .= sprintf("%02x", ord($str{$iCount}));
1103
            $iCount++;
1104
        } while ($iCount < strlen($str));
1105
        return $hex;
1106
    }//fim str2Hex
1107
    
1108
    protected static function getCardName($tBand)
1109
    {
1110
        switch ($tBand) {
1111
            case '01':
1112
                $tBandNome = 'VISA';
1113
                break;
1114
            case '02':
1115
                $tBandNome = 'MASTERCARD';
1116
                break;
1117
            case '03':
1118
                $tBandNome = 'AMERICAM EXPRESS';
1119
                break;
1120
            case '04':
1121
                $tBandNome = 'SOROCRED';
1122
                break;
1123
            case '99':
1124
                $tBandNome = 'OUTROS';
1125
        }
1126
        return $tBandNome;
0 ignored issues
show
Bug introduced by
The variable $tBandNome 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...
1127
    }
1128
    
1129
    /**
1130
     * hex2Str
1131
     * Converte hexadecimal ASCII para string
1132
     *
1133
     * @param  string $str
1134
     * @return string
1135
     */
1136
    protected static function hex2Str($str)
1137
    {
1138
        if ($str == '') {
1139
            return '';
1140
        }
1141
        $bin = "";
1142
        $iCount = 0;
1143
        do {
1144
            $bin .= chr(hexdec($str{$iCount}.$str{($iCount + 1)}));
1145
            $iCount += 2;
1146
        } while ($iCount < strlen($str));
1147
        return $bin;
1148
    }
1149
    
1150
    protected function makeQRCode(
1151
        $chNFe,
1152
        $url,
1153
        $tpAmb,
1154
        $cDest = '',
1155
        $dhEmi = '',
1156
        $vNF = '',
1157
        $vICMS = '',
1158
        $digVal = '',
1159
        $idToken = '000001',
1160
        $token = ''
1161
    ) {
1162
        $nVersao = '100';
1163
        $dhHex = self::str2Hex($dhEmi);
1164
        $digHex = self::str2Hex($digVal);
1165
        $seq = '';
1166
        $seq .= 'chNFe=' . $chNFe;
1167
        $seq .= '&nVersao=' . $nVersao;
1168
        $seq .= '&tpAmb=' . $tpAmb;
1169
        if ($cDest != '') {
1170
            $seq .= '&cDest=' . $cDest;
1171
        }
1172
        $seq .= '&dhEmi=' . strtolower($dhHex);
1173
        $seq .= '&vNF=' . $vNF;
1174
        $seq .= '&vICMS=' . $vICMS;
1175
        $seq .= '&digVal=' . strtolower($digHex);
1176
        $seq .= '&cIdToken=' . $idToken;
1177
        //o hash code é calculado com o Token incluso
1178
        $hash = sha1($seq.$token);
1179
        $seq .= '&cHashQRCode='. strtoupper($hash);
1180
        if (strpos($url, '?') === false) {
1181
            $seq = $url.'?'.$seq;
1182
        } else {
1183
            $seq = $url.''.$seq;
1184
        }
1185
        return $seq;
1186
    }
1187
    
1188
    protected function pNotaCancelada()
1189
    {
1190
        if (!isset($this->nfeProc)) {
1191
            return false;
1192
        }
1193
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1194
        return $cStat == '101' ||
1195
                $cStat == '151' ||
1196
                $cStat == '135' ||
1197
                $cStat == '155';
1198
    }
1199
1200
    protected function pNotaDenegada()
1201
    {
1202
        if (!isset($this->nfeProc)) {
1203
            return false;
1204
        }
1205
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1206
        //1 VEZ NO ARQUIVO INTEIRO
1207
        $cStat = $this->pSimpleGetValue($this->nfeProc, "cStat");
1208
        return $cStat == '110' ||
1209
               $cStat == '301' ||
1210
               $cStat == '302';
1211
    }
1212
}
1213