Make   F
last analyzed

Complexity

Total Complexity 180

Size/Duplication

Total Lines 3153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 180
lcom 1
cbo 2
dl 0
loc 3153
ccs 0
cts 2480
cp 0
rs 0.8
c 0
b 0
f 0

62 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getXML() 0 7 2
A getChave() 0 4 1
A getModelo() 0 4 1
A setOnlyAscii() 0 4 1
A montaMDFe() 0 4 1
A contaDoc() 0 8 2
B tagide() 0 168 1
A taginfMunCarrega() 0 26 1
A taginfPercurso() 0 18 1
A tagemit() 0 53 2
B tagenderEmit() 0 91 1
A tagrodo() 0 5 1
A tagferrov() 0 7 2
A taginfDoc() 0 7 2
A tagvalePed() 0 7 2
A taginfANTT() 0 18 1
A tagdisp() 0 51 1
A taginfContratante() 0 47 3
A taginfCIOT() 0 37 2
A taginfMunDescarga() 0 28 1
B taginfCTe() 0 72 6
B tagperi() 0 56 1
B taginfNFe() 0 46 5
A taginfMDFeTransp() 0 36 5
B taginfUnidTransp() 0 56 5
A taginfUnidCarga() 0 50 3
B tagseg() 0 79 4
A tagprodPred() 0 44 2
A taginfLotacao() 0 16 3
A tagLocalCarrega() 0 35 2
A tagLocalDescarrega() 0 35 2
C tagtot() 0 84 10
A taglacres() 0 17 1
A taginfAdic() 0 25 1
A tagautXML() 0 25 1
A buildInfModal() 0 19 3
A buildIde() 0 19 5
B tagaereo() 0 58 1
A tagtrem() 0 50 1
B tagVag() 0 66 1
C tagaquav() 0 112 11
A taginfUnidTranspVazia() 0 25 1
A taginfUnidCargaVazia() 0 25 1
A taginfTermDescarreg() 0 25 1
A taginfTermCarreg() 0 26 1
A taginfEmbComb() 0 26 1
A tagcondutor() 0 25 1
B tagveicTracao() 0 157 5
B tagveicReboque() 0 142 3
A tagcodAgPorto() 0 15 1
A taglacRodo() 0 17 1
B taginfRespTec() 0 65 3
B taginfPag() 0 74 6
A infPrazo() 0 33 1
A infBanc() 0 36 2
A buildMDFe() 0 8 2
A checkMDFKey() 0 41 3
A getErrors() 0 4 1
A equilizeParameters() 0 4 1
F monta() 0 123 41
A compPag() 0 33 1

How to fix   Complexity   

Complex Class

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 3.00a
11
 *
12
 * @category  Library
13
 * @package   nfephp-org/sped-mdfe
14
 * @name      Make.php
15
 * @copyright 2009-2019 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    Cleiton Perin <cperin20 at gmail dot com>
19
 * @author    Vanderlei Cavassin <cavassin.vanderlei at gmail dot com>
20
 */
21
22
use DOMElement;
23
use NFePHP\Common\DOMImproved as Dom;
24
use NFePHP\Common\Keys;
25
use NFePHP\Common\Strings;
26
use RuntimeException;
27
use stdClass;
28
29
class Make
30
{
31
    /**
32
     * @var array
33
     */
34
    public $errors = [];
35
    /**
36
     * versao
37
     * numero da versão do xml da MDFe
38
     *
39
     * @var string
40
     */
41
    public $versao = '3.00';
42
    /**
43
     * mod
44
     * modelo da MDFe 58
45
     *
46
     * @var integer
47
     */
48
    public $mod = '58';
49
    /**
50
     * chave da MDFe
51
     *
52
     * @var string
53
     */
54
    public $chMDFe = '';
55
56
    //propriedades privadas utilizadas internamente pela classe
57
    /**
58
     * @type string|\DOMNode
59
     */
60
    private $MDFe = '';
61
    /**
62
     * @type string|\DOMNode
63
     */
64
    private $infMDFe = '';
65
    /**
66
     * @type string|\DOMNode
67
     */
68
    private $ide = '';
69
    /**
70
     * @type string|\DOMNode
71
     */
72
    private $emit = '';
73
    /**
74
     * @type string|\DOMNode
75
     */
76
    private $infANTT = '';
77
    /**
78
     * @type string|\DOMNode
79
     */
80
    private $enderEmit = '';
81
    /**
82
     * @type string|\DOMNode
83
     */
84
    private $infModal = '';
85
    /**
86
     * @type string|\DOMNode
87
     */
88
    private $tot = '';
89
    /**
90
     * @type string|\DOMNode
91
     */
92
    private $seg = [];
93
    /**
94
     * @type string|\DOMNode
95
     */
96
    private $prodPred = null;
97
    /**
98
     * @type string|\DOMNode
99
     */
100
    private $infMunDescarga = [];
101
    /**
102
     * @type string|\DOMNode
103
     */
104
    private $veicReboque = [];
105
    /**
106
     * @type string|\DOMNode
107
     */
108
    private $infNFe = [];
109
    /**
110
     * @type string|\DOMNode
111
     */
112
    private $infCTe = [];
113
    /**
114
     * @type string|\DOMNode
115
     */
116
    private $infMDFeTransp = [];
117
    /**
118
     * @type string|\DOMNode
119
     */
120
    private $infContratante = [];
121
    /**
122
     * @type string|\DOMNode
123
     */
124
    private $infPag = [];
125
    /**
126
     * @type string|\DOMNode
127
     */
128
    private $infLotacao = null;
129
    /**
130
     * @type string|\DOMNode
131
     */
132
    private $autXML = [];
133
    /**
134
     * @type string|\DOMNode
135
     */
136
    private $infCIOT = [];
137
    /**
138
     * @type string|\DOMNode
139
     */
140
    private $disp = [];
141
    /**
142
     * @type string|\DOMNode
143
     */
144
    private $infMunCarrega = [];
145
    /**
146
     * @type string|\DOMNode
147
     */
148
    private $infPercurso = [];
149
    /**
150
     * @type string|\DOMNode
151
     */
152
    private $lacRodo = [];
153
    /**
154
     * @type string|\DOMNode
155
     */
156
    private $vag = [];
157
    /**
158
     * @type string|\DOMNode
159
     */
160
    private $infAdic = '';
161
    /**
162
     * @type string|\DOMNode
163
     */
164
    private $rodo = '';
165
    /**
166
     * @type string|\DOMNode
167
     */
168
    private $ferrov = '';
169
    /**
170
     * @type string|\DOMNode
171
     */
172
    private $infDoc = '';
173
    /**
174
     * @type string|\DOMNode
175
     */
176
    private $valePed = '';
177
    /**
178
     * @type string|\DOMNode
179
     */
180
    private $veicTracao = '';
181
    /**
182
     * @type string|\DOMNode
183
     */
184
    private $infUnidTransp = '';
185
    /**
186
     * @type string|\DOMNode
187
     */
188
    private $aereo = '';
189
    /**
190
     * @type string|\DOMNode
191
     */
192
    private $trem = '';
193
    /**
194
     * @type string|\DOMNode
195
     */
196
    private $aquav = '';
197
    /**
198
     * @type array
199
     */
200
    private $infTermCarreg = [];
201
    /**
202
     * @type array
203
     */
204
    private $infTermDescarreg = [];
205
    /**
206
     * @type array
207
     */
208
    private $infEmbComb = [];
209
    /**
210
     * @type array
211
     */
212
    private $infUnidCargaVazia = [];
213
    /**
214
     * @type array
215
     */
216
    private $infUnidTranspVazia = [];
217
    /**
218
     * @var boolean
219
     */
220
    protected $replaceAccentedChars = false;
221
222
    /**
223
     * Função construtora cria um objeto DOMDocument
224
     * que será carregado com o documento fiscal
225
     */
226
    public function __construct()
227
    {
228
        $this->dom = new Dom('1.0', 'UTF-8');
0 ignored issues
show
Bug introduced by Marcio Souza
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...
229
        $this->dom->preserveWhiteSpace = false;
230
        $this->dom->formatOutput = false;
231
    }
232
233
    /**
234
     * Retorns the xml
235
     *
236
     * @return xml
237
     */
238
    public function getXML()
239
    {
240
        if (empty($this->xml)) {
0 ignored issues
show
Bug introduced by Marcio Souza
The property xml 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...
241
            $this->montaMDFe();
242
        }
243
        return $this->xml;
244
    }
245
246
    /**
247
     * Retorns the key number of NFe (44 digits)
248
     *
249
     * @return string
250
     */
251
    public function getChave()
252
    {
253
        return $this->chMDFe;
254
    }
255
256
    /**
257
     * Returns the model of MDFe
258
     *
259
     * @return int
260
     */
261
    public function getModelo()
262
    {
263
        return $this->mod;
264
    }
265
266
    /**
267
     * Set character convertion to ASCII only ou not
268
     * @param bool $option
269
     */
270
    public function setOnlyAscii($option = false)
271
    {
272
        $this->replaceAccentedChars = $option;
273
    }
274
275
    /**
276
     * Call method of xml assembly. For compatibility only.
277
     *
278
     * @return boolean
279
     */
280
    public function montaMDFe()
281
    {
282
        return $this->monta();
283
    }
284
285
    /**
286
     * @param $indDoc
287
     * @return int|void
288
     */
289
    private function contaDoc($indDoc)
290
    {
291
        $total = 0;
292
        foreach ($indDoc as $doc) {
293
            $total += count($doc);
294
        }
295
        return $total;
296
    }
297
298
    /**
299
     * MDFe xml mount method
300
     * this function returns TRUE on success or FALSE on error
301
     * The xml of the MDFe must be retrieved by the getXML() function or
302
     * directly by the public property $xml
303
     *
304
     * @return boolean
305
     */
306
    public function monta()
307
    {
308
        $this->errors = $this->dom->errors;
309
        //cria a tag raiz da MDFe
310
        $this->buildMDFe();
311
        $this->buildInfModal();
312
        $this->infMDFe = $this->dom->createElement("infMDFe");
313
        $this->buildIde();
314
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "enderEmit"');
315
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "emit"');
316
        if ($this->rodo) {
317
            $tpEmit = $this->ide->getElementsByTagName('tpEmit')->item(0)->nodeValue;
318
            if (($tpEmit == 1 || $tpEmit == 3) && empty($this->prodPred)) {
319
                $this->errors[] = "Tag prodPred é obrigatória para modal rodoviário!";
320
            }
321
            if (($tpEmit == 1 || $tpEmit == 3) && empty($this->infLotacao) && ($this->contaDoc($this->infCTe) + $this->contaDoc($this->infNFe) + $this->contaDoc($this->infMDFeTransp)) == 1) {
322
                $this->errors[] = "Tag infLotacao é obrigatória quando só existir um Documento informado!";
323
            }
324
            if ($this->infANTT) {
325
                if ($this->infCIOT) {
326
                    $this->dom->addArrayChild($this->infANTT, $this->infCIOT, 'Falta tag "infCIOT"');
327
                }
328
                if ($this->valePed) {
329
                    $this->dom->appChild($this->infANTT, $this->valePed, 'Falta tag "valePed"');
330
                    if ($this->disp) {
331
                        $this->dom->addArrayChild($this->valePed, $this->disp, 'Falta tag "disp"');
332
                    }
333
                }
334
                if ($this->infContratante) {
335
                    $this->dom->addArrayChild($this->infANTT, $this->infContratante, 'Falta tag "infContratante"');
336
                }
337
                if ($this->infPag) {
338
                    $this->dom->addArrayChild($this->infANTT, $this->infPag, 'Falta tag "infpag"');
339
                }
340
                $this->dom->appChild($this->rodo, $this->infANTT, 'Falta tag "infANTT"');
341
            }
342
            if ($this->veicTracao) {
343
                $this->dom->appChild($this->rodo, $this->veicTracao, 'Falta tag "rodo"');
344
            }
345
            if ($this->veicReboque) {
346
                $this->dom->addArrayChild($this->rodo, $this->veicReboque, 'Falta tag "veicReboque"');
347
            }
348
            if ($this->lacRodo) {
349
                $this->dom->addArrayChild($this->rodo, $this->lacRodo, 'Falta tag "lacRodo"');
350
            }
351
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
352
        }
353
        if ($this->aereo) {
354
            $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
355
        }
356
        if ($this->ferrov) {
357
            if ($this->trem) {
358
                $this->dom->appChild($this->ferrov, $this->trem, 'Falta tag "ferrov"');
359
            }
360
            if ($this->vag) {
361
                $this->dom->addArrayChild($this->ferrov, $this->vag, 'Falta tag "vag"');
362
            }
363
            $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
364
        }
365
        if ($this->aquav) {
366
            foreach ($this->infTermCarreg as $termCarreg) {
367
                $this->dom->appChild($this->aquav, $termCarreg, 'Falta tag "aquav"');
368
            }
369
            foreach ($this->infTermDescarreg as $termDescarreg) {
370
                $this->dom->appChild($this->aquav, $termDescarreg, 'Falta tag "aquav"');
371
            }
372
            foreach ($this->infEmbComb as $embComb) {
373
                $this->dom->appChild($this->aquav, $embComb, 'Falta tag "aquav"');
374
            }
375
            foreach ($this->infUnidCargaVazia as $unidCargaVazia) {
376
                $this->dom->appChild($this->aquav, $unidCargaVazia, 'Falta tag "aquav"');
377
            }
378
            foreach ($this->infUnidTranspVazia as $unidTranspVazia) {
379
                $this->dom->appChild($this->aquav, $unidTranspVazia, 'Falta tag "aquav"');
380
            }
381
            $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
382
        }
383
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infModal"');
384
        if ($this->infDoc) {
385
            $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infDoc"');
386
            if ($this->infMunDescarga) {
387
                foreach ($this->infMunDescarga as $key => $value) {
0 ignored issues
show
Bug introduced by uilasmar
The expression $this->infMunDescarga of type string|object<DOMNode> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
388
                    $this->dom->appChild($this->infDoc, $value, 'Falta tag "infMunDescarga"');
389
                    if (isset($this->infCTe[$key])) {
390
                        $this->dom->addArrayChild($value, $this->infCTe[$key], 'Falta tag "infCTe"');
391
                    }
392
                    if (isset($this->infNFe[$key])) {
393
                        $this->dom->addArrayChild($value, $this->infNFe[$key], 'Falta tag "infNFe"');
394
                    }
395
                    if (isset($this->infMDFeTransp[$key])) {
396
                        $this->dom->addArrayChild($value, $this->infMDFeTransp[$key], 'Falta tag "infMDFeTransp"');
397
                    }
398
                }
399
            }
400
        }
401
        if (!empty($this->seg)) {
402
            $this->dom->addArrayChild($this->infMDFe, $this->seg, 'Falta tag "seg"');
403
        }
404
        if (!empty($this->prodPred)) {
405
            $this->dom->appChild($this->infMDFe, $this->prodPred, 'Falta tag "prodPred"');
406
        }
407
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "tot"');
408
        if (!empty($this->lacres)) {
409
            foreach ($this->lacres as $lacres) {
0 ignored issues
show
Bug introduced by Bruno Neves
The property lacres 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...
410
                $this->dom->appChild($this->infMDFe, $lacres, 'Falta tag "lacres"');
411
            }
412
        }
413
        foreach ($this->autXML as $autXML) {
0 ignored issues
show
Bug introduced by Marcio Souza
The expression $this->autXML of type string|object<DOMNode> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
414
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
415
        }
416
        if (!empty($this->infAdic)) {
417
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
418
        }
419
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
420
        $this->dom->appendChild($this->MDFe);
421
        // testa da chave
422
        $this->checkMDFKey($this->dom);
423
        $this->xml = $this->dom->saveXML();
424
        if (count($this->errors) > 0) {
425
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
426
        }
427
        return true;
428
    }
429
430
    /**
431
     * Informações de identificação da MDFe
432
     * tag MDFe/infMDFe/ide
433
     *
434
     * @param  stdClass $std
435
     * @return DOMElement
436
     */
437
    public function tagide(stdClass $std)
438
    {
439
440
        $possible = [
441
            'cUF',
442
            'tpAmb',
443
            'tpEmit',
444
            'tpTransp',
445
            'mod',
446
            'serie',
447
            'nMDF',
448
            'cMDF',
449
            'cDV',
450
            'modal',
451
            'dhEmi',
452
            'tpEmis',
453
            'procEmi',
454
            'verProc',
455
            'UFIni',
456
            'UFFim',
457
            'dhIniViagem',
458
            'indCanalVerde',
459
            'indCarregaPosterior'
460
        ];
461
462
        $std = $this->equilizeParameters($std, $possible);
463
464
        $this->tpAmb = $std->tpAmb;
0 ignored issues
show
Bug introduced by Marcio Souza
The property tpAmb 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...
465
        $identificador = '[4] <ide> - ';
466
        $ide = $this->dom->createElement("ide");
467
        $this->dom->addChild(
468
            $ide,
469
            "cUF",
470
            $std->cUF,
471
            true,
472
            $identificador . "Código da UF do emitente do Documento Fiscal"
473
        );
474
        $this->dom->addChild(
475
            $ide,
476
            "tpAmb",
477
            $std->tpAmb,
478
            true,
479
            $identificador . "Identificação do Ambiente"
480
        );
481
        $this->dom->addChild(
482
            $ide,
483
            "tpEmit",
484
            $std->tpEmit,
485
            true,
486
            $identificador . "Indicador da tipo de emitente"
487
        );
488
        $this->dom->addChild(
489
            $ide,
490
            "tpTransp",
491
            $std->tpTransp,
492
            false,
493
            $identificador . "Tipo do Transportador"
494
        );
495
        $this->dom->addChild(
496
            $ide,
497
            "mod",
498
            $std->mod,
499
            true,
500
            $identificador . "Código do Modelo do Documento Fiscal"
501
        );
502
        $this->dom->addChild(
503
            $ide,
504
            "serie",
505
            $std->serie,
506
            true,
507
            $identificador . "Série do Documento Fiscal"
508
        );
509
        $this->dom->addChild(
510
            $ide,
511
            "nMDF",
512
            $std->nMDF,
513
            true,
514
            $identificador . "Número do Documento Fiscal"
515
        );
516
        $this->dom->addChild(
517
            $ide,
518
            "cMDF",
519
            str_pad($std->cMDF, 8, '0', STR_PAD_LEFT),
520
            true,
521
            $identificador . "Código do numérico do MDF"
522
        );
523
        $this->dom->addChild(
524
            $ide,
525
            "cDV",
526
            $std->cDV,
527
            true,
528
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
529
        );
530
        $this->dom->addChild(
531
            $ide,
532
            "modal",
533
            $std->modal,
534
            true,
535
            $identificador . "Modalidade de transporte"
536
        );
537
        $this->dom->addChild(
538
            $ide,
539
            "dhEmi",
540
            $std->dhEmi,
541
            true,
542
            $identificador . "Data e hora de emissão do Documento Fiscal"
543
        );
544
        $this->dom->addChild(
545
            $ide,
546
            "tpEmis",
547
            $std->tpEmis,
548
            true,
549
            $identificador . "Tipo de Emissão do Documento Fiscal"
550
        );
551
        $this->dom->addChild(
552
            $ide,
553
            "procEmi",
554
            $std->procEmi,
555
            true,
556
            $identificador . "Processo de emissão"
557
        );
558
        $this->dom->addChild(
559
            $ide,
560
            "verProc",
561
            $std->verProc,
562
            true,
563
            $identificador . "Versão do Processo de emissão"
564
        );
565
        $this->dom->addChild(
566
            $ide,
567
            "UFIni",
568
            $std->UFIni,
569
            true,
570
            $identificador . "Sigla da UF do Carregamento"
571
        );
572
        $this->dom->addChild(
573
            $ide,
574
            "UFFim",
575
            $std->UFFim,
576
            true,
577
            $identificador . "Sigla da UF do Descarregamento"
578
        );
579
        $this->dom->addChild(
580
            $ide,
581
            "dhIniViagem",
582
            $std->dhIniViagem,
583
            false,
584
            $identificador . "Data e hora previstos de início da viagem"
585
        );
586
        $this->dom->addChild(
587
            $ide,
588
            "indCanalVerde",
589
            $std->indCanalVerde,
590
            false,
591
            $identificador . "Indicador de participação do Canal Verde"
592
        );
593
        $this->dom->addChild(
594
            $ide,
595
            "indCarregaPosterior",
596
            $std->indCarregaPosterior,
597
            false,
598
            $identificador . "Indicador de MDF-e com inclusão da Carga posterior a emissão por evento de inclusão de DF-e"
599
        );
600
601
        $this->mod = $std->mod;
602
        $this->ide = $ide;
603
        return $ide;
604
    }
605
606
    /**
607
     * taginfMunCarrega
608
     *
609
     * tag MDFe/infMDFe/ide/infMunCarrega
610
     *
611
     * @param  stdClass $std
612
     * @return DOMElement
613
     */
614
    public function taginfMunCarrega(stdClass $std)
615
    {
616
        $possible = [
617
            'cMunCarrega',
618
            'xMunCarrega'
619
        ];
620
621
        $std = $this->equilizeParameters($std, $possible);
622
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
623
        $this->dom->addChild(
624
            $infMunCarrega,
625
            "cMunCarrega",
626
            $std->cMunCarrega,
627
            true,
628
            "Código do Município de Carregamento"
629
        );
630
        $this->dom->addChild(
631
            $infMunCarrega,
632
            "xMunCarrega",
633
            $std->xMunCarrega,
634
            true,
635
            "Nome do Município de Carregamento"
636
        );
637
        $this->infMunCarrega[] = $infMunCarrega;
638
        return $infMunCarrega;
639
    }
640
641
    /**
642
     * tagInfPercurso
643
     *
644
     * tag MDFe/infMDFe/ide/infPercurso
645
     *
646
     * @param  stdClass $std
647
     * @return DOMElement
648
     */
649
    public function taginfPercurso(stdClass $std)
650
    {
651
        $possible = [
652
            'UFPer'
653
        ];
654
655
        $std = $this->equilizeParameters($std, $possible);
656
        $infPercurso = $this->dom->createElement("infPercurso");
657
        $this->dom->addChild(
658
            $infPercurso,
659
            "UFPer",
660
            $std->UFPer,
661
            true,
662
            "Sigla das Unidades da Federação do percurso"
663
        );
664
        $this->infPercurso[] = $infPercurso;
665
        return $infPercurso;
666
    }
667
668
    /**
669
     * tagemit
670
     * Identificação do emitente da MDFe
671
     * tag MDFe/infMDFe/emit
672
     *
673
     * @param  stdClass $std
674
     * @return DOMElement
675
     */
676
    public function tagemit(stdClass $std)
677
    {
678
        $possible = [
679
            'CNPJ',
680
            'CPF',
681
            'IE',
682
            'xNome',
683
            'xFant'
684
        ];
685
        $std = $this->equilizeParameters($std, $possible);
686
687
        $identificador = '[25] <emit> - ';
688
        $this->emit = $this->dom->createElement("emit");
689
        if ($std->CPF) {
690
            $this->dom->addChild(
691
                $this->emit,
692
                "CPF",
693
                $std->CPF,
694
                true,
695
                $identificador . "CPF do emitente"
696
            );
697
        } else {
698
            $this->dom->addChild(
699
                $this->emit,
700
                "CNPJ",
701
                $std->CNPJ,
702
                true,
703
                $identificador . "CNPJ do emitente"
704
            );
705
        }
706
        $this->dom->addChild(
707
            $this->emit,
708
            "IE",
709
            $std->IE,
710
            false,
711
            $identificador . "Inscrição Estadual do emitente"
712
        );
713
        $this->dom->addChild(
714
            $this->emit,
715
            "xNome",
716
            $std->xNome,
717
            true,
718
            $identificador . "Razão Social ou Nome do emitente"
719
        );
720
        $this->dom->addChild(
721
            $this->emit,
722
            "xFant",
723
            $std->xFant,
724
            false,
725
            $identificador . "Nome fantasia do emitente"
726
        );
727
        return $this->emit;
728
    }
729
730
    /**
731
     * tagenderEmit
732
     * Endereço do emitente [30] pai [25]
733
     * tag MDFe/infMDFe/emit/endEmit
734
     *
735
     * @param  stdClass $std
736
     * @return DOMElement
737
     */
738
    public function tagenderEmit(stdClass $std)
739
    {
740
        $possible = [
741
            'xLgr',
742
            'nro',
743
            'xCpl',
744
            'xBairro',
745
            'cMun',
746
            'xMun',
747
            'CEP',
748
            'UF',
749
            'fone',
750
            'email'
751
        ];
752
        $std = $this->equilizeParameters($std, $possible);
753
754
        $identificador = '[30] <enderEmit> - ';
755
        $this->enderEmit = $this->dom->createElement("enderEmit");
756
757
        $this->dom->addChild(
758
            $this->enderEmit,
759
            "xLgr",
760
            $std->xLgr,
761
            true,
762
            $identificador . "Logradouro do Endereço do emitente"
763
        );
764
        $this->dom->addChild(
765
            $this->enderEmit,
766
            "nro",
767
            $std->nro,
768
            true,
769
            $identificador . "Número do Endereço do emitente"
770
        );
771
        $this->dom->addChild(
772
            $this->enderEmit,
773
            "xCpl",
774
            $std->xCpl,
775
            false,
776
            $identificador . "Complemento do Endereço do emitente"
777
        );
778
        $this->dom->addChild(
779
            $this->enderEmit,
780
            "xBairro",
781
            $std->xBairro,
782
            true,
783
            $identificador . "Bairro do Endereço do emitente"
784
        );
785
        $this->dom->addChild(
786
            $this->enderEmit,
787
            "cMun",
788
            $std->cMun,
789
            true,
790
            $identificador . "Código do município do Endereço do emitente"
791
        );
792
        $this->dom->addChild(
793
            $this->enderEmit,
794
            "xMun",
795
            $std->xMun,
796
            true,
797
            $identificador . "Nome do município do Endereço do emitente"
798
        );
799
        $this->dom->addChild(
800
            $this->enderEmit,
801
            "CEP",
802
            $std->CEP,
803
            true,
804
            $identificador . "Código do CEP do Endereço do emitente"
805
        );
806
        $this->dom->addChild(
807
            $this->enderEmit,
808
            "UF",
809
            $std->UF,
810
            true,
811
            $identificador . "Sigla da UF do Endereço do emitente"
812
        );
813
        $this->dom->addChild(
814
            $this->enderEmit,
815
            "fone",
816
            $std->fone,
817
            false,
818
            $identificador . "Número de telefone do emitente"
819
        );
820
        $this->dom->addChild(
821
            $this->enderEmit,
822
            "email",
823
            $std->email,
824
            false,
825
            $identificador . "Endereço de email do emitente"
826
        );
827
        return $this->enderEmit;
828
    }
829
830
    /**
831
     * tagrodo
832
     * tag MDFe/infMDFe/infModal/rodo
833
     *
834
     * @return DOMElement
835
     */
836
    private function tagrodo()
837
    {
838
        $this->rodo = $this->dom->createElement("rodo");
839
        return $this->rodo;
840
    }
841
842
    /**
843
     * tagferrov
844
     * tag MDFe/infMDFe/infModal/ferrov
845
     *
846
     * @return DOMElement
847
     */
848
    private function tagferrov()
849
    {
850
        if (empty($this->ferrov)) {
851
            $this->ferrov = $this->dom->createElement("ferrov");
852
        }
853
        return $this->ferrov;
854
    }
855
856
    /**
857
     * tagrodo
858
     * tag MDFe/infMDFe/infModal/rodo
859
     *
860
     * @return DOMElement
861
     */
862
    private function taginfDoc()
863
    {
864
        if (empty($this->infDoc)) {
865
            $this->infDoc = $this->dom->createElement("infDoc");
866
        }
867
        return $this->infDoc;
868
    }
869
870
    /**
871
     * valePed
872
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed
873
     *
874
     * @return DOMElement
875
     */
876
    private function tagvalePed()
877
    {
878
        if (empty($this->valePed)) {
879
            $this->valePed = $this->dom->createElement("valePed");
880
        }
881
        return $this->valePed;
882
    }
883
884
    /**
885
     * infANTT
886
     * tag MDFe/infMDFe/infModal/rodo/infANTT
887
     *
888
     * @return DOMElement
889
     */
890
    public function taginfANTT(stdClass $std)
891
    {
892
        $possible = [
893
            'RNTRC'
894
        ];
895
        $std = $this->equilizeParameters($std, $possible);
896
        $identificador = '[2] <infANTT> - ';
897
        $infANTT = $this->dom->createElement("infANTT");
898
        $this->dom->addChild(
899
            $infANTT,
900
            "RNTRC",
901
            $std->RNTRC,
902
            false,
903
            $identificador . "Registro Nacional de Transportadores Rodoviários de Carga"
904
        );
905
        $this->infANTT = $infANTT;
906
        return $infANTT;
907
    }
908
909
    /**
910
     * disp
911
     * tag MDFe/infMDFe/infModal/rodo/infANTT/disp
912
     *
913
     * @return DOMElement
914
     */
915
    public function tagdisp(stdClass $std)
916
    {
917
        $possible = [
918
            'CNPJForn',
919
            'CNPJPg',
920
            'CPFPg',
921
            'nCompra',
922
            'vValePed'
923
        ];
924
        $this->tagvalePed();
925
        $std = $this->equilizeParameters($std, $possible);
926
        $identificador = '[4] <disp> - ';
927
        $disp = $this->dom->createElement("disp");
928
        $this->dom->addChild(
929
            $disp,
930
            "CNPJForn",
931
            $std->CNPJForn,
932
            false,
933
            $identificador . "CNPJ da empresa fornecedora do ValePedágio"
934
        );
935
        $this->dom->addChild(
936
            $disp,
937
            "CNPJPg",
938
            $std->CNPJPg,
939
            false,
940
            $identificador . "CNPJ do responsável pelo pagamento do Vale-Pedágio"
941
        );
942
        $this->dom->addChild(
943
            $disp,
944
            "CPFPg",
945
            $std->CPFPg,
946
            false,
947
            $identificador . "CPF do responsável pelo pagamento do Vale-Pedágio"
948
        );
949
        $this->dom->addChild(
950
            $disp,
951
            "nCompra",
952
            $std->nCompra,
953
            false,
954
            $identificador . "Número do comprovante de compra"
955
        );
956
        $this->dom->addChild(
957
            $disp,
958
            "vValePed",
959
            $std->vValePed,
960
            false,
961
            $identificador . "Valor do Vale-Pedagio"
962
        );
963
        $this->disp[] = $disp;
964
        return $disp;
965
    }
966
967
    /**
968
     * infContratante
969
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infContratante
970
     *
971
     * @return DOMElement
972
     */
973
    public function taginfContratante(stdClass $std)
974
    {
975
        $possible = [
976
            'xNome',
977
            'CPF',
978
            'CPF',
979
            'idEstrangeiro'
980
        ];
981
        $std = $this->equilizeParameters($std, $possible);
982
        $identificador = '[4] <infContratante> - ';
983
        $infContratante = $this->dom->createElement("infContratante");
984
985
        $this->dom->addChild(
986
            $infContratante,
987
            "xNome",
988
            $std->xNome,
989
            false,
990
            $identificador . "Nome do contratante do serviço"
991
        );
992
        if ($std->CPF) {
993
            $this->dom->addChild(
994
                $infContratante,
995
                "CPF",
996
                $std->CPF,
997
                true,
998
                $identificador . "Número do CPF do contratante do serviço"
999
            );
1000
        } elseif ($std->CNPJ) {
1001
            $this->dom->addChild(
1002
                $infContratante,
1003
                "CNPJ",
1004
                $std->CNPJ,
1005
                true,
1006
                $identificador . "Número do CNPJ do contratante do serviço"
1007
            );
1008
        } else {
1009
            $this->dom->addChild(
1010
                $infContratante,
1011
                "idEstrangeiro",
1012
                $std->idEstrangeiro,
1013
                true,
1014
                $identificador . "Identificador do contratante do serviço em caso de ser estrangeiro"
1015
            );
1016
        }
1017
        $this->infContratante[] = $infContratante;
1018
        return $infContratante;
1019
    }
1020
1021
    /**
1022
     * infANTT
1023
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infCIOT
1024
     *
1025
     * @return DOMElement
1026
     */
1027
    public function taginfCIOT(stdClass $std)
1028
    {
1029
        $possible = [
1030
            'CIOT',
1031
            'CPF',
1032
            'CNPJ'
1033
        ];
1034
        $std = $this->equilizeParameters($std, $possible);
1035
        $identificador = '[4] <infCIOT> - ';
1036
        $infCIOT = $this->dom->createElement("infCIOT");
1037
        $this->dom->addChild(
1038
            $infCIOT,
1039
            "CIOT",
1040
            $std->CIOT,
1041
            true,
1042
            $identificador . "Código Identificador da Operação de Transporte"
1043
        );