Completed
Push — master ( ea2608...a76314 )
by
unknown
12s
created

Make   D

Complexity

Total Complexity 61

Size/Duplication

Total Lines 1736
Duplicated Lines 8.24 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 11
Bugs 0 Features 0
Metric Value
wmc 61
c 11
b 0
f 0
lcom 1
cbo 3
dl 143
loc 1736
ccs 0
cts 884
cp 0
rs 4.7962

39 Methods

Rating   Name   Duplication   Size   Complexity  
B montaMDFe() 0 43 3
B tagide() 0 132 2
A tagInfMunCarrega() 0 22 1
A tagInfPercurso() 0 13 1
A tagemit() 0 14 1
B tagenderEmit() 0 86 1
A tagInfMunDescarga() 0 23 1
A tagInfCTe() 23 23 1
A tagInfNFe() 23 23 1
A tagInfMDFeTransp() 0 15 1
A tagTot() 0 54 1
A tagLacres() 0 14 1
A taginfAdic() 0 22 1
A tagautXML() 0 20 1
A tagAereo() 0 54 1
B tagTrem() 0 46 1
B tagVag() 0 38 1
A tagAqua() 0 54 1
A tagInfTermCarreg() 0 14 1
A tagInfTermDescarreg() 0 14 1
A tagInfEmbComb() 0 14 1
A tagRodo() 0 22 1
A taginfMDFe() 0 9 1
A tagInfModal() 0 7 1
B tagVeicTracao() 39 39 1
A tagCondutor() 0 22 1
B tagVeicReboque() 40 40 1
B tagValePed() 0 30 1
B zTagVeiculo() 0 105 3
A zTagPropVeiculo() 0 72 2
A zTagMDFe() 0 8 2
A zTagIde() 0 5 1
A zTagLacres() 0 4 1
D zTagInfDoc() 18 33 9
A zTagRodo() 0 15 4
A zTagFerrov() 0 9 2
A zTagAereo() 0 6 2
A zTagAqua() 0 9 2
B zTestaChaveXML() 0 35 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Make often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Make, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace NFePHP\MDFe;
4
5
/**
6
 * Classe a construção do xml do Manifesto Eletrônico de Documentos Fiscais (MDF-e)
7
 * NOTA: Esta classe foi construida conforme estabelecido no
8
 * Manual de Orientação do Contribuinte
9
 * Padrões Técnicos de Comunicação do Manifesto Eletrônico de Documentos Fiscais
10
 * versão 1.00 de Junho de 2012
11
 *
12
 * @category  Library
13
 * @package   nfephp-org/sped-mdfe
14
 * @name      Make.php
15
 * @copyright 2009-2016 NFePHP
16
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
17
 * @link      http://github.com/nfephp-org/sped-mdfe for the canonical source repository
18
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
19
 */
20
21
use NFePHP\Common\DateTime\DateTime;
22
use NFePHP\Common\Base\BaseMake;
23
use \DOMElement;
24
25
class Make extends BaseMake
26
{
27
    /**
28
     * versao
29
     * numero da versão do xml da MDFe
30
     *
31
     * @var string
32
     */
33
    public $versao = '1.00';
34
    /**
35
     * mod
36
     * modelo da MDFe 58
37
     *
38
     * @var integer
39
     */
40
    public $mod = '58';
41
    /**
42
     * chave da MDFe
43
     *
44
     * @var string
45
     */
46
    public $chMDFe = '';
47
48
    //propriedades privadas utilizadas internamente pela classe
49
    /**
50
     * @type string|\DOMNode
51
     */
52
    private $MDFe = '';
53
    /**
54
     * @type string|\DOMNode
55
     */
56
    private $infMDFe = '';
57
    /**
58
     * @type string|\DOMNode
59
     */
60
    private $ide = '';
61
    /**
62
     * @type string|\DOMNode
63
     */
64
    private $emit = '';
65
    /**
66
     * @type string|\DOMNode
67
     */
68
    private $enderEmit = '';
69
    /**
70
     * @type string|\DOMNode
71
     */
72
    private $infModal = '';
73
    /**
74
     * @type string|\DOMNode
75
     */
76
    private $tot = '';
77
    /**
78
     * @type string|\DOMNode
79
     */
80
    private $infAdic = '';
81
    /**
82
     * @type string|\DOMNode
83
     */
84
    private $rodo = '';
85
    /**
86
     * @type string|\DOMNode
87
     */
88
    private $veicTracao = '';
89
    /**
90
     * @type string|\DOMNode
91
     */
92
    private $aereo = '';
93
    /**
94
     * @type string|\DOMNode
95
     */
96
    private $trem = '';
97
    /**
98
     * @type string|\DOMNode
99
     */
100
    private $aqua = '';
101
102
    // Arrays
103
    private $aInfMunCarrega = []; //array de DOMNode
104
    private $aInfPercurso = []; //array de DOMNode
105
    private $aInfMunDescarga = []; //array de DOMNode
106
    private $aInfCTe = []; //array de DOMNode
107
    private $aInfNFe = []; //array de DOMNode
108
    private $aInfMDFe = []; //array de DOMNode
109
    private $aLacres = []; //array de DOMNode
110
    private $aAutXML = []; //array de DOMNode
111
    private $aCondutor = []; //array de DOMNode
112
    private $aReboque = []; //array de DOMNode
113
    private $aDisp = []; //array de DOMNode
114
    private $aVag = []; //array de DOMNode
115
    private $aInfTermCarreg = []; //array de DOMNode
116
    private $aInfTermDescarreg = []; //array de DOMNode
117
    private $aInfEmbComb = []; //array de DOMNode
118
    private $aCountDoc = []; //contador de documentos fiscais
119
120
    /**
121
     *
122
     * @return boolean
123
     */
124
    public function montaMDFe()
125
    {
126
        if (count($this->erros) > 0) {
127
            return false;
128
        }
129
        //cria a tag raiz da MDFe
130
        $this->zTagMDFe();
131
        //monta a tag ide com as tags adicionais
132
        $this->zTagIde();
133
        //tag ide [4]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
134
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "infMDFe"');
0 ignored issues
show
Bug introduced by
It seems like $this->infMDFe can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->ide can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
135
        //tag enderemit [30]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
136
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "emit"');
0 ignored issues
show
Bug introduced by
It seems like $this->emit can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->enderEmit can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
137
        //tag emit [25]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
138
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "infMDFe"');
139
        //tag infModal [41]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
140
        $this->zTagRodo();
141
        $this->zTagAereo();
142
        $this->zTagFerrov();
143
        $this->zTagAqua();
144
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infMDFe"');
0 ignored issues
show
Bug introduced by
It seems like $this->infModal can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
145
        //tag indDoc [44]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
146
        $this->zTagInfDoc();
147
        //tag tot [68]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
148
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "infMDFe"');
0 ignored issues
show
Bug introduced by
It seems like $this->tot can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
149
        //tag lacres [76]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
150
        $this->zTagLacres();
151
        // tag autXML [137]
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
152
        foreach ($this->aAutXML as $aut) {
153
            $this->dom->appChild($this->infMDFe, $aut, 'Falta tag "infMDFe"');
154
        }
155
        //tag infAdic [78]
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
156
        $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infMDFe"');
0 ignored issues
show
Bug introduced by
It seems like $this->infAdic can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
157
        //[1] tag infMDFe (1 A01)
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
158
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "MDFe"');
0 ignored issues
show
Bug introduced by
It seems like $this->MDFe can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
159
        //[0] tag MDFe
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
160
        $this->dom->appChild($this->dom, $this->MDFe, 'Falta DOMDocument');
161
        // testa da chave
162
        $this->zTestaChaveXML($this->dom);
163
        //convert DOMDocument para string
164
        $this->xml = $this->dom->saveXML();
165
        return true;
166
    }
167
168
169
    /**
170
     * taginfMDFe
171
     * Informações da MDFe 1 pai MDFe
172
     * tag MDFe/infMDFe
173
     *
174
     * @param  string $chave
175
     * @param  string $versao
176
     *
177
     * @return DOMElement
178
     */
179
    public function taginfMDFe($chave = '', $versao = '')
180
    {
181
        $this->infMDFe = $this->dom->createElement("infMDFe");
182
        $this->infMDFe->setAttribute("Id", 'MDFe'.$chave);
183
        $this->infMDFe->setAttribute("versao", $versao);
184
        $this->chMDFe = $chave;
185
        $this->versao = $versao;
186
        return $this->infMDFe;
187
    }
188
189
    /**
190
     * tgaide
191
     * Informações de identificação da MDFe 4 pai 1
192
     * tag MDFe/infMDFe/ide
193
     *
194
     * @param  string $cUF
195
     * @param  string $tpAmb
196
     * @param  string $tpEmit
197
     * @param  string $mod
198
     * @param  string $serie
199
     * @param  string $nMDF
200
     * @param  string $cMDF
201
     * @param  string $cDV
202
     * @param  string $modal
203
     * @param  string $dhEmi
204
     * @param  string $tpEmis
205
     * @param  string $procEmi
206
     * @param  string $verProc
207
     * @param  string $ufIni
208
     * @param  string $ufFim
209
     *
210
     * @return DOMElement
211
     */
212
    public function tagide(
213
        $cUF = '',
214
        $tpAmb = '',
215
        $tpEmit = '',
216
        $mod = '58',
217
        $serie = '',
218
        $nMDF = '',
219
        $cMDF = '',
220
        $cDV = '',
221
        $modal = '',
222
        $dhEmi = '',
223
        $tpEmis = '',
224
        $procEmi = '',
225
        $verProc = '',
226
        $ufIni = '',
227
        $ufFim = ''
228
    ) {
229
        $this->tpAmb = $tpAmb;
230
        if ($dhEmi == '') {
231
            $dhEmi = DateTime::convertTimestampToSefazTime();
232
        }
233
        $identificador = '[4] <ide> - ';
234
        $ide = $this->dom->createElement("ide");
235
        $this->dom->addChild(
236
            $ide,
237
            "cUF",
238
            $cUF,
239
            true,
240
            $identificador . "Código da UF do emitente do Documento Fiscal"
241
        );
242
        $this->dom->addChild(
243
            $ide,
244
            "tpAmb",
245
            $tpAmb,
246
            true,
247
            $identificador . "Identificação do Ambiente"
248
        );
249
        $this->dom->addChild(
250
            $ide,
251
            "tpEmit",
252
            $tpEmit,
253
            true,
254
            $identificador . "Indicador da tipo de emitente"
255
        );
256
        $this->dom->addChild(
257
            $ide,
258
            "mod",
259
            $mod,
260
            true,
261
            $identificador . "Código do Modelo do Documento Fiscal"
262
        );
263
        $this->dom->addChild(
264
            $ide,
265
            "serie",
266
            $serie,
267
            true,
268
            $identificador . "Série do Documento Fiscal"
269
        );
270
        $this->dom->addChild(
271
            $ide,
272
            "nMDF",
273
            $nMDF,
274
            true,
275
            $identificador . "Número do Documento Fiscal"
276
        );
277
        $this->dom->addChild(
278
            $ide,
279
            "cMDF",
280
            $cMDF,
281
            true,
282
            $identificador . "Código do numérico do MDF"
283
        );
284
        $this->dom->addChild(
285
            $ide,
286
            "cDV",
287
            $cDV,
288
            true,
289
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
290
        );
291
        $this->dom->addChild(
292
            $ide,
293
            "modal",
294
            $modal,
295
            true,
296
            $identificador . "Modalidade de transporte"
297
        );
298
        $this->dom->addChild(
299
            $ide,
300
            "dhEmi",
301
            $dhEmi,
302
            true,
303
            $identificador . "Data e hora de emissão do Documento Fiscal"
304
        );
305
        $this->dom->addChild(
306
            $ide,
307
            "tpEmis",
308
            $tpEmis,
309
            true,
310
            $identificador . "Tipo de Emissão do Documento Fiscal"
311
        );
312
        $this->dom->addChild(
313
            $ide,
314
            "procEmi",
315
            $procEmi,
316
            true,
317
            $identificador . "Processo de emissão"
318
        );
319
        $this->dom->addChild(
320
            $ide,
321
            "verProc",
322
            $verProc,
323
            true,
324
            $identificador . "Versão do Processo de emissão"
325
        );
326
        $this->dom->addChild(
327
            $ide,
328
            "UFIni",
329
            $ufIni,
330
            true,
331
            $identificador . "Sigla da UF do Carregamento"
332
        );
333
        $this->dom->addChild(
334
            $ide,
335
            "UFFim",
336
            $ufFim,
337
            true,
338
            $identificador . "Sigla da UF do Descarregamento"
339
        );
340
        $this->mod = $mod;
0 ignored issues
show
Documentation Bug introduced by
The property $mod was declared of type integer, but $mod is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
341
        $this->ide = $ide;
342
        return $ide;
343
    }
344
345
    /**
346
     * tagInfMunCarrega
347
     *
348
     * tag MDFe/infMDFe/ide/infMunCarrega
349
     *
350
     * @param  string $cMunCarrega
351
     * @param  string $xMunCarrega
352
     *
353
     * @return DOMElement
354
     */
355
    public function tagInfMunCarrega(
356
        $cMunCarrega = '',
357
        $xMunCarrega = ''
358
    ) {
359
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
360
        $this->dom->addChild(
361
            $infMunCarrega,
362
            "cMunCarrega",
363
            $cMunCarrega,
364
            true,
365
            "Código do Município de Carregamento"
366
        );
367
        $this->dom->addChild(
368
            $infMunCarrega,
369
            "xMunCarrega",
370
            $xMunCarrega,
371
            true,
372
            "Nome do Município de Carregamento"
373
        );
374
        $this->aInfMunCarrega[] = $infMunCarrega;
375
        return $infMunCarrega;
376
    }
377
378
    /**
379
     * tagInfPercurso
380
     *
381
     * tag MDFe/infMDFe/ide/infPercurso
382
     *
383
     * @param  string $ufPer
384
     *
385
     * @return DOMElement
386
     */
387
    public function tagInfPercurso($ufPer = '')
388
    {
389
        $infPercurso = $this->dom->createElement("infPercurso");
390
        $this->dom->addChild(
391
            $infPercurso,
392
            "UFPer",
393
            $ufPer,
394
            true,
395
            "Sigla das Unidades da Federação do percurso"
396
        );
397
        $this->aInfPercurso[] = $infPercurso;
398
        return $infPercurso;
399
    }
400
401
    /**
402
     * tagemit
403
     * Identificação do emitente da MDFe [25] pai 1
404
     * tag MDFe/infMDFe/emit
405
     *
406
     * @param  string $cnpj
407
     * @param  string $numIE
408
     * @param  string $xNome
409
     * @param  string $xFant
410
     *
411
     * @return DOMElement
412
     */
413
    public function tagemit(
414
        $cnpj = '',
415
        $numIE = '',
416
        $xNome = '',
417
        $xFant = ''
418
    ) {
419
        $identificador = '[25] <emit> - ';
420
        $this->emit = $this->dom->createElement("emit");
421
        $this->dom->addChild($this->emit, "CNPJ", $cnpj, true, $identificador . "CNPJ do emitente");
422
        $this->dom->addChild($this->emit, "IE", $numIE, true, $identificador . "Inscrição Estadual do emitente");
423
        $this->dom->addChild($this->emit, "xNome", $xNome, true, $identificador . "Razão Social ou Nome do emitente");
424
        $this->dom->addChild($this->emit, "xFant", $xFant, false, $identificador . "Nome fantasia do emitente");
425
        return $this->emit;
426
    }
427
428
    /**
429
     * tagenderEmit
430
     * Endereço do emitente [30] pai [25]
431
     * tag MDFe/infMDFe/emit/endEmit
432
     *
433
     * @param  string $xLgr
434
     * @param  string $nro
435
     * @param  string $xCpl
436
     * @param  string $xBairro
437
     * @param  string $cMun
438
     * @param  string $xMun
439
     * @param  string $cep
440
     * @param  string $siglaUF
441
     * @param  string $fone
442
     * @param  string $email
443
     *
444
     * @return DOMElement
445
     */
446
    public function tagenderEmit(
447
        $xLgr = '',
448
        $nro = '',
449
        $xCpl = '',
450
        $xBairro = '',
451
        $cMun = '',
452
        $xMun = '',
453
        $cep = '',
454
        $siglaUF = '',
455
        $fone = '',
456
        $email = ''
457
    ) {
458
        $identificador = '[30] <enderEmit> - ';
459
        $this->enderEmit = $this->dom->createElement("enderEmit");
460
        $this->dom->addChild(
461
            $this->enderEmit,
462
            "xLgr",
463
            $xLgr,
464
            true,
465
            $identificador . "Logradouro do Endereço do emitente"
466
        );
467
        $this->dom->addChild(
468
            $this->enderEmit,
469
            "nro",
470
            $nro,
471
            true,
472
            $identificador . "Número do Endereço do emitente"
473
        );
474
        $this->dom->addChild(
475
            $this->enderEmit,
476
            "xCpl",
477
            $xCpl,
478
            false,
479
            $identificador . "Complemento do Endereço do emitente"
480
        );
481
        $this->dom->addChild(
482
            $this->enderEmit,
483
            "xBairro",
484
            $xBairro,
485
            true,
486
            $identificador . "Bairro do Endereço do emitente"
487
        );
488
        $this->dom->addChild(
489
            $this->enderEmit,
490
            "cMun",
491
            $cMun,
492
            true,
493
            $identificador . "Código do município do Endereço do emitente"
494
        );
495
        $this->dom->addChild(
496
            $this->enderEmit,
497
            "xMun",
498
            $xMun,
499
            true,
500
            $identificador . "Nome do município do Endereço do emitente"
501
        );
502
        $this->dom->addChild(
503
            $this->enderEmit,
504
            "CEP",
505
            $cep,
506
            true,
507
            $identificador . "Código do CEP do Endereço do emitente"
508
        );
509
        $this->dom->addChild(
510
            $this->enderEmit,
511
            "UF",
512
            $siglaUF,
513
            true,
514
            $identificador . "Sigla da UF do Endereço do emitente"
515
        );
516
        $this->dom->addChild(
517
            $this->enderEmit,
518
            "fone",
519
            $fone,
520
            false,
521
            $identificador . "Número de telefone do emitente"
522
        );
523
        $this->dom->addChild(
524
            $this->enderEmit,
525
            "email",
526
            $email,
527
            false,
528
            $identificador . "Endereço de email do emitente"
529
        );
530
        return $this->enderEmit;
531
    }
532
533
    /**
534
     * tagInfMunDescarga
535
     * tag MDFe/infMDFe/infDoc/infMunDescarga
536
     *
537
     * @param  integer $nItem
538
     * @param  string  $cMunDescarga
539
     * @param  string  $xMunDescarga
540
     *
541
     * @return DOMElement
542
     */
543
    public function tagInfMunDescarga(
544
        $nItem = 0,
545
        $cMunDescarga = '',
546
        $xMunDescarga = ''
547
    ) {
548
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
549
        $this->dom->addChild(
550
            $infMunDescarga,
551
            "cMunDescarga",
552
            $cMunDescarga,
553
            true,
554
            "Código do Município de Descarga"
555
        );
556
        $this->dom->addChild(
557
            $infMunDescarga,
558
            "xMunDescarga",
559
            $xMunDescarga,
560
            true,
561
            "Nome do Município de Descarga"
562
        );
563
        $this->aInfMunDescarga[$nItem] = $infMunDescarga;
564
        return $infMunDescarga;
565
    }
566
567
    /**
568
     * tagInfCTe
569
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
570
     *
571
     * @param  integer $nItem
572
     * @param  string  $chCTe
573
     * @param  string  $segCodBarra
574
     *
575
     * @return DOMElement
576
     */
577 View Code Duplication
    public function tagInfCTe(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
578
        $nItem = 0,
579
        $chCTe = '',
580
        $segCodBarra = ''
581
    ) {
582
        $infCTe = $this->dom->createElement("infCTe");
583
        $this->dom->addChild(
584
            $infCTe,
585
            "chCTe",
586
            $chCTe,
587
            true,
588
            "Chave de Acesso CTe"
589
        );
590
        $this->dom->addChild(
591
            $infCTe,
592
            "SegCodBarra",
593
            $segCodBarra,
594
            false,
595
            "Segundo código de barras do CTe"
596
        );
597
        $this->aInfCTe[$nItem][] = $infCTe;
598
        return $infCTe;
599
    }
600
601
    /**
602
     * tagInfNFe
603
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
604
     *
605
     * @param  integer $nItem
606
     * @param  string  $chNFe
607
     * @param  string  $segCodBarra
608
     *
609
     * @return DOMElement
610
     */
611 View Code Duplication
    public function tagInfNFe(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
612
        $nItem = 0,
613
        $chNFe = '',
614
        $segCodBarra = ''
615
    ) {
616
        $infNFe = $this->dom->createElement("infNFe");
617
        $this->dom->addChild(
618
            $infNFe,
619
            "chNFe",
620
            $chNFe,
621
            true,
622
            "Chave de Acesso da NFe"
623
        );
624
        $this->dom->addChild(
625
            $infNFe,
626
            "SegCodBarra",
627
            $segCodBarra,
628
            false,
629
            "Segundo código de barras da NFe"
630
        );
631
        $this->aInfNFe[$nItem][] = $infNFe;
632
        return $infNFe;
633
    }
634
635
    /**
636
     * tagInfMDFeTransp
637
     * tag MDFe/infMDFeTransp/infDoc/infMunDescarga/infMDFeTranspTransp
638
     *
639
     * @param  integer $nItem
640
     * @param  string  $chMDFe
641
     *
642
     * @return DOMElement
643
     */
644
    public function tagInfMDFeTransp(
645
        $nItem = 0,
646
        $chMDFe = ''
647
    ) {
648
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
649
        $this->dom->addChild(
650
            $infMDFeTransp,
651
            "chMDFe",
652
            $chMDFe,
653
            true,
654
            "Chave de Acesso da MDFe"
655
        );
656
        $this->aInfMDFe[$nItem][] = $infMDFeTransp;
657
        return $infMDFeTransp;
658
    }
659
660
    /**
661
     * tagTot
662
     * tag MDFe/infMDFe/tot
663
     *
664
     * @param  string $qCTe
665
     * @param  string $qNFe
666
     * @param  string $qMDFe
667
     * @param  string $vCarga
668
     * @param  string $cUnid
669
     * @param  string $qCarga
670
     *
671
     * @return DOMElement
672
     */
673
    public function tagTot(
674
        $qCTe = '',
675
        $qNFe = '',
676
        $qMDFe = '',
677
        $vCarga = '',
678
        $cUnid = '',
679
        $qCarga = ''
680
    ) {
681
        $tot = $this->dom->createElement("tot");
682
        $this->dom->addChild(
683
            $tot,
684
            "qCTe",
685
            $qCTe,
686
            false,
687
            "Quantidade total de CT-e relacionados no Manifesto"
688
        );
689
        $this->dom->addChild(
690
            $tot,
691
            "qNFe",
692
            $qNFe,
693
            false,
694
            "Quantidade total de NF-e relacionados no Manifesto"
695
        );
696
        $this->dom->addChild(
697
            $tot,
698
            "qMDFe",
699
            $qMDFe,
700
            false,
701
            "Quantidade total de MDF-e relacionados no Manifesto"
702
        );
703
        $this->dom->addChild(
704
            $tot,
705
            "vCarga",
706
            $vCarga,
707
            true,
708
            "Valor total da mercadoria/carga transportada"
709
        );
710
        $this->dom->addChild(
711
            $tot,
712
            "cUnid",
713
            $cUnid,
714
            true,
715
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
716
        );
717
        $this->dom->addChild(
718
            $tot,
719
            "qCarga",
720
            $qCarga,
721
            true,
722
            "Peso Bruto Total da Carga / Mercadoria Transportada"
723
        );
724
        $this->tot = $tot;
725
        return $tot;
726
    }
727
728
    /**
729
     * tagLacres
730
     * tag MDFe/infMDFe/lacres
731
     *
732
     * @param  string $nLacre
733
     *
734
     * @return DOMElement
735
     */
736
    public function tagLacres(
737
        $nLacre = ''
738
    ) {
739
        $lacres = $this->dom->createElement("lacres");
740
        $this->dom->addChild(
741
            $lacres,
742
            "nLacre",
743
            $nLacre,
744
            false,
745
            "Número do lacre"
746
        );
747
        $this->aLacres[] = $lacres;
748
        return $lacres;
749
    }
750
751
    /**
752
     * taginfAdic
753
     * Grupo de Informações Adicionais Z01 pai A01
754
     * tag MDFe/infMDFe/infAdic (opcional)
755
     *
756
     * @param  string $infAdFisco
757
     * @param  string $infCpl
758
     *
759
     * @return DOMElement
760
     */
761
    public function taginfAdic(
762
        $infAdFisco = '',
763
        $infCpl = ''
764
    ) {
765
        $infAdic = $this->dom->createElement("infAdic");
766
        $this->dom->addChild(
767
            $infAdic,
768
            "infAdFisco",
769
            $infAdFisco,
770
            false,
771
            "Informações Adicionais de Interesse do Fisco"
772
        );
773
        $this->dom->addChild(
774
            $infAdic,
775
            "infCpl",
776
            $infCpl,
777
            false,
778
            "Informações Complementares de interesse do Contribuinte"
779
        );
780
        $this->infAdic = $infAdic;
781
        return $infAdic;
782
    }
783
784
    /**
785
     * tagLacres
786
     * tag MDFe/infMDFe/autXML
787
     *
788
     * Autorizados para download do XML do MDF-e
789
     *
790
     * @param string $cnpj
791
     * @param string $cpf
792
     *
793
     * @return DOMElement
794
     */
795
    public function tagautXML($cnpj = '', $cpf = '')
796
    {
797
        $autXML = $this->dom->createElement("autXML");
798
        $this->dom->addChild(
799
            $autXML,
800
            "CNPJ",
801
            $cnpj,
802
            false,
803
            "CNPJ do autorizado"
804
        );
805
        $this->dom->addChild(
806
            $autXML,
807
            "CPF",
808
            $cpf,
809
            false,
810
            "CPF do autorizado"
811
        );
812
        $this->aAutXML[] = $autXML;
813
        return $autXML;
814
    }
815
816
    /**
817
     * tagInfModal
818
     * tag MDFe/infMDFe/infModal
819
     *
820
     * @param  string $versaoModal
821
     *
822
     * @return DOMElement
823
     */
824
    public function tagInfModal($versaoModal = '')
825
    {
826
        $infModal = $this->dom->createElement("infModal");
827
        $infModal->setAttribute("versaoModal", $versaoModal);
828
        $this->infModal = $infModal;
829
        return $infModal;
830
    }
831
832
    /**
833
     * tagAereo
834
     * tag MDFe/infMDFe/infModal/aereo
835
     *
836
     * @param  string $nac
837
     * @param  string $matr
838
     * @param  string $nVoo
839
     * @param  string $cAerEmb
840
     * @param  string $cAerDes
841
     * @param  string $dVoo
842
     *
843
     * @return DOMElement
844
     */
845
    public function tagAereo(
846
        $nac = '',
847
        $matr = '',
848
        $nVoo = '',
849
        $cAerEmb = '',
850
        $cAerDes = '',
851
        $dVoo = ''
852
    ) {
853
        $aereo = $this->dom->createElement("aereo");
854
        $this->dom->addChild(
855
            $aereo,
856
            "nac",
857
            $nac,
858
            true,
859
            "Marca da Nacionalidade da aeronave"
860
        );
861
        $this->dom->addChild(
862
            $aereo,
863
            "matr",
864
            $matr,
865
            true,
866
            "Marca de Matrícula da aeronave"
867
        );
868
        $this->dom->addChild(
869
            $aereo,
870
            "nVoo",
871
            $nVoo,
872
            true,
873
            "Número do Vôo"
874
        );
875
        $this->dom->addChild(
876
            $aereo,
877
            "cAerEmb",
878
            $cAerEmb,
879
            true,
880
            "Aeródromo de Embarque - Código IATA"
881
        );
882
        $this->dom->addChild(
883
            $aereo,
884
            "cAerDes",
885
            $cAerDes,
886
            true,
887
            "Aeródromo de Destino - Código IATA"
888
        );
889
        $this->dom->addChild(
890
            $aereo,
891
            "dVoo",
892
            $dVoo,
893
            true,
894
            "Data do Vôo"
895
        );
896
        $this->aereo = $aereo;
897
        return $aereo;
898
    }
899
900
    /**
901
     * tagTrem
902
     * tag MDFe/infMDFe/infModal/ferrov/trem
903
     *
904
     * @param  string $xPref
905
     * @param  string $dhTrem
906
     * @param  string $xOri
907
     * @param  string $xDest
908
     * @param  string $qVag
909
     *
910
     * @return DOMElement
911
     */
912
    public function tagTrem(
913
        $xPref = '',
914
        $dhTrem = '',
915
        $xOri = '',
916
        $xDest = '',
917
        $qVag = ''
918
    ) {
919
        $trem = $this->dom->createElement("trem");
920
        $this->dom->addChild(
921
            $trem,
922
            "xPref",
923
            $xPref,
924
            true,
925
            "Prefixo do Trem"
926
        );
927
        $this->dom->addChild(
928
            $trem,
929
            "dhTrem",
930
            $dhTrem,
931
            false,
932
            "Data e hora de liberação do trem na origem"
933
        );
934
        $this->dom->addChild(
935
            $trem,
936
            "xOri",
937
            $xOri,
938
            true,
939
            "Origem do Trem"
940
        );
941
        $this->dom->addChild(
942
            $trem,
943
            "xDest",
944
            $xDest,
945
            true,
946
            "Destino do Trem"
947
        );
948
        $this->dom->addChild(
949
            $trem,
950
            "qVag",
951
            $qVag,
952
            true,
953
            "Quantidade de vagões"
954
        );
955
        $this->trem = $trem;
956
        return $trem;
957
    }
958
959
    /**
960
     * tagVag
961
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
962
     *
963
     * @param  string $serie
964
     * @param  string $nVag
965
     * @param  string $nSeq
966
     * @param  string $tonUtil
967
     *
968
     * @return DOMElement
969
     */
970
    public function tagVag(
971
        $serie = '',
972
        $nVag = '',
973
        $nSeq = '',
974
        $tonUtil = ''
975
    ) {
976
        $vag = $this->dom->createElement("vag");
977
        $this->dom->addChild(
978
            $vag,
979
            "serie",
980
            $serie,
981
            true,
982
            "Série de Identificação do vagão"
983
        );
984
        $this->dom->addChild(
985
            $vag,
986
            "nVag",
987
            $nVag,
988
            true,
989
            "Número de Identificação do vagão"
990
        );
991
        $this->dom->addChild(
992
            $vag,
993
            "nSeq",
994
            $nSeq,
995
            false,
996
            "Sequência do vagão na composição"
997
        );
998
        $this->dom->addChild(
999
            $vag,
1000
            "TU",
1001
            $tonUtil,
1002
            true,
1003
            "Tonelada Útil"
1004
        );
1005
        $this->aVag[] = $vag;
1006
        return $vag;
1007
    }
1008
1009
    /**
1010
     * tagAqua
1011
     * tag MDFe/infMDFe/infModal/Aqua
1012
     *
1013
     * @param  string $cnpjAgeNav
1014
     * @param  string $tpEmb
1015
     * @param  string $cEmbar
1016
     * @param  string $nViagem
1017
     * @param  string $cPrtEmb
1018
     * @param  string $cPrtDest
1019
     *
1020
     * @return DOMElement
1021
     */
1022
    public function tagAqua(
1023
        $cnpjAgeNav = '',
1024
        $tpEmb = '',
1025
        $cEmbar = '',
1026
        $nViagem = '',
1027
        $cPrtEmb = '',
1028
        $cPrtDest = ''
1029
    ) {
1030
        $aqua = $this->dom->createElement("Aqua");
1031
        $this->dom->addChild(
1032
            $aqua,
1033
            "CNPJAgeNav",
1034
            $cnpjAgeNav,
1035
            true,
1036
            "CNPJ da Agência de Navegação"
1037
        );
1038
        $this->dom->addChild(
1039
            $aqua,
1040
            "tpEmb",
1041
            $tpEmb,
1042
            true,
1043
            "Código do tipo de embarcação"
1044
        );
1045
        $this->dom->addChild(
1046
            $aqua,
1047
            "cEmbar",
1048
            $cEmbar,
1049
            true,
1050
            "Código da Embarcação"
1051
        );
1052
        $this->dom->addChild(
1053
            $aqua,
1054
            "nViagem",
1055
            $nViagem,
1056
            true,
1057
            "Número da Viagem"
1058
        );
1059
        $this->dom->addChild(
1060
            $aqua,
1061
            "cPrtEmb",
1062
            $cPrtEmb,
1063
            true,
1064
            "Código do Porto de Embarque"
1065
        );
1066
        $this->dom->addChild(
1067
            $aqua,
1068
            "cPrtDest",
1069
            $cPrtDest,
1070
            true,
1071
            "Código do Porto de Destino"
1072
        );
1073
        $this->aqua = $aqua;
1074
        return $aqua;
1075
    }
1076
1077
    /**
1078
     * tagInfTermCarreg
1079
     * tag MDFe/infMDFe/infModal/Aqua/infTermCarreg
1080
     *
1081
     * @param  string $cTermCarreg
1082
     *
1083
     * @return DOMElement
1084
     */
1085
    public function tagInfTermCarreg(
1086
        $cTermCarreg = ''
1087
    ) {
1088
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
1089
        $this->dom->addChild(
1090
            $infTermCarreg,
1091
            "cTermCarreg",
1092
            $cTermCarreg,
1093
            true,
1094
            "Código do Terminal de Carregamento"
1095
        );
1096
        $this->aInfTermCarreg[] = $infTermCarreg;
1097
        return $infTermCarreg;
1098
    }
1099
1100
    /**
1101
     * tagInfTermDescarreg
1102
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
1103
     *
1104
     * @param  string $cTermDescarreg
1105
     *
1106
     * @return DOMElement
1107
     */
1108
    public function tagInfTermDescarreg(
1109
        $cTermDescarreg = ''
1110
    ) {
1111
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
1112
        $this->dom->addChild(
1113
            $infTermDescarreg,
1114
            "cTermCarreg",
1115
            $cTermDescarreg,
1116
            true,
1117
            "Código do Terminal de Descarregamento"
1118
        );
1119
        $this->aInfTermDescarreg[] = $infTermDescarreg;
1120
        return $infTermDescarreg;
1121
    }
1122
1123
    /**
1124
     * tagInfEmbComb
1125
     * tag MDFe/infMDFe/infModal/Aqua/infEmbComb
1126
     *
1127
     * @param  string $cEmbComb
1128
     *
1129
     * @return DOMElement
1130
     */
1131
    public function tagInfEmbComb(
1132
        $cEmbComb = ''
1133
    ) {
1134
        $infEmbComb = $this->dom->createElement("infEmbComb");
1135
        $this->dom->addChild(
1136
            $infEmbComb,
1137
            "cEmbComb",
1138
            $cEmbComb,
1139
            true,
1140
            "Código da embarcação do comboio"
1141
        );
1142
        $this->aInfEmbComb[] = $infEmbComb;
1143
        return $infEmbComb;
1144
    }
1145
1146
    /**
1147
     * tagRodo
1148
     * tag MDFe/infMDFe/infModal/rodo
1149
     *
1150
     * @param  string $rntrc
1151
     * @param  string $ciot
1152
     *
1153
     * @return DOMElement
1154
     */
1155
    public function tagRodo(
1156
        $rntrc = '',
1157
        $ciot = ''
1158
    ) {
1159
        $rodo = $this->dom->createElement("rodo");
1160
        $this->dom->addChild(
1161
            $rodo,
1162
            "RNTRC",
1163
            $rntrc,
1164
            false,
1165
            "Registro Nacional de Transportadores Rodoviários de Carga"
1166
        );
1167
        $this->dom->addChild(
1168
            $rodo,
1169
            "CIOT",
1170
            $ciot,
1171
            false,
1172
            "Código Identificador da Operação de Transporte"
1173
        );
1174
        $this->rodo = $rodo;
1175
        return $rodo;
1176
    }
1177
1178
    /**
1179
     * tagVeicTracao
1180
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
1181
     *
1182
     * @param  string $cInt
1183
     * @param  string $placa
1184
     * @param  string $tara
1185
     * @param  string $capKG
1186
     * @param  string $capM3
1187
     * @param  string $tpRod
1188
     * @param  string $tpCar
1189
     * @param  string $UF
1190
     * @param  string $propRNTRC
1191
     * @param  string $propCPF
1192
     * @param  string $propCNPJ
1193
     * @param  string $propXNome
1194
     * @param  string $propIE
1195
     * @param  string $propUF
1196
     * @param  string $propTpProp
1197
     *
1198
     * @return DOMElement
1199
     */
1200 View Code Duplication
    public function tagVeicTracao(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1201
        $cInt = '',
1202
        $placa = '',
1203
        $tara = '',
1204
        $capKG = '',
1205
        $capM3 = '',
1206
        $tpRod = '',
1207
        $tpCar = '',
1208
        $UF = '',
1209
        $propRNTRC = '',
1210
        $propCPF = '',
1211
        $propCNPJ = '',
1212
        $propXNome = '',
1213
        $propIE = '',
1214
        $propUF = '',
1215
        $propTpProp = ''
1216
    ) {
1217
        $veicTracao = $this->zTagVeiculo(
1218
            'veicTracao',
1219
            $cInt,
1220
            $placa,
1221
            $tara,
1222
            $this->aCondutor,
1223
            $capKG,
1224
            $capM3,
1225
            $tpRod,
1226
            $tpCar,
1227
            $UF,
1228
            $propRNTRC,
1229
            $propCPF,
1230
            $propCNPJ,
1231
            $propXNome,
1232
            $propIE,
1233
            $propUF,
1234
            $propTpProp
1235
        );
1236
        $this->veicTracao = $veicTracao;
1237
        return $veicTracao;
1238
    }
1239
1240
    /**
1241
     * tagCondutor
1242
     * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor
1243
     *
1244
     * @param  string $xNome
1245
     * @param  string $cpf
1246
     *
1247
     * @return DOMElement
1248
     */
1249
    public function tagCondutor(
1250
        $xNome = '',
1251
        $cpf = ''
1252
    ) {
1253
        $condutor = $this->dom->createElement("condutor");
1254
        $this->dom->addChild(
1255
            $condutor,
1256
            "xNome",
1257
            $xNome,
1258
            true,
1259
            "Nome do condutor"
1260
        );
1261
        $this->dom->addChild(
1262
            $condutor,
1263
            "CPF",
1264
            $cpf,
1265
            true,
1266
            "CPF do condutor"
1267
        );
1268
        $this->aCondutor[] = $condutor;
1269
        return $condutor;
1270
    }
1271
1272
    /**
1273
     * tagVeicReboque
1274
     * tag MDFe/infMDFe/infModal/rodo/reboque
1275
     *
1276
     * @param string $cInt
1277
     * @param string $placa
1278
     * @param string $tara
1279
     * @param string $capKG
1280
     * @param string $capM3
1281
     * @param string $propRNTRC
1282
     * @param string $propCPF
1283
     * @param string $propCNPJ
1284
     * @param string $propXNome
1285
     * @param string $propIE
1286
     * @param string $propUF
1287
     * @param string $propTpProp
1288
     * @param string $tpCar
1289
     * @param string $UF
1290
     *
1291
     * @return DOMElement
1292
     */
1293 View Code Duplication
    public function tagVeicReboque(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1294
        $cInt = '',
1295
        $placa = '',
1296
        $tara = '',
1297
        $capKG = '',
1298
        $capM3 = '',
1299
        $propRNTRC = '',
1300
        $propCPF = '',
1301
        $propCNPJ = '',
1302
        $propXNome = '',
1303
        $propIE = '',
1304
        $propUF = '',
1305
        $propTpProp = '',
1306
        $tpCar = '',
1307
        $UF = ''
1308
    ) {
1309
        $reboque = $this->zTagVeiculo(
1310
            'veicReboque',
1311
            $cInt,
1312
            $placa,
1313
            $tara,
1314
            [],
1315
            $capKG,
1316
            $capM3,
1317
            null,
1318
            $tpCar,
1319
            $UF,
1320
            $propRNTRC,
1321
            $propCPF,
1322
            $propCNPJ,
1323
            $propXNome,
1324
            $propIE,
1325
            $propUF,
1326
            $propTpProp
1327
        );
1328
1329
        $this->aReboque[] = $reboque;
1330
1331
        return $reboque;
1332
    }
1333
1334
    /**
1335
     * tagValePed
1336
     * tag MDFe/infMDFe/infModal/rodo/valePed
1337
     *
1338
     * @param  string $cnpjForn
1339
     * @param  string $cnpjPg
1340
     * @param  string $nCompra
1341
     *
1342
     * @return DOMElement
1343
     */
1344
    public function tagValePed(
1345
        $cnpjForn = '',
1346
        $cnpjPg = '',
1347
        $nCompra = ''
1348
    ) {
1349
        $disp = $this->dom->createElement($disp);
0 ignored issues
show
Bug introduced by
The variable $disp seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1350
        $this->dom->addChild(
1351
            $disp,
1352
            "CNPJForn",
1353
            $cnpjForn,
1354
            true,
1355
            "CNPJ da empresa fornecedora do Vale-Pedágio"
1356
        );
1357
        $this->dom->addChild(
1358
            $disp,
1359
            "CNPJPg",
1360
            $cnpjPg,
1361
            false,
1362
            "CNPJ do responsável pelo pagamento do Vale-Pedágio"
1363
        );
1364
        $this->dom->addChild(
1365
            $disp,
1366
            "nCompra",
1367
            $nCompra,
1368
            true,
1369
            "Número do comprovante de compra"
1370
        );
1371
        $this->aDisp[] = $disp;
1372
        return $disp;
1373
    }
1374
1375
    /**
1376
     * zTagVeiculo
1377
     *
1378
     * @param string $tag
1379
     * @param string $cInt
1380
     * @param string $placa
1381
     * @param string $tara
1382
     * @param array  $condutores
1383
     * @param string $capKG
1384
     * @param string $capM3
1385
     * @param string $tpRod
1386
     * @param string $tpCar
1387
     * @param string $UF
1388
     * @param string $propRNTRC
1389
     * @param string $propCPF
1390
     * @param string $propCNPJ
1391
     * @param string $propXNome
1392
     * @param string $propIE
1393
     * @param string $propUF
1394
     * @param string $propTpProp
1395
     *
1396
     * @return DOMElement
1397
     */
1398
    protected function zTagVeiculo(
1399
        $tag = '',
1400
        $cInt = '',
1401
        $placa = '',
1402
        $tara = '',
1403
        $condutores = array(),
1404
        $capKG = '',
1405
        $capM3 = '',
1406
        $tpRod = '',
1407
        $tpCar = '',
1408
        $UF = '',
1409
        $propRNTRC = '',
1410
        $propCPF = '',
1411
        $propCNPJ = '',
1412
        $propXNome = '',
1413
        $propIE = '',
1414
        $propUF = '',
1415
        $propTpProp = ''
1416
    ) {
1417
        $node = $this->dom->createElement($tag);
1418
        $this->dom->addChild(
1419
            $node,
1420
            "cInt",
1421
            $cInt,
1422
            false,
1423
            "Código interno do veículo"
1424
        );
1425
        $this->dom->addChild(
1426
            $node,
1427
            "placa",
1428
            $placa,
1429
            true,
1430
            "Placa do veículo"
1431
        );
1432
        $this->dom->addChild(
1433
            $node,
1434
            "tara",
1435
            $tara,
1436
            true,
1437
            "Tara em KG"
1438
        );
1439
        $this->dom->addArrayChild(
1440
            $node,
0 ignored issues
show
Documentation introduced by
$node is of type object<DOMElement>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1441
            $condutores
1442
        );
1443
        $this->dom->addChild(
1444
            $node,
1445
            "capKG",
1446
            $capKG,
1447
            false,
1448
            "Capacidade em KG"
1449
        );
1450
        $this->dom->addChild(
1451
            $node,
1452
            "capM3",
1453
            $capM3,
1454
            false,
1455
            "Capacidade em M3"
1456
        );
1457
1458
        $prop = $this->zTagPropVeiculo(
1459
            'prop',
1460
            $propCPF,
1461
            $propCNPJ,
1462
            $propRNTRC,
1463
            $propXNome,
1464
            $propIE,
1465
            $propUF,
1466
            $propTpProp
1467
        );
1468
1469
        if ($prop) {
1470
            $node->appendChild($prop);
1471
        }
1472
1473
        if ($condutores) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $condutores of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1474
            $this->dom->addArrayChild(
1475
                $node,
0 ignored issues
show
Documentation introduced by
$node is of type object<DOMElement>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1476
                $condutores
1477
            );
1478
        }
1479
        $this->dom->addChild(
1480
            $node,
1481
            "tpRod",
1482
            $tpRod,
1483
            false,
1484
            "Tipo de rodado"
1485
        );
1486
        $this->dom->addChild(
1487
            $node,
1488
            "tpCar",
1489
            $tpCar,
1490
            true,
1491
            "Tipo de carroceria"
1492
        );
1493
        $this->dom->addChild(
1494
            $node,
1495
            "UF",
1496
            $UF,
1497
            true,
1498
            "UF de licenciamento do veículo"
1499
        );
1500
1501
        return $node;
1502
    }
1503
1504
    /**
1505
     * @param string $tag
1506
     * @param string $CPF
1507
     * @param string $CNPJ
1508
     * @param string $RNTRC
1509
     * @param string $xNome
1510
     * @param string $IE
1511
     * @param string $UF
1512
     * @param string $tpProp
1513
     *
1514
     * @return DOMElement
1515
     */
1516
    protected function zTagPropVeiculo(
1517
        $tag = '',
1518
        $CPF = '',
1519
        $CNPJ = '',
1520
        $RNTRC = '',
1521
        $xNome = '',
1522
        $IE = '',
1523
        $UF = '',
1524
        $tpProp = ''
1525
    ) {
1526
        $args = func_get_args();
1527
        unset($args[0]);
1528
1529
        if (!array_filter($args)) {
1530
            return false;
1531
        }
1532
1533
        $identificador = "<{$tag}> - ";
1534
        $nodeProp = $this->dom->createElement($tag);
1535
1536
        $this->dom->addChild(
1537
            $nodeProp,
1538
            'CPF',
1539
            $CPF,
1540
            false,
1541
            "{$identificador} Número do CPF do proprietário"
1542
        );
1543
        $this->dom->addChild(
1544
            $nodeProp,
1545
            'CNPJ',
1546
            $CNPJ,
1547
            false,
1548
            "{$identificador} Número do CNPJ do proprietário"
1549
        );
1550
        $this->dom->addChild(
1551
            $nodeProp,
1552
            'RNTRC',
1553
            $RNTRC,
1554
            true,
1555
            "{$identificador} Registro Nacional dos Transportadores Rodoviários de Carga do proprietário"
1556
        );
1557
        $this->dom->addChild(
1558
            $nodeProp,
1559
            'xNome',
1560
            $xNome,
1561
            true,
1562
            "{$identificador} Razão Social ou Nome do proprietário do proprietário"
1563
        );
1564
        $this->dom->addChild(
1565
            $nodeProp,
1566
            'IE',
1567
            $IE,
1568
            true,
1569
            "{$identificador} Inscrição Estadual do proprietário"
1570
        );
1571
        $this->dom->addChild(
1572
            $nodeProp,
1573
            'UF',
1574
            $UF,
1575
            true,
1576
            "{$identificador} UF do proprietário"
1577
        );
1578
        $this->dom->addChild(
1579
            $nodeProp,
1580
            'tpProp',
1581
            $tpProp,
1582
            true,
1583
            "{$identificador} Tipo do Proprietário"
1584
        );
1585
1586
        return $nodeProp;
1587
    }
1588
1589
    /**
1590
     * zTagMDFe
1591
     * Tag raiz da MDFe
1592
     * tag MDFe DOMNode
1593
     * Função chamada pelo método [ monta ]
1594
     *
1595
     * @return DOMElement
1596
     */
1597
    protected function zTagMDFe()
1598
    {
1599
        if (empty($this->MDFe)) {
1600
            $this->MDFe = $this->dom->createElement("MDFe");
1601
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
1602
        }
1603
        return $this->MDFe;
1604
    }
1605
1606
    /**
1607
     * Adiciona as tags
1608
     * infMunCarrega e infPercurso
1609
     * a tag ide
1610
     */
1611
    protected function zTagIde()
1612
    {
1613
        $this->dom->addArrayChild($this->ide, $this->aInfMunCarrega);
0 ignored issues
show
Documentation introduced by
$this->ide is of type string|object<DOMNode>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1614
        $this->dom->addArrayChild($this->ide, $this->aInfPercurso);
1615
    }
1616
1617
    /**
1618
     * Processa lacres
1619
     */
1620
    protected function zTagLacres()
1621
    {
1622
        $this->dom->addArrayChild($this->infMDFe, $this->aLacres);
0 ignored issues
show
Documentation introduced by
$this->infMDFe is of type string|object<DOMNode>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1623
    }
1624
1625
    /**
1626
     * Proecessa documentos fiscais
1627
     */
1628
    protected function zTagInfDoc()
1629
    {
1630
        $this->aCountDoc = ['CTe'=>0, 'NFe'=>0, 'MDFe'=>0];
1631
        if (! empty($this->aInfMunDescarga)) {
1632
            $infDoc = $this->dom->createElement("infDoc");
1633
            $this->aCountDoc['CTe'] = 0;
1634
            $this->aCountDoc['NFe'] = 0;
1635
            $this->aCountDoc['MDFe'] = 0;
1636
            foreach ($this->aInfMunDescarga as $nItem => $node) {
1637 View Code Duplication
                if (isset($this->aInfCTe[$nItem])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1638
                    $this->aCountDoc['CTe'] += $this->dom->addArrayChild($node, $this->aInfCTe[$nItem]);
1639
                }
1640 View Code Duplication
                if (isset($this->aInfNFe[$nItem])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1641
                    $this->aCountDoc['NFe'] += $this->dom->addArrayChild($node, $this->aInfNFe[$nItem]);
1642
                }
1643 View Code Duplication
                if (isset($this->aInfMDFe[$nItem])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1644
                    $this->aCountDoc['MDFe'] += $this->dom->addArrayChild($node, $this->aInfMDFe[$nItem]);
1645
                }
1646
                $this->dom->appChild($infDoc, $node, '');
1647
            }
1648
            $this->dom->appChild($this->infMDFe, $infDoc, 'Falta tag "infMDFe"');
0 ignored issues
show
Bug introduced by
It seems like $this->infMDFe can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1649
        }
1650
        //ajusta quantidades em tot
1651 View Code Duplication
        if ($this->aCountDoc['CTe'] > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1652
            $this->tot->getElementsByTagName('qCTe')->item(0)->nodeValue = $this->aCountDoc['CTe'];
1653
        }
1654 View Code Duplication
        if ($this->aCountDoc['NFe'] > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1655
            $this->tot->getElementsByTagName('qNFe')->item(0)->nodeValue = $this->aCountDoc['NFe'];
1656
        }
1657 View Code Duplication
        if ($this->aCountDoc['MDFe'] > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1658
            $this->tot->getElementsByTagName('qMDFe')->item(0)->nodeValue = $this->aCountDoc['MDFe'];
1659
        }
1660
    }
1661
1662
    /**
1663
     * Processa modal rodoviario
1664
     */
1665
    protected function zTagRodo()
1666
    {
1667
        if (! empty($this->rodo)) {
1668
            $this->dom->appChild($this->rodo, $this->veicTracao, 'Falta tag "rodo"');
0 ignored issues
show
Bug introduced by
It seems like $this->rodo can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->veicTracao can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1669
            $this->dom->addArrayChild($this->rodo, $this->aReboque);
0 ignored issues
show
Documentation introduced by
$this->rodo is of type object<DOMNode>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1670
            if (! empty($this->aDisp)) {
1671
                $valePed = $this->dom->createElement("valePed");
1672
                foreach ($this->aDisp as $node) {
1673
                    $this->dom->appChild($valePed, $node, '');
1674
                }
1675
                $this->dom->appChild($this->rodo, $valePed, '');
1676
            }
1677
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
0 ignored issues
show
Bug introduced by
It seems like $this->infModal can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1678
        }
1679
    }
1680
1681
    /**
1682
     * Proecessa modal ferroviario
1683
     */
1684
    protected function zTagFerrov()
1685
    {
1686
        if (! empty($this->trem)) {
1687
            $this->dom->addArrayChild($this->trem, $this->aVag);
0 ignored issues
show
Documentation introduced by
$this->trem is of type string|object<DOMNode>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1688
            $ferrov = $this->dom->createElement("ferrov");
1689
            $this->dom->appChild($ferrov, $this->trem, '');
1690
            $this->dom->appChild($this->infModal, $ferrov, 'Falta tag "infModal"');
0 ignored issues
show
Bug introduced by
It seems like $this->infModal can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1691
        }
1692
    }
1693
1694
    /**
1695
     * Processa modal aereo
1696
     */
1697
    protected function zTagAereo()
1698
    {
1699
        if (! empty($this->aereo)) {
1700
            $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "infModal"');
0 ignored issues
show
Bug introduced by
It seems like $this->infModal can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->aereo can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1701
        }
1702
    }
1703
1704
    /**
1705
     * Processa modal aquaviário
1706
     */
1707
    protected function zTagAqua()
1708
    {
1709
        if (! empty($this->aqua)) {
1710
            $this->dom->addArrayChild($this->aqua, $this->aInfTermCarreg);
0 ignored issues
show
Documentation introduced by
$this->aqua is of type string|object<DOMNode>, but the function expects a object<NFePHP\Common\Dom\DOMElement>.

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...
1711
            $this->dom->addArrayChild($this->aqua, $this->aInfTermDescarreg);
1712
            $this->dom->addArrayChild($this->aqua, $this->aInfEmbComb);
1713
            $this->dom->appChild($this->infModal, $this->aqua, 'Falta tag "infModal"');
0 ignored issues
show
Bug introduced by
It seems like $this->infModal can also be of type string; however, NFePHP\Common\Dom\Dom::appChild() does only seem to accept object<DOMNode>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1714
        }
1715
    }
1716
1717
    /**
1718
     * zTestaChaveXML
1719
     * Remonta a chave da NFe de 44 digitos com base em seus dados
1720
     * Isso é útil no caso da chave informada estar errada
1721
     * se a chave estiver errada a mesma é substituida
1722
     *
1723
     * @param object $dom
1724
     */
1725
    private function zTestaChaveXML($dom)
1726
    {
1727
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
1728
        $ide = $dom->getElementsByTagName("ide")->item(0);
1729
        $emit = $dom->getElementsByTagName("emit")->item(0);
1730
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
1731
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
1732
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
1733
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
1734
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
1735
        $nNF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
1736
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
1737
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
1738
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
1739
        $tempData = explode("-", $dhEmi);
1740
        $chaveMontada = $this->montaChave(
1741
            $cUF,
1742
            $tempData[0] - 2000,
1743
            $tempData[1],
1744
            $cnpj,
1745
            $mod,
1746
            $serie,
1747
            $nNF,
1748
            $tpEmis,
1749
            $cNF
1750
        );
1751
        //caso a chave contida na NFe esteja errada
1752
        //substituir a chave
1753
        if ($chaveMontada != $chave) {
1754
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
1755
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
1756
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
1757
            $this->chMDFe = $chaveMontada;
1758
        }
1759
    }
1760
}
1761