Completed
Pull Request — master (#89)
by
unknown
11:04
created

Make::monta()   F

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 102

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 812

Importance

Changes 0
Metric Value
cc 28
nc 403201
nop 0
dl 0
loc 102
rs 0
c 0
b 0
f 0
ccs 0
cts 87
cp 0
crap 812

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\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    Roberto L. Machado <linux.rlm at gmail dot com>
19
 */
20
21
use NFePHP\Common\Keys;
22
use NFePHP\Common\DOMImproved as Dom;
23
use NFePHP\Common\Strings;
24
use stdClass;
25
use RuntimeException;
26
use InvalidArgumentException;
27
use DOMElement;
28
use DateTime;
29
30
class Make
31
{
32
    /**
33
     * @var array
34
     */
35
    public $errors = [];
36
    /**
37
     * versao
38
     * numero da versão do xml da MDFe
39
     *
40
     * @var string
41
     */
42
    public $versao = '3.00';
43
    /**
44
     * mod
45
     * modelo da MDFe 58
46
     *
47
     * @var integer
48
     */
49
    public $mod = '58';
50
    /**
51
     * chave da MDFe
52
     *
53
     * @var string
54
     */
55
    public $chMDFe = '';
56
57
    //propriedades privadas utilizadas internamente pela classe
58
    /**
59
     * @type string|\DOMNode
60
     */
61
    private $MDFe = '';
62
    /**
63
     * @type string|\DOMNode
64
     */
65
    private $infMDFe = '';
66
    /**
67
     * @type string|\DOMNode
68
     */
69
    private $ide = '';
70
    /**
71
     * @type string|\DOMNode
72
     */
73
    private $emit = '';
74
    /**
75
     * @type string|\DOMNode
76
     */
77
    private $infANTT = '';
78
    /**
79
     * @type string|\DOMNode
80
     */
81
    private $enderEmit = '';
82
    /**
83
     * @type string|\DOMNode
84
     */
85
    private $infModal = '';
86
    /**
87
     * @type string|\DOMNode
88
     */
89
    private $tot = '';
90
    /**
91
     * @type string|\DOMNode
92
     */
93
    private $seg = [];
94
    /**
95
     * @type string|\DOMNode
96
     */
97
    private $infMunDescarga = [];
98
    /**
99
     * @type string|\DOMNode
100
     */
101
    private $veicReboque = [];
102
    /**
103
     * @type string|\DOMNode
104
     */
105
    private $aLacres = [];
106
    /**
107
     * @type string|\DOMNode
108
     */
109
    private $infNFe = [];
110
    /**
111
     * @type string|\DOMNode
112
     */
113
    private $infCTe = [];
114
    /**
115
     * @type string|\DOMNode
116
     */
117
    private $infMDFeTransp = [];
118
    /**
119
     * @type string|\DOMNode
120
     */
121
    private $infContratante = [];
122
    /**
123
     * @type string|\DOMNode
124
     */
125
    private $autXML = [];
126
    /**
127
     * @type string|\DOMNode
128
     */
129
    private $infCIOT = [];
130
    /**
131
     * @type string|\DOMNode
132
     */
133
    private $disp = [];
134
    /**
135
     * @type string|\DOMNode
136
     */
137
    private $infMunCarrega = [];
138
    /**
139
     * @type string|\DOMNode
140
     */
141
    private $infPercurso = [];
142
    /**
143
     * @type string|\DOMNode
144
     */
145
    private $lacRodo = [];
146
    /**
147
     * @type string|\DOMNode
148
     */
149
    private $vag = [];
150
    /**
151
     * @type string|\DOMNode
152
     */
153
    private $infAdic = '';
154
    /**
155
     * @type string|\DOMNode
156
     */
157
    private $rodo = '';
158
    /**
159
     * @type string|\DOMNode
160
     */
161
    private $ferrov = '';
162
    /**
163
     * @type string|\DOMNode
164
     */
165
    private $infDoc = '';
166
    /**
167
     * @type string|\DOMNode
168
     */
169
    private $aquav = '';
170
    /**
171
     * @type string|\DOMNode
172
     */
173
    private $valePed = '';
174
    /**
175
     * @type array|\DOMNode
176
     */
177
    private $aInfMunDescarga = [];
178
    /**
179
     * @type array|\DOMNode
180
     */
181
    private $aInfMunCarrega = [];
182
    /**
183
     * @type array|\DOMNode
184
     */
185
    private $aInfPercurso = [];
186
    /**
187
     * @type string|\DOMNode
188
     */
189
    private $veicTracao = '';
190
    /**
191
     * @type string|\DOMNode
192
     */
193
    private $infUnidTransp = '';
194
    /**
195
     * @type string|\DOMNode
196
     */
197
    private $aereo = '';
198
    /**
199
     * @type string|\DOMNode
200
     */
201
    private $trem = '';
202
    /**
203
     * @type string|\DOMNode
204
     */
205
206
    /**
207
     * @var boolean
208
     */
209
    protected $replaceAccentedChars = false;
210
211
    /**
212
     * Função construtora cria um objeto DOMDocument
213
     * que será carregado com o documento fiscal
214
     */
215
    public function __construct()
216
    {
217
        $this->dom = new Dom('1.0', 'UTF-8');
0 ignored issues
show
Bug introduced by
The property dom does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
218
        $this->dom->preserveWhiteSpace = false;
219
        $this->dom->formatOutput = false;
220
    }
221
222
    /**
223
     * Retorns the xml
224
     * @return xml
225
     */
226
    public function getXML()
227
    {
228
        if (empty($this->xml)) {
0 ignored issues
show
Bug introduced by
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...
229
            $this->montaMDFe();
230
        }
231
        return $this->xml;
232
    }
233
234
    /**
235
     * Retorns the key number of NFe (44 digits)
236
     * @return string
237
     */
238
    public function getChave()
239
    {
240
        return $this->chMDFe;
241
    }
242
243
    /**
244
     * Returns the model of NFe 55 or 65
245
     * @return int
246
     */
247
    public function getModelo()
248
    {
249
        return $this->mod;
250
    }
251
252
    /**
253
     * Call method of xml assembly. For compatibility only.
254
     * @return boolean
255
     */
256
    public function montaMDFe()
257
    {
258
        return $this->monta();
259
    }
260
261
    /**
262
     * MDFe xml mount method
263
     * this function returns TRUE on success or FALSE on error
264
     * The xml of the MDFe must be retrieved by the getXML() function or
265
     * directly by the public property $xml
266
     * @return boolean
267
     */
268
    public function monta()
269
    {
270
        $this->errors = $this->dom->errors;
271
        if (count($this->errors) > 0) {
272
            return false;
273
        }
274
        //cria a tag raiz da MDFe
275
        $this->buildMDFe();
276
        $this->buildInfModal();
277
278
        $this->infMDFe = $this->dom->createElement("infMDFe");
279
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "ide"');
280
        if ($this->infMunCarrega) {
281
            $this->dom->addArrayChild($this->ide, $this->infMunCarrega, 'Falta tag "infMunCarrega"');
282
        }
283
        if ($this->infPercurso) {
284
            $this->dom->addArrayChild($this->ide, $this->infPercurso, 'Falta tag "infPercurso"');
285
        }
286
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "enderEmit"');
287
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "emit"');
288
        if ($this->rodo) {
289
290
            if ($this->infANTT) {
291
                if ($this->infCIOT) {
292
                    $this->dom->addArrayChild($this->infANTT, $this->infCIOT, 'Falta tag "infCIOT"');
293
                }
294
                if ($this->valePed) {
295
                    $this->dom->appChild($this->infANTT, $this->valePed, 'Falta tag "valePed"');
296
                    if ($this->disp) {
297
                        $this->dom->addArrayChild($this->valePed, $this->disp, 'Falta tag "disp"');
298
                    }
299
                }
300
                if ($this->infContratante) {
301
                    $this->dom->addArrayChild($this->infANTT, $this->infContratante, 'Falta tag "infContratante"');
302
                }
303
                $this->dom->appChild($this->rodo, $this->infANTT, 'Falta tag "infANTT"');
304
            }
305
            if ($this->veicTracao) {
306
                $this->dom->appChild($this->rodo, $this->veicTracao, 'Falta tag "rodo"');
307
            }
308
            if ($this->veicReboque) {
309
                $this->dom->addArrayChild($this->rodo, $this->veicReboque, 'Falta tag "veicReboque"');
310
            }
311
            if ($this->lacRodo) {
312
                $this->dom->addArrayChild($this->rodo, $this->lacRodo, 'Falta tag "lacRodo"');
313
            }
314
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
315
        }
316
        if ($this->aereo) {
317
            $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
318
        }
319
        if ($this->ferrov) {
320
            if ($this->trem) {
321
                $this->dom->appChild($this->ferrov, $this->trem, 'Falta tag "ferrov"');
322
            }
323
            if ($this->vag) {
324
                $this->dom->addArrayChild($this->ferrov, $this->vag, 'Falta tag "vag"');
325
            }
326
            $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
327
        }
328
        if ($this->aquav) {
329
            $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
330
        }
331
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infModal"');
332
        if ($this->infDoc) {
333
            $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infDoc"');
334
            if ($this->infMunDescarga) {
335
                foreach ($this->infMunDescarga as $key => $value) {
0 ignored issues
show
Bug introduced by
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...
336
                    $this->dom->appChild($this->infDoc, $value, 'Falta tag "infMunDescarga"');
337
                    if (isset($this->infCTe[$key])) {
338
                        $this->dom->addArrayChild($value, $this->infCTe[$key], 'Falta tag "infCTe"');
339
                    }
340
                    if (isset($this->infNFe[$key])) {
341
                        $this->dom->addArrayChild($value, $this->infNFe[$key], 'Falta tag "infNFe"');
342
                    }
343
                    if (isset($this->infMDFeTransp[$key])) {
344
                        $this->dom->addArrayChild($value, $this->infMDFeTransp[$key], 'Falta tag "infMDFeTransp"');
345
                    }
346
                }
347
            }
348
        }
349
        if (!empty($this->seg)) {
350
            $this->dom->addArrayChild($this->infMDFe, $this->seg, 'Falta tag "seg"');
351
        }
352
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "tot"');
353
        foreach ($this->lacres as $lacres) {
0 ignored issues
show
Bug introduced by
The property lacres does not seem to exist. Did you mean aLacres?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
354
            $this->dom->appChild($this->infMDFe, $lacres, 'Falta tag "lacres"');
355
356
        }
357
        foreach ($this->autXML as $autXML) {
0 ignored issues
show
Bug introduced by
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...
358
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
359
        }
360
        if (!empty($this->infAdic)) {
361
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
362
        }
363
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
364
        $this->dom->appendChild($this->MDFe);
365
        // testa da chave
366
        $this->checkMDFKey($this->dom);
367
        $this->xml = $this->dom->saveXML();
368
        return true;
369
    }
370
371
    /**
372
     * Informações de identificação da MDFe
373
     * tag MDFe/infMDFe/ide
374
     * @param  stdClass $std
375
     * @return DOMElement
376
     */
377
    public function tagide(stdClass $std)
378
    {
379
380
        $possible = [
381
            'cUF',
382
            'tpAmb',
383
            'tpEmit',
384
            'tpTransp',
385
            'mod',
386
            'serie',
387
            'nMDF',
388
            'cMDF',
389
            'cDV',
390
            'modal',
391
            'dhEmi',
392
            'tpEmis',
393
            'procEmi',
394
            'verProc',
395
            'ufIni',
396
            'ufFim'
397
        ];
398
399
        $std = $this->equilizeParameters($std, $possible);
400
401
        $this->tpAmb = $std->tpAmb;
0 ignored issues
show
Bug introduced by
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...
402
        $identificador = '[4] <ide> - ';
403
        $ide = $this->dom->createElement("ide");
404
        $this->dom->addChild(
405
            $ide,
406
            "cUF",
407
            $std->cUF,
408
            true,
409
            $identificador . "Código da UF do emitente do Documento Fiscal"
410
        );
411
        $this->dom->addChild(
412
            $ide,
413
            "tpAmb",
414
            $std->tpAmb,
415
            true,
416
            $identificador . "Identificação do Ambiente"
417
        );
418
        $this->dom->addChild(
419
            $ide,
420
            "tpEmit",
421
            $std->tpEmit,
422
            true,
423
            $identificador . "Indicador da tipo de emitente"
424
        );
425
        $this->dom->addChild(
426
            $ide,
427
            "tpTransp",
428
            $std->tpTransp,
429
            false,
430
            $identificador . "Tipo do Transportador"
431
        );
432
        $this->dom->addChild(
433
            $ide,
434
            "mod",
435
            $std->mod,
436
            true,
437
            $identificador . "Código do Modelo do Documento Fiscal"
438
        );
439
        $this->dom->addChild(
440
            $ide,
441
            "serie",
442
            $std->serie,
443
            true,
444
            $identificador . "Série do Documento Fiscal"
445
        );
446
        $this->dom->addChild(
447
            $ide,
448
            "nMDF",
449
            $std->nMDF,
450
            true,
451
            $identificador . "Número do Documento Fiscal"
452
        );
453
        $this->dom->addChild(
454
            $ide,
455
            "cMDF",
456
            str_pad($std->cMDF, 8, '0', STR_PAD_LEFT),
457
            true,
458
            $identificador . "Código do numérico do MDF"
459
        );
460
        $this->dom->addChild(
461
            $ide,
462
            "cDV",
463
            $std->cDV,
464
            true,
465
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
466
        );
467
        $this->dom->addChild(
468
            $ide,
469
            "modal",
470
            $std->modal,
471
            true,
472
            $identificador . "Modalidade de transporte"
473
        );
474
        $this->dom->addChild(
475
            $ide,
476
            "dhEmi",
477
            $std->dhEmi,
478
            true,
479
            $identificador . "Data e hora de emissão do Documento Fiscal"
480
        );
481
        $this->dom->addChild(
482
            $ide,
483
            "tpEmis",
484
            $std->tpEmis,
485
            true,
486
            $identificador . "Tipo de Emissão do Documento Fiscal"
487
        );
488
        $this->dom->addChild(
489
            $ide,
490
            "procEmi",
491
            $std->procEmi,
492
            true,
493
            $identificador . "Processo de emissão"
494
        );
495
        $this->dom->addChild(
496
            $ide,
497
            "verProc",
498
            $std->verProc,
499
            true,
500
            $identificador . "Versão do Processo de emissão"
501
        );
502
        $this->dom->addChild(
503
            $ide,
504
            "UFIni",
505
            $std->UFIni,
506
            true,
507
            $identificador . "Sigla da UF do Carregamento"
508
        );
509
        $this->dom->addChild(
510
            $ide,
511
            "UFFim",
512
            $std->UFFim,
513
            true,
514
            $identificador . "Sigla da UF do Descarregamento"
515
        );
516
517
        $this->mod = $std->mod;
518
        $this->ide = $ide;
519
        return $ide;
520
    }
521
522
    /**
523
     * taginfMunCarrega
524
     *
525
     * tag MDFe/infMDFe/ide/infMunCarrega
526
     *
527
     * @param  stdClass $std
528
     * @return DOMElement
529
     */
530 View Code Duplication
    public function taginfMunCarrega(stdClass $std)
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...
531
    {
532
        $possible = [
533
            'cMunCarrega',
534
            'xMunCarrega'
535
        ];
536
537
        $std = $this->equilizeParameters($std, $possible);
538
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
539
        $this->dom->addChild(
540
            $infMunCarrega,
541
            "cMunCarrega",
542
            $std->cMunCarrega,
543
            true,
544
            "Código do Município de Carregamento"
545
        );
546
        $this->dom->addChild(
547
            $infMunCarrega,
548
            "xMunCarrega",
549
            $std->xMunCarrega,
550
            true,
551
            "Nome do Município de Carregamento"
552
        );
553
        $this->infMunCarrega[] = $infMunCarrega;
554
        return $infMunCarrega;
555
    }
556
557
    /**
558
     * tagInfPercurso
559
     *
560
     * tag MDFe/infMDFe/ide/infPercurso
561
     *
562
     * @param  stdClass $std
563
     * @return DOMElement
564
     */
565 View Code Duplication
    public function taginfPercurso(stdClass $std)
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...
566
    {
567
        $possible = [
568
            'UFPer'
569
        ];
570
571
        $std = $this->equilizeParameters($std, $possible);
572
        $infPercurso = $this->dom->createElement("infPercurso");
573
        $this->dom->addChild(
574
            $infPercurso,
575
            "UFPer",
576
            $std->UFPer,
577
            true,
578
            "Sigla das Unidades da Federação do percurso"
579
        );
580
        $this->infPercurso[] = $infPercurso;
581
        return $infPercurso;
582
    }
583
584
    /**
585
     * tagemit
586
     * Identificação do emitente da MDFe
587
     * tag MDFe/infMDFe/emit
588
     *
589
     * @param  stdClass $std
590
     * @return DOMElement
591
     */
592
    public function tagemit(stdClass $std)
593
    {
594
        $possible = [
595
            'CNPJ',
596
            'CPF',
597
            'IE',
598
            'xNome',
599
            'xFant'
600
        ];
601
        $std = $this->equilizeParameters($std, $possible);
602
603
        $identificador = '[25] <emit> - ';
604
        $this->emit = $this->dom->createElement("emit");
605
        if ($std->CPF) {
606
            $this->dom->addChild(
607
                $this->emit,
608
                "CPF",
609
                $std->CPF,
610
                true,
611
                $identificador . "CPF do emitente"
612
            );
613
        } else {
614
            $this->dom->addChild(
615
                $this->emit,
616
                "CNPJ",
617
                $std->CNPJ,
618
                true,
619
                $identificador . "CNPJ do emitente"
620
            );
621
        }
622
623
        $this->dom->addChild(
624
            $this->emit,
625
            "IE",
626
            $std->IE,
627
            true,
628
            $identificador . "Inscrição Estadual do emitente"
629
        );
630
        $this->dom->addChild(
631
            $this->emit,
632
            "xNome",
633
            $std->xNome,
634
            true,
635
            $identificador . "Razão Social ou Nome do emitente"
636
        );
637
        $this->dom->addChild(
638
            $this->emit,
639
            "xFant",
640
            $std->xFant,
641
            false,
642
            $identificador . "Nome fantasia do emitente"
643
        );
644
        return $this->emit;
645
    }
646
647
    /**
648
     * tagenderEmit
649
     * Endereço do emitente [30] pai [25]
650
     * tag MDFe/infMDFe/emit/endEmit
651
     *
652
     * @param  stdClass $std
653
     * @return DOMElement
654
     */
655
    public function tagenderEmit(stdClass $std)
656
    {
657
        $possible = [
658
            'xLgr',
659
            'nro',
660
            'xCpl',
661
            'xBairro',
662
            'cMun',
663
            'xMun',
664
            'CEP',
665
            'UF',
666
            'fone',
667
            'email'
668
        ];
669
        $std = $this->equilizeParameters($std, $possible);
670
671
        $identificador = '[30] <enderEmit> - ';
672
        $this->enderEmit = $this->dom->createElement("enderEmit");
673
674
        $this->dom->addChild(
675
            $this->enderEmit,
676
            "xLgr",
677
            $std->xLgr,
678
            true,
679
            $identificador . "Logradouro do Endereço do emitente"
680
        );
681
        $this->dom->addChild(
682
            $this->enderEmit,
683
            "nro",
684
            $std->nro,
685
            true,
686
            $identificador . "Número do Endereço do emitente"
687
        );
688
        $this->dom->addChild(
689
            $this->enderEmit,
690
            "xCpl",
691
            $std->xCpl,
692
            false,
693
            $identificador . "Complemento do Endereço do emitente"
694
        );
695
        $this->dom->addChild(
696
            $this->enderEmit,
697
            "xBairro",
698
            $std->xBairro,
699
            true,
700
            $identificador . "Bairro do Endereço do emitente"
701
        );
702
        $this->dom->addChild(
703
            $this->enderEmit,
704
            "cMun",
705
            $std->cMun,
706
            true,
707
            $identificador . "Código do município do Endereço do emitente"
708
        );
709
        $this->dom->addChild(
710
            $this->enderEmit,
711
            "xMun",
712
            $std->xMun,
713
            true,
714
            $identificador . "Nome do município do Endereço do emitente"
715
        );
716
        $this->dom->addChild(
717
            $this->enderEmit,
718
            "CEP",
719
            $std->CEP,
720
            true,
721
            $identificador . "Código do CEP do Endereço do emitente"
722
        );
723
        $this->dom->addChild(
724
            $this->enderEmit,
725
            "UF",
726
            $std->UF,
727
            true,
728
            $identificador . "Sigla da UF do Endereço do emitente"
729
        );
730
        $this->dom->addChild(
731
            $this->enderEmit,
732
            "fone",
733
            $std->fone,
734
            false,
735
            $identificador . "Número de telefone do emitente"
736
        );
737
        $this->dom->addChild(
738
            $this->enderEmit,
739
            "email",
740
            $std->email,
741
            false,
742
            $identificador . "Endereço de email do emitente"
743
        );
744
        return $this->enderEmit;
745
    }
746
747
    /**
748
     * tagrodo
749
     * tag MDFe/infMDFe/infModal/rodo
750
     *
751
     * @return DOMElement
752
     */
753
    public function tagrodo()
754
    {
755
        $this->rodo = $this->dom->createElement("rodo");
756
        return $this->rodo;
757
    }
758
759
    /**
760
     * tagferrov
761
     * tag MDFe/infMDFe/infModal/ferrov
762
     *
763
     * @return DOMElement
764
     */
765
    public function tagferrov()
766
    {
767
        $this->ferrov = $this->dom->createElement("ferrov");
768
        return $this->ferrov;
769
    }
770
771
    /**
772
     * tagrodo
773
     * tag MDFe/infMDFe/infModal/rodo
774
     *
775
     * @return DOMElement
776
     */
777
    public function taginfDoc()
778
    {
779
        $this->infDoc = $this->dom->createElement("infDoc");
780
        return $this->infDoc;
781
    }
782
783
    /**
784
     * valePed
785
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed
786
     *
787
     * @return DOMElement
788
     */
789
    public function tagvalePed()
790
    {
791
792
        $this->valePed = $this->dom->createElement("valePed");
793
        return $this->valePed;
794
    }
795
796
    /**
797
     * infANTT
798
     * tag MDFe/infMDFe/infModal/rodo/infANTT
799
     *
800
     * @return DOMElement
801
     */
802 View Code Duplication
    public function taginfANTT(stdClass $std)
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...
803
    {
804
        $possible = [
805
            'RNTRC'
806
        ];
807
        $std = $this->equilizeParameters($std, $possible);
808
        $identificador = '[2] <infANTT> - ';
809
        $infANTT = $this->dom->createElement("infANTT");
810
        $this->dom->addChild(
811
            $infANTT,
812
            "RNTRC",
813
            $std->RNTRC,
814
            false,
815
            $identificador . "Registro Nacional de Transportadores Rodoviários de Carga"
816
        );
817
        $this->infANTT = $infANTT;
818
        return $infANTT;
819
    }
820
821
    /**
822
     * disp
823
     * tag MDFe/infMDFe/infModal/rodo/infANTT/disp
824
     *
825
     * @return DOMElement
826
     */
827 View Code Duplication
    public function tagdisp(stdClass $std)
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...
828
    {
829
        $possible = [
830
            'CNPJForn',
831
            'CNPJPg',
832
            'CPFPg',
833
            'nCompra',
834
            'vValePed'
835
        ];
836
        $std = $this->equilizeParameters($std, $possible);
837
        $identificador = '[4] <disp> - ';
838
        $disp = $this->dom->createElement("disp");
839
        $this->dom->addChild(
840
            $disp,
841
            "CNPJForn",
842
            $std->CNPJForn,
843
            false,
844
            $identificador . "CNPJ da empresa fornecedora do ValePedágio"
845
        );
846
        $this->dom->addChild(
847
            $disp,
848
            "CNPJPg",
849
            $std->CNPJPg,
850
            false,
851
            $identificador . "CNPJ do responsável pelo pagamento do Vale-Pedágio"
852
        );
853
        $this->dom->addChild(
854
            $disp,
855
            "CPFPg",
856
            $std->CPFPg,
857
            false,
858
            $identificador . "CPF do responsável pelo pagamento do Vale-Pedágio"
859
        );
860
        $this->dom->addChild(
861
            $disp,
862
            "nCompra",
863
            $std->nCompra,
864
            false,
865
            $identificador . "Número do comprovante de compra"
866
        );
867
        $this->dom->addChild(
868
            $disp,
869
            "vValePed",
870
            $std->vValePed,
871
            false,
872
            $identificador . "Valor do Vale-Pedagio"
873
        );
874
        $this->disp[] = $disp;
875
        return $disp;
876
    }
877
    /**
878
     * infContratante
879
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infContratante
880
     *
881
     * @return DOMElement
882
     */
883
    public function taginfContratante(stdClass $std)
884
    {
885
        $possible = [
886
            'CPF',
887
            'CNPJ'
888
        ];
889
        $std = $this->equilizeParameters($std, $possible);
890
        $identificador = '[4] <infContratante> - ';
891
        $infContratante = $this->dom->createElement("infContratante");
892
        if ($std->CPF) {
893
            $this->dom->addChild(
894
                $infContratante,
895
                "CPF",
896
                $std->CPF,
897
                true,
898
                $identificador . "Número do CPF do contratente do serviço"
899
            );
900
        } else {
901
            $this->dom->addChild(
902
                $infContratante,
903
                "CNPJ",
904
                $std->CNPJ,
905
                true,
906
                $identificador . "Número do CNPJ do contratente do serviço"
907
            );
908
        }
909
        $this->infContratante[] = $infContratante;
910
        return $infContratante;
911
    }
912
913
    /**
914
     * infANTT
915
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infCIOT
916
     *
917
     * @return DOMElement
918
     */
919
    public function taginfCIOT(stdClass $std)
920
    {
921
        $possible = [
922
            'CIOT',
923
            'CPF',
924
            'CNPJ'
925
        ];
926
        $std = $this->equilizeParameters($std, $possible);
927
        $identificador = '[4] <infCIOT> - ';
928
        $infCIOT = $this->dom->createElement("infCIOT");
929
        $this->dom->addChild(
930
            $infCIOT,
931
            "CIOT",
932
            $std->CIOT,
933
            true,
934
            $identificador . "Código Identificador da Operação de Transporte"
935
        );
936
        if ($std->CPF) {
937
            $this->dom->addChild(
938
                $infCIOT,
939
                "CPF",
940
                $std->CPF,
941
                true,
942
                $identificador . "Número do CPF responsável pela geração do CIOT"
943
            );
944
        } else {
945
            $this->dom->addChild(
946
                $infCIOT,
947
                "CNPJ",
948
                $std->CNPJ,
949
                true,
950
                $identificador . "Número do CNPJ responsável pela geração do CIOT"
951
            );
952
        }
953
        $this->infCIOT[] = $infCIOT;
954
        return $infCIOT;
955
    }
956
957
    /**
958
     * tagInfMunDescarga
959
     * tag MDFe/infMDFe/infDoc/infMunDescarga
960
     *
961
     * @param  stdClass $std
962
     * @return DOMElement
963
     */
964 View Code Duplication
    public function taginfMunDescarga(stdClass $std)
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...
965
    {
966
        $possible = [
967
            'cMunDescarga',
968
            'xMunDescarga'
969
        ];
970
        $std = $this->equilizeParameters($std, $possible);
971
        $identificador = '[4] <infMunDescarga> - ';
972
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
973
        $this->dom->addChild(
974
            $infMunDescarga,
975
            "cMunDescarga",
976
            $std->cMunDescarga,
977
            true,
978
            $identificador . "Código do Município de Descarga"
979
        );
980
        $this->dom->addChild(
981
            $infMunDescarga,
982
            "xMunDescarga",
983
            $std->xMunDescarga,
984
            true,
985
            $identificador . "Nome do Município de Descarga"
986
        );
987
        $this->infMunDescarga[] = $infMunDescarga;
988
        return $infMunDescarga;
989
    }
990
      
991
    /**
992
     * taginfCTe
993
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
994
     *
995
     * @param  stdClass $std
996
     * @return DOMElement
997
     */
998
    public function taginfCTe(stdClass $std)
999
    {
1000
        $possible = [
1001
            'chCTe',
1002
            'SegCodBarra',
1003
            'indReentrega',
1004
            'infEntregaParcial',
1005
            'infUnidTransp',
1006
            'peri'
1007
        ];
1008
        $std = $this->equilizeParameters($std, $possible);
1009
        $infCTe = $this->dom->createElement("infCTe");
1010
        $identificador = '[4] <infCTe> - ';
1011
        $this->dom->addChild(
1012
            $infCTe,
1013
            "chCTe",
1014
            $std->chCTe,
1015
            true,
1016
            $identificador . "Chave de Acesso CTe"
1017
        );
1018
        $this->dom->addChild(
1019
            $infCTe,
1020
            "SegCodBarra",
1021
            $std->SegCodBarra,
1022
            false,
1023
            $identificador . "Segundo código de barras do CTe"
1024
        );
1025
        $this->dom->addChild(
1026
            $infCTe,
1027
            "indReentrega",
1028
            $std->indReentrega,
1029
            false,
1030
            $identificador . "Indicador de Reentrega"
1031
        );
1032
        if ($std->infUnidTransp) {
1033
            foreach ($std->infUnidTransp as  $value) {
1034
                $this->dom->appChild($infCTe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1035
            }
1036
        }
1037
        if ($std->peri) {
1038
            foreach ($std->peri as  $value) {
1039
                $this->dom->appChild($infCTe, $this->tagperi($value), 'Falta tag "peri"');
1040
            }
1041
1042
        }
1043
        if ($std->infEntregaParcial != null) {
1044
            $possible = [
1045
                'qtdTotal',
1046
                'qtdParcial'
1047
            ];
1048
            $stdinfEntregaParcial = $this->equilizeParameters($std->infEntregaParcial, $possible);
1049
            $identificadorparcial = '[4] <infEntregaParcial> - ';
1050
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
1051
            $this->dom->addChild(
1052
                $infEntregaParcial,
1053
                "qtdTotal",
1054
                $stdinfEntregaParcial->qtdTotal,
1055
                true,
1056
                $identificadorparcial . "Quantidade total de volumes"
1057
            );
1058
            $this->dom->addChild(
1059
                $infEntregaParcial,
1060
                "qtdParcial",
1061
                $stdinfEntregaParcial->qtdParcial,
1062
                true,
1063
                $identificadorparcial . "Quantidade de volumes enviados no MDF-e"
1064
            );
1065
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infCTe"');
1066
        }
1067
        $this->infCTe[count($this->infMunDescarga) - 1][] = $infCTe;
1068
        return $infCTe;
1069
    }
1070
1071
    /**
1072
     * tagperi
1073
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
1074
     *
1075
     * @param  stdClass $std
1076
     * @return DOMElement
1077
     */
1078 View Code Duplication
    public function tagperi(stdClass $std)
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...
1079
    {
1080
        $possible = [
1081
            'nONU',
1082
            'xNomeAE',
1083
            'xClaRisco',
1084
            'grEmb',
1085
            'qTotProd',
1086
            'qVolTipo'
1087
        ];
1088
        $std = $this->equilizeParameters($std, $possible);
1089
        $peri = $this->dom->createElement("peri");
1090
        $this->dom->addChild(
1091
            $peri,
1092
            "nONU",
1093
            $std->nONU,
1094
            true,
1095
            "Número ONU/UN"
1096
        );
1097
        $this->dom->addChild(
1098
            $peri,
1099
            "xNomeAE",
1100
            $std->xNomeAE,
1101
            true,
1102
            "Nome apropriado para embarque do produto"
1103
        );
1104
        $this->dom->addChild(
1105
            $peri,
1106
            "xClaRisco",
1107
            $std->xClaRisco,
1108
            true,
1109
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
1110
        );
1111
        $this->dom->addChild(
1112
            $peri,
1113
            "grEmb",
1114
            $std->grEmb,
1115
            true,
1116
            "Grupo de Embalagem"
1117
        );
1118
        $this->dom->addChild(
1119
            $peri,
1120
            "qTotProd",
1121
            $std->qTotProd,
1122
            true,
1123
            "Quantidade total por produto"
1124
        );
1125
        $this->dom->addChild(
1126
            $peri,
1127
            "qVolTipo",
1128
            $std->qVolTipo,
1129
            true,
1130
            "Quantidade e Tipo de volumes"
1131
        );
1132
        return $peri;
1133
    }
1134
1135
    /**
1136
     * taginfNFe
1137
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
1138
     *
1139
     * @param  stdClass $std
1140
     * @return DOMElement
1141
     */
1142
    public function taginfNFe(stdClass $std)
1143
    {
1144
        $possible = [
1145
            'chNFe',
1146
            'SegCodBarra',
1147
            'indReentrega',
1148
            'infUnidTransp',
1149
            'peri'
1150
        ];
1151
        $std = $this->equilizeParameters($std, $possible);
1152
        $infNFe = $this->dom->createElement("infNFe");
1153
        $this->dom->addChild(
1154
            $infNFe,
1155
            "chNFe",
1156
            $std->chNFe,
1157
            true,
1158
            "Chave de Acesso NFe"
1159
        );
1160
        $this->dom->addChild(
1161
            $infNFe,
1162
            "SegCodBarra",
1163
            $std->SegCodBarra,
1164
            false,
1165
            "Segundo código de barras do NFe"
1166
        );
1167
        $this->dom->addChild(
1168
            $infNFe,
1169
            "indReentrega",
1170
            $std->indReentrega,
1171
            false,
1172
            "Indicador de Reentrega"
1173
        );
1174
        if ($std->infUnidTransp) {
1175
            foreach ($std->infUnidTransp as  $value) {
1176
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1177
            }
1178
        }
1179
        if ($std->peri) {
1180
            foreach ($std->peri as  $value) {
1181
                $this->dom->appChild($infNFe, $this->tagperi($value), 'Falta tag "peri"');
1182
            }
1183
        }
1184
        $this->infNFe[count($this->infMunDescarga) - 1][] = $infNFe;
1185
        return $infNFe;
1186
    }
1187
1188
    /**
1189
     * taginfMDFeTransp
1190
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1191
     *
1192
     * @param  stdClass $std
1193
     * @return DOMElement
1194
     */
1195
    public function taginfMDFeTransp(stdClass $std)
1196
    {
1197
        $possible = [
1198
            'chNFe',
1199
            'indReentrega',
1200
        ];
1201
        $std = $this->equilizeParameters($std, $possible);
1202
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1203
        $this->dom->addChild(
1204
            $infMDFeTransp,
1205
            "chNFe",
1206
            $std->chNFe,
1207
            true,
1208
            "Chave de Acesso NFe"
1209
        );
1210
        $this->dom->addChild(
1211
            $infMDFeTransp,
1212
            "indReentrega",
1213
            $std->indReentrega,
1214
            false,
1215
            "Indicador de Reentrega"
1216
        );
1217
        if ($std->infUnidTransp) {
1218
            foreach ($std->infUnidTransp as  $value) {
1219
                $this->dom->appChild($infMDFeTransp, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1220
            }
1221
        }
1222
        if ($std->peri) {
1223
            foreach ($std->peri as  $value) {
1224
                $this->dom->appChild($infMDFeTransp, $this->tagperi($value), 'Falta tag "peri"');
1225
            }
1226
        }
1227
        $this->infMDFeTransp[count($this->infMunDescarga) - 1][] = $infMDFeTransp;
1228
        return $infMDFeTransp;
1229
    }
1230
1231
    /**
1232
     * taginfUnidTransp
1233
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1234
     *
1235
     * @param  stdClass $std
1236
     * @return DOMElement
1237
     */
1238
    public function taginfUnidTransp(stdClass $std)
1239
    {
1240
        $possible = [
1241
            'tpUnidTransp',
1242
            'idUnidTransp',
1243
            'qtdRat',
1244
            'lacUnidTransp',
1245
            'infUnidCarga'
1246
        ];
1247
        $std = $this->equilizeParameters($std, $possible);
1248
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1249
        $this->dom->addChild(
1250
            $infUnidTransp,
1251
            "tpUnidTransp",
1252
            $std->tpUnidTransp,
1253
            true,
1254
            "Tipo da Unidade de Transporte"
1255
        );
1256
        $this->dom->addChild(
1257
            $infUnidTransp,
1258
            "idUnidTransp",
1259
            $std->idUnidTransp,
1260
            false,
1261
            "Identificação da Unidade de Transporte"
1262
        );
1263 View Code Duplication
        if ($std->lacUnidTransp != null) {
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...
1264
            $possible = [
1265
                'nLacre'
1266
            ];
1267
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1268
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
1269
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1270
                $this->dom->addChild(
1271
                    $lacUnidTransp,
1272
                    "nLacre",
1273
                    $nLacre,
1274
                    true,
1275
                    "Número do lacre"
1276
                );
1277
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
1278
            }
1279
        }
1280
        if ($std->infUnidCarga) {
1281
            foreach ($std->infUnidCarga as  $value) {
1282
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
1283
            }
1284
1285
        }
1286
        $this->dom->addChild(
1287
            $infUnidTransp,
1288
            "qtdRat",
1289
            $std->qtdRat,
1290
            false,
1291
            "Quantidade rateada (Peso,Volume) "
1292
        );
1293
        return $infUnidTransp;
1294
    }
1295
1296
    /**
1297
     * taginfUnidCarga
1298
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1299
     *
1300
     * @param  stdClass $std
1301
     * @return DOMElement
1302
     */
1303
    public function taginfUnidCarga(stdClass $std)
1304
    {
1305
        $possible = [
1306
            'tpUnidCarga',
1307
            'idUnidCarga',
1308
            'lacUnidCarga',
1309
            'qtdRat'
1310
        ];
1311
        $std = $this->equilizeParameters($std, $possible);
1312
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1313
        $this->dom->addChild(
1314
            $infUnidCarga,
1315
            "tpUnidCarga",
1316
            $std->tpUnidCarga,
1317
            false,
1318
            "Tipo da Unidade de Carga"
1319
        );
1320
        $this->dom->addChild(
1321
            $infUnidCarga,
1322
            "idUnidCarga",
1323
            $std->idUnidCarga,
1324
            false,
1325
            "Identificação da Unidade de Carga "
1326
        );
1327 View Code Duplication
        if ($std->lacUnidCarga != null) {
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...
1328
            $possible = [
1329
                'nLacre'
1330
            ];
1331
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1332
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
1333
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1334
                $this->dom->addChild(
1335
                    $lacUnidCarga,
1336
                    "nLacre",
1337
                    $nLacre,
1338
                    true,
1339
                    "Número do lacre"
1340
                );
1341
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
1342
            }
1343
        }
1344
        $this->dom->addChild(
1345
            $infUnidCarga,
1346
            "qtdRat",
1347
            $std->qtdRat,
1348
            false,
1349
            "Quantidade rateada (Peso,Volume) "
1350
        );
1351
        return $infUnidCarga;
1352
    }
1353
1354
    /**
1355
     * tagseg
1356
     * tag MDFe/infMDFe/seg
1357
     *
1358
     * @param  stdClass $std
1359
     * @return DOMElement
1360
     */
1361
    public function tagseg(stdClass $std)
1362
    {
1363
        $possible = [
1364
            'respSeg',
1365
            'CNPJ',
1366
            'CPF',
1367
            'infSeg',
1368
            'nApol',
1369
            'nAver'
1370
        ];
1371
        $std = $this->equilizeParameters($std, $possible);
1372
        $seg = $this->dom->createElement("seg");
1373
        $infResp = $this->dom->createElement("infResp");
1374
        $this->dom->addChild(
1375
            $infResp,
1376
            "respSeg",
1377
            $std->respSeg,
1378
            true,
1379
            "Responsável pelo seguro"
1380
        );
1381
        $this->dom->addChild(
1382
            $infResp,
1383
            "CNPJ",
1384
            $std->CNPJ,
1385
            false,
1386
            "Número do CNPJ do responsável pelo seguro"
1387
        );
1388
        $this->dom->addChild(
1389
            $infResp,
1390
            "CPF",
1391
            $std->CPF,
1392
            false,
1393
            "Número do CPF do responsável pelo seguro"
1394
        );
1395
        $this->dom->appChild($seg, $infResp, 'Falta tag "seg"');
1396
        if ($std->infSeg != null) {
1397
            $possible = [
1398
                'xSeg',
1399
                'CNPJ'
1400
            ];
1401
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1402
            $infSeg = $this->dom->createElement("infSeg");
1403
            $this->dom->addChild(
1404
                $infSeg,
1405
                "xSeg",
1406
                $stdinfSeg->xSeg,
1407
                true,
1408
                "Nome da Seguradora"
1409
            );
1410
            $this->dom->addChild(
1411
                $infSeg,
1412
                "CNPJ",
1413
                $stdinfSeg->CNPJ,
1414
                false,
1415
                "Número do CNPJ da seguradora"
1416
            );
1417
            $this->dom->appChild($seg, $infSeg, 'Falta tag "seg"');
1418
        }
1419
        $this->dom->addChild(
1420
            $seg,
1421
            "nApol",
1422
            $std->nApol,
1423
            false,
1424
            "Número da Apólice"
1425
        );
1426
        if ($std->nAver != null) {
1427
            foreach ($std->nAver as $nAver) {
1428
                $this->dom->addChild(
1429
                    $seg,
1430
                    "nAver",
1431
                    $nAver,
1432
                    true,
1433
                    "Número da Averbação"
1434
                );
1435
            }
1436
        }
1437
        $this->seg[] = $seg;
1438
        return $seg;
1439
    }
1440
1441
    /**
1442
     * tagTot
1443
     * tag MDFe/infMDFe/tot
1444
     *
1445
     * @param  stdClass $std
1446
     * @return DOMElement
1447
     */
1448 View Code Duplication
    public function tagtot(stdClass $std)
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...
1449
    {
1450
        $possible = [
1451
            'qCTe',
1452
            'qNFe',
1453
            'qMDFe',
1454
            'vCarga',
1455
            'cUnid',
1456
            'qCarga'
1457
        ];
1458
        $std = $this->equilizeParameters($std, $possible);
1459
        $tot = $this->dom->createElement("tot");
1460
        $this->dom->addChild(
1461
            $tot,
1462
            "qCTe",
1463
            $std->qCTe,
1464
            false,
1465
            "Quantidade total de CT-e relacionados no Manifesto"
1466
        );
1467
        $this->dom->addChild(
1468
            $tot,
1469
            "qNFe",
1470
            $std->qNFe,
1471
            false,
1472
            "Quantidade total de NF-e relacionados no Manifesto"
1473
        );
1474
        $this->dom->addChild(
1475
            $tot,
1476
            "qMDFe",
1477
            $std->qMDFe,
1478
            false,
1479
            "Quantidade total de MDF-e relacionados no Manifesto"
1480
        );
1481
        $this->dom->addChild(
1482
            $tot,
1483
            "vCarga",
1484
            $std->vCarga,
1485
            true,
1486
            "Valor total da mercadoria/carga transportada"
1487
        );
1488
        $this->dom->addChild(
1489
            $tot,
1490
            "cUnid",
1491
            $std->cUnid,
1492
            true,
1493
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1494
        );
1495
        $this->dom->addChild(
1496
            $tot,
1497
            "qCarga",
1498
            $std->qCarga,
1499
            true,
1500
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1501
        );
1502
        $this->tot = $tot;
1503
        return $tot;
1504
    }
1505
1506
    /**
1507
     * tagLacres
1508
     * tag MDFe/infMDFe/lacres
1509
     *
1510
     * @param  stdClass $std
1511
     * @return DOMElement
1512
     */
1513 View Code Duplication
    public function taglacres(stdClass $std)
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...
1514
    {
1515
        $possible = [
1516
            'nLacre'
1517
        ];
1518
        $std = $this->equilizeParameters($std, $possible);
1519
		foreach ($std->nLacre as $nLacre) {
1520
			$lacres = $this->dom->createElement("lacres");
1521
			$this->dom->addChild(
1522
				$lacres,
1523
				"nLacre",
1524
				$nLacre,
1525
				false,
1526
				"Número do lacre"
1527
			);
1528
			$this->aLacres[] = $lacres; //array de DOMNode
1529
		}
1530
        return $this->aLacres;
1531
    }
1532
1533
    /**
1534
     * taginfAdic
1535
     * Grupo de Informações Adicionais Z01 pai A01
1536
     * tag MDFe/infMDFe/infAdic (opcional)
1537
     *
1538
     * @param  stdClass $std
1539
     * @return DOMElement
1540
     */
1541 View Code Duplication
    public function taginfAdic(stdClass $std)
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...
1542
    {
1543
        $possible = [
1544
            'infAdFisco',
1545
            'infCpl'
1546
        ];
1547
        $std = $this->equilizeParameters($std, $possible);
1548
        $infAdic = $this->dom->createElement("infAdic");
1549
        $this->dom->addChild(
1550
            $infAdic,
1551
            "infAdFisco",
1552
            $std->infAdFisco,
1553
            false,
1554
            "Informações Adicionais de Interesse do Fisco"
1555
        );
1556
        $this->dom->addChild(
1557
            $infAdic,
1558
            "infCpl",
1559
            $std->infCpl,
1560
            false,
1561
            "Informações Complementares de interesse do Contribuinte"
1562
        );
1563
        $this->infAdic = $infAdic;
1564
        return $infAdic;
1565
    }
1566
1567
    /**
1568
     * tagautXML
1569
     * tag MDFe/infMDFe/autXML
1570
     *
1571
     * Autorizados para download do XML do MDF-e
1572
     *
1573
     * @param  stdClass $std
1574
     * @return DOMElement
1575
     */
1576 View Code Duplication
    public function tagautXML(stdClass $std)
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...
1577
    {
1578
        $possible = [
1579
            'CNPJ',
1580
            'CPF'
1581
        ];
1582
        $std = $this->equilizeParameters($std, $possible);
1583
        $autXML = $this->dom->createElement("autXML");
1584
        $this->dom->addChild(
1585
            $autXML,
1586
            "CNPJ",
1587
            $std->CNPJ,
1588
            false,
1589
            "CNPJ do autorizado"
1590
        );
1591
        $this->dom->addChild(
1592
            $autXML,
1593
            "CPF",
1594
            $std->CPF,
1595
            false,
1596
            "CPF do autorizado"
1597
        );
1598
        $this->autXML[] = $autXML;
1599
        return $this->autXML;
1600
    }
1601
1602
    /**
1603
     * buildInfModal
1604
     * tag MDFe/infMDFe/infModal
1605
     *
1606
     * @return DOMElement
1607
     */
1608
    public function buildInfModal()
1609
    {
1610
        $infModal = $this->dom->createElement("infModal");
1611
        $infModal->setAttribute("versaoModal", $this->versao);
1612
        $this->infModal = $infModal;
1613
        return $infModal;
1614
    }
1615
1616
    /**
1617
     * tagAereo
1618
     * tag MDFe/infMDFe/infModal/aereo
1619
     *
1620
     * @return DOMElement
1621
     */
1622
1623
    public function tagaereo(stdClass $std)
1624
    {
1625
        $possible = [
1626
            'nac',
1627
            'matr',
1628
            'nVoo',
1629
            'cAerEmb',
1630
            'cAerDes',
1631
            'dVoo'
1632
        ];
1633
        $std = $this->equilizeParameters($std, $possible);
1634
        $aereo = $this->dom->createElement("aereo");
1635
        $identificador = '[1] <aereo> - ';
1636
        $this->dom->addChild(
1637
            $aereo,
1638
            "nac",
1639
            $std->nac,
1640
            true,
1641
            $identificador . "Marca da Nacionalidade da aeronave"
1642
        );
1643
        $this->dom->addChild(
1644
            $aereo,
1645
            "matr",
1646
            $std->matr,
1647
            true,
1648
            $identificador . "Marca de Matrícula da aeronave"
1649
        );
1650
        $this->dom->addChild(
1651
            $aereo,
1652
            "nVoo",
1653
            $std->nVoo,
1654
            true,
1655
            $identificador . "Número do Vôo"
1656
        );
1657
        $this->dom->addChild(
1658
            $aereo,
1659
            "cAerEmb",
1660
            $std->cAerEmb,
1661
            true,
1662
            $identificador . "Aeródromo de Embarque - Código IATA"
1663
        );
1664
        $this->dom->addChild(
1665
            $aereo,
1666
            "cAerDes",
1667
            $std->cAerDes,
1668
            true,
1669
            $identificador . "Aeródromo de Destino - Código IATA"
1670
        );
1671
        $this->dom->addChild(
1672
            $aereo,
1673
            "dVoo",
1674
            $std->dVoo,
1675
            true,
1676
            $identificador . "Data do Vôo"
1677
        );
1678
        $this->aereo = $aereo;
1679
        return $aereo;
1680
    }
1681
1682
1683
1684
    /**
1685
     * tagtrem
1686
     * tag MDFe/infMDFe/infModal/ferrov/trem
1687
     *
1688
     * @return DOMElement
1689
     */
1690
1691 View Code Duplication
    public function tagtrem(stdClass $std)
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...
1692
    {
1693
        $possible = [
1694
            'xPref',
1695
            'dhTrem',
1696
            'xOri',
1697
            'xDest',
1698
            'qVag'
1699
        ];
1700
        $std = $this->equilizeParameters($std, $possible);
1701
        $trem = $this->dom->createElement("trem");
1702
        $identificador = '[1] <trem> - ';
1703
        $this->dom->addChild(
1704
            $trem,
1705
            "xPref",
1706
            $std->xPref,
1707
            true,
1708
            $identificador . "Prefixo do Trem"
1709
        );
1710
        $this->dom->addChild(
1711
            $trem,
1712
            "dhTrem",
1713
            $std->dhTrem,
1714
            false,
1715
            $identificador . "Data e hora de liberação do trem na origem"
1716
        );
1717
        $this->dom->addChild(
1718
            $trem,
1719
            "xOri",
1720
            $std->xOri,
1721
            true,
1722
            $identificador . "Origem do Trem"
1723
        );
1724
        $this->dom->addChild(
1725
            $trem,
1726
            "xDest",
1727
            $std->xDest,
1728
            true,
1729
            $identificador . "Destino do Trem"
1730
        );
1731
        $this->dom->addChild(
1732
            $trem,
1733
            "qVag",
1734
            $std->qVag,
1735
            true,
1736
            $identificador . "Quantidade de vagões carregados"
1737
        );
1738
        $this->trem = $trem;
1739
        return $trem;
1740
    }
1741
1742
    /**
1743
     * tagVag
1744
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
1745
     *
1746
     * @param  string $serie
1747
     * @param  string $nVag
0 ignored issues
show
Bug introduced by
There is no parameter named $serie. Was it maybe removed?

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

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

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

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

Loading history...
1748
     * @param  string $nSeq
0 ignored issues
show
Bug introduced by
There is no parameter named $nVag. Was it maybe removed?

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

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

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

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

Loading history...
1749
     * @param  string $tonUtil
0 ignored issues
show
Bug introduced by
There is no parameter named $nSeq. Was it maybe removed?

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

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

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

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

Loading history...
1750
     *
0 ignored issues
show
Bug introduced by
There is no parameter named $tonUtil. Was it maybe removed?

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

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

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

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

Loading history...
1751
     * @return DOMElement
1752
     */
1753
1754
    public function tagVag(stdClass $std)
1755
    {
1756
        $possible = [
1757
            'pesoBC',
1758
            'pesoR',
1759
            'tpVag',
1760
            'serie',
1761
            'nVag',
1762
            'nSeq',
1763
            'TU'
1764
        ];
1765
        $identificador = '[1] <vag> - ';
1766
        $std = $this->equilizeParameters($std, $possible);
1767
        $vag = $this->dom->createElement("vag");
1768
        $this->dom->addChild(
1769
            $vag,
1770
            "pesoBC",
1771
            $std->pesoBC,
1772
            true,
1773
            $identificador . "Peso Base de Cálculo de Frete em Toneladas"
1774
        );
1775
        $this->dom->addChild(
1776
            $vag,
1777
            "pesoR",
1778
            $std->pesoR,
1779
            true,
1780
            $identificador . "Peso Real em Toneladas"
1781
        );
1782
        $this->dom->addChild(
1783
            $vag,
1784
            "tpVag",
1785
            $std->tpVag,
1786
            false,
1787
            $identificador . "Tipo de Vagão"
1788
        );
1789
        $this->dom->addChild(
1790
            $vag,
1791
            "serie",
1792
            $std->serie,
1793
            true,
1794
            $identificador . "Serie de Identificação do vagão"
1795
        );
1796
        $this->dom->addChild(
1797
            $vag,
1798
            "nVag",
1799
            $std->nVag,
1800
            true,
1801
            $identificador . "Número de Identificação do vagão"
1802
        );
1803
        $this->dom->addChild(
1804
            $vag,
1805
            "nSeq",
1806
            $std->nSeq,
1807
            false,
1808
            $identificador . "Sequência do vagão na composição"
1809
        );
1810
        $this->dom->addChild(
1811
            $vag,
1812
            "TU",
1813
            $std->TU,
1814
            true,
1815
            $identificador . "Tonelada Útil"
1816
        );
1817
        $this->vag[] = $vag;
1818
        return $vag;
1819
    }
1820
1821
    /**
1822
     * tagaquav
1823
     * tag MDFe/infMDFe/infModal/aquav
1824
     *
1825
     * @param  string $cnpjAgeNav
1826
     * @param  string $tpEmb
0 ignored issues
show
Bug introduced by
There is no parameter named $cnpjAgeNav. Was it maybe removed?

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

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

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

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

Loading history...
1827
     * @param  string $cEmbar
0 ignored issues
show
Bug introduced by
There is no parameter named $tpEmb. Was it maybe removed?

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

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

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

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

Loading history...
1828
     * @param  string $nViagem
0 ignored issues
show
Bug introduced by
There is no parameter named $cEmbar. Was it maybe removed?

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

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

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

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

Loading history...
1829
     * @param  string $cPrtEmb
0 ignored issues
show
Bug introduced by
There is no parameter named $nViagem. Was it maybe removed?

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

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

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

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

Loading history...
1830
     * @param  string $cPrtDest
0 ignored issues
show
Bug introduced by
There is no parameter named $cPrtEmb. Was it maybe removed?

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

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

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

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

Loading history...
1831
     *
0 ignored issues
show
Bug introduced by
There is no parameter named $cPrtDest. Was it maybe removed?

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

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

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

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

Loading history...
1832
     * @return DOMElement
1833
     */
1834
1835
    public function tagaquav(stdClass $std)
1836
    {
1837
        $possible = [
1838
            'irin',
1839
            'tpEmb',
1840
            'cEmbar',
1841
            'xEmbar',
1842
            'nViag',
1843
            'cPrtEmb',
1844
            'cPrtDest',
1845
            'prtTrans',
1846
            'tpNav',
1847
            'infTermCarreg',
1848
            'infTermDescarreg',
1849
            'infEmbComb',
1850
            'infUnidCargaVazia',
1851
            'infUnidTranspVazia'
1852
        ];
1853
        $identificador = '[1] <aquav> - ';
1854
        $std = $this->equilizeParameters($std, $possible);
1855
        $aquav = $this->dom->createElement("aquav");
1856
        $this->dom->addChild(
1857
            $aquav,
1858
            "irin",
1859
            $std->irin,
1860
            true,
1861
            $identificador . "Irin do navio sempre deverá ser informado"
1862
        );
1863
        $this->dom->addChild(
1864
            $aquav,
1865
            "tpEmb",
1866
            $std->tpEmb,
1867
            true,
1868
            $identificador . "Código do tipo de embarcação"
1869
        );
1870
        $this->dom->addChild(
1871
            $aquav,
1872
            "cEmbar",
1873
            $std->cEmbar,
1874
            true,
1875
            $identificador . "Código da embarcação"
1876
        );
1877
        $this->dom->addChild(
1878
            $aquav,
1879
            "xEmbar",
1880
            $std->xEmbar,
1881
            true,
1882
            $identificador . "Nome da embarcação"
1883
        );
1884
        $this->dom->addChild(
1885
            $aquav,
1886
            "nViag",
1887
            $std->nViag,
1888
            true,
1889
            $identificador . "Número da Viagem"
1890
        );
1891
        $this->dom->addChild(
1892
            $aquav,
1893
            "cPrtEmb",
1894
            $std->cPrtEmb,
1895
            true,
1896
            $identificador . "Código do Porto de Embarque"
1897
        );
1898
        $this->dom->addChild(
1899
            $aquav,
1900
            "cPrtDest",
1901
            $std->cPrtDest,
1902
            true,
1903
            $identificador . "Código do Porto de Destino"
1904
        );
1905
        $this->dom->addChild(
1906
            $aquav,
1907
            "prtTrans",
1908
            $std->prtTrans,
1909
            false,
1910
            $identificador . "Porto de Transbordo"
1911
        );
1912
        $this->dom->addChild(
1913
            $aquav,
1914
            "tpNav",
1915
            $std->tpNav,
1916
            false,
1917
            $identificador . "Tipo de Navegação"
1918
        );
1919
        if ($std->infTermCarreg) {
1920
            foreach ($std->infTermCarreg as  $value) {
1921
                $this->dom->appChild($aquav, $this->taginfTermCarreg($value), 'Falta tag "infTermCarreg"');
1922
            }
1923
        }
1924
        if ($std->infTermDescarreg) {
1925
            foreach ($std->infTermDescarreg as  $value) {
1926
                $this->dom->appChild($aquav, $this->taginfTermDescarreg($value), 'Falta tag "infTermDescarreg"');
1927
            }
1928
        }
1929
        if ($std->infEmbComb) {
1930
            foreach ($std->infEmbComb as  $value) {
1931
                $this->dom->appChild($aquav, $this->taginfEmbComb($value), 'Falta tag "infEmbComb"');
1932
            }
1933
        }
1934
        if ($std->infUnidCargaVazia) {
1935
            foreach ($std->infUnidCargaVazia as  $value) {
1936
                $this->dom->appChild($aquav, $this->taginfUnidCargaVazia($value), 'Falta tag "infUnidCargaVazia"');
1937
            }
1938
        }
1939
        if ($std->infUnidTranspVazia) {
1940
            foreach ($std->infUnidTranspVazia as  $value) {
1941
                $this->dom->appChild($aquav, $this->taginfUnidTranspVazia($value), 'Falta tag "infUnidTranspVazia"');
1942
            }
1943
        }
1944
        $this->aquav = $aquav;
1945
        return $aquav;
1946
    }
1947
1948
    /**
1949
     * infUnidTranspVazia
1950
     * tag MDFe/infMDFe/infModal/Aqua/infUnidTranspVazia
1951
     *
1952
     * @return DOMElement
1953
     */
1954 View Code Duplication
    public function taginfUnidTranspVazia(stdClass $std)
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...
1955
    {
1956
        $possible = [
1957
            'idUnidTranspVazia',
1958
            'tpUnidTranspVazia'
1959
        ];
1960
        $identificador = '[1] <infUnidTranspVazia> - ';
1961
        $std = $this->equilizeParameters($std, $possible);
1962
        $infUnidTranspVazia = $this->dom->createElement("infUnidTranspVazia");
1963
        $this->dom->addChild(
1964
            $infUnidTranspVazia,
1965
            "idUnidTranspVazia",
1966
            $std->idUnidTranspVazia,
1967
            true,
1968
            $identificador . "dentificação da unidades de transporte vazia"
1969
        );
1970
        $this->dom->addChild(
1971
            $infUnidTranspVazia,
1972
            "tpUnidTranspVazia",
1973
            $std->tpUnidTranspVazia,
1974
            true,
1975
            $identificador . "Tipo da unidade de transporte vazia"
1976
        );
1977
        return $infUnidTranspVazia;
1978
    }
1979
    /**
1980
     * infUnidCargaVazia
1981
     * tag MDFe/infMDFe/infModal/Aqua/infUnidCargaVazia
1982
     *
1983
     * @return DOMElement
1984
     */
1985 View Code Duplication
    public function taginfUnidCargaVazia(stdClass $std)
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...
1986
    {
1987
        $possible = [
1988
            'idUnidCargaVazia',
1989
            'tpUnidCargaVazia'
1990
        ];
1991
        $identificador = '[1] <infUnidCargaVazia> - ';
1992
        $std = $this->equilizeParameters($std, $possible);
1993
        $infUnidCargaVazia = $this->dom->createElement("infUnidCargaVazia");
1994
        $this->dom->addChild(
1995
            $infUnidCargaVazia,
1996
            "idUnidCargaVazia",
1997
            $std->idUnidCargaVazia,
1998
            true,
1999
            $identificador . "Identificação da unidades de carga vazia"
2000
        );
2001
        $this->dom->addChild(
2002
            $infUnidCargaVazia,
2003
            "tpUnidCargaVazia",
2004
            $std->tpUnidCargaVazia,
2005
            true,
2006
            $identificador . "Tipo da unidade de carga vazia"
2007
        );
2008
        return $infUnidCargaVazia;
2009
    }
2010
    /**
2011
     * taginfTermDescarreg
2012
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
2013
     *
2014
     * @return DOMElement
2015
     */
2016 View Code Duplication
    public function taginfTermDescarreg(stdClass $std)
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...
2017
    {
2018
        $possible = [
2019
            'cTermDescarreg',
2020
            'xTermDescarreg'
2021
        ];
2022
        $identificador = '[1] <infTermDescarreg> - ';
2023
        $std = $this->equilizeParameters($std, $possible);
2024
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
2025
        $this->dom->addChild(
2026
            $infTermDescarreg,
2027
            "cTermDescarreg",
2028
            $std->cTermDescarreg,
2029
            true,
2030
            $identificador . "Código do Terminal de Descarregamento"
2031
        );
2032
        $this->dom->addChild(
2033
            $infTermDescarreg,
2034
            "xTermDescarreg",
2035
            $std->xTermDescarreg,
2036
            true,
2037
            $identificador . "Nome do Terminal de Descarregamento"
2038
        );
2039
        return $infTermDescarreg;
2040
    }
2041
    /**
2042
     * tagInfTermCarreg
2043
     * tag MDFe/infMDFe/infModal/Aqua/infTermCarreg
2044
     *
2045
     * @return DOMElement
2046
     */
2047 View Code Duplication
    public function taginfTermCarreg(stdClass $std)
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...
2048
    {
2049
        $possible = [
2050
            'cTermCarreg',
2051
            'xTermCarreg'
2052
        ];
2053
        $identificador = '[1] <infTermCarreg> - ';
2054
        $std = $this->equilizeParameters($std, $possible);
2055
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
2056
        $this->dom->addChild(
2057
            $infTermCarreg,
2058
            "cTermCarreg",
2059
            $std->cTermCarreg,
2060
            true,
2061
            $identificador . "Código do Terminal de Carregamento"
2062
        );
2063
        $this->dom->addChild(
2064
            $infTermCarreg,
2065
            "xTermCarreg",
2066
            $std->xTermCarreg,
2067
            true,
2068
            $identificador . "Nome do Terminal de Carregamento"
2069
        );
2070
        return $infTermCarreg;
2071
    }
2072
2073
    /**
2074
     * tagInfEmbComb
2075
     * tag MDFe/infMDFe/infModal/Aqua/infEmbComb
2076
     *
2077
     * @param  string cEmbComb
2078
     *
2079
     * @return DOMElement
2080
     */
2081 View Code Duplication
    public function taginfEmbComb(stdClass $std)
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...
2082
    {
2083
        $possible = [
2084
            'cEmbComb',
2085
            'xBalsa'
2086
        ];
2087
        $identificador = '[1] <infEmbComb> - ';
2088
        $std = $this->equilizeParameters($std, $possible);
2089
        $infEmbComb = $this->dom->createElement("infEmbComb");
2090
        $this->dom->addChild(
2091
            $infEmbComb,
2092
            "cEmbComb",
2093
            $std->cEmbComb,
2094
            true,
2095
            $identificador . "Código da embarcação do comboio"
2096
        );
2097
        $this->dom->addChild(
2098
            $infEmbComb,
2099
            "xBalsa",
2100
            $std->xBalsa,
2101
            true,
2102
            $identificador . "Identificador da Balsa"
2103
        );
2104
        return $infEmbComb;
2105
    }
2106
2107
    /**
2108
     * condutor
2109
     * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor
2110
     *
2111
     * @param  string $cEmbComb
0 ignored issues
show
Bug introduced by
There is no parameter named $cEmbComb. Was it maybe removed?

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

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

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

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

Loading history...
2112
     *
2113
     * @return DOMElement
2114
     */
2115 View Code Duplication
    public function tagcondutor(stdClass $std)
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...
2116
    {
2117
        $possible = [
2118
            'xNome',
2119
            'CPF',
2120
        ];
2121
        $std = $this->equilizeParameters($std, $possible);
2122
        $condutor = $this->dom->createElement("condutor");
2123
        $identificador = '[4] <condutor> - ';
2124
        $this->dom->addChild(
2125
            $condutor,
2126
            "xNome",
2127
            $std->xNome,
2128
            true,
2129
            $identificador . "Nome do Condutor "
2130
        );
2131
        $this->dom->addChild(
2132
            $condutor,
2133
            "CPF",
2134
            $std->CPF,
2135
            true,
2136
            $identificador . "CPF do Condutor "
2137
        );
2138
        return $condutor;
2139
    }
2140
2141
    /**
2142
     * tagVeicTracao
2143
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
2144
     *
2145
     * @param  stdClass $std
2146
     * @return DOMElement
2147
     */
2148
2149
    public function tagveicTracao(stdClass $std)
2150
    {
2151
        $possible = [
2152
            'cInt',
2153
            'placa',
2154
            'RENAVAM',
2155
            'tara',
2156
            'capKG',
2157
            'capM3',
2158
            'prop',
2159
            'tpRod',
2160
            'tpCar',
2161
            'UF',
2162
            'condutor'
2163
        ];
2164
        $std = $this->equilizeParameters($std, $possible);
2165
        $veicTracao = $this->dom->createElement("veicTracao");
2166
        $identificador = '[4] <disp> - ';
2167
        $this->dom->addChild(
2168
            $veicTracao,
2169
            "cInt",
2170
            $std->cInt,
2171
            false,
2172
            $identificador . "Código interno do veículo"
2173
        );
2174
        $this->dom->addChild(
2175
            $veicTracao,
2176
            "placa",
2177
            $std->placa,
2178
            true,
2179
            $identificador . "Placa do veículo"
2180
        );
2181
        $this->dom->addChild(
2182
            $veicTracao,
2183
            "RENAVAM",
2184
            $std->RENAVAM,
2185
            false,
2186
            $identificador . "RENAVAM"
2187
        );
2188
        $this->dom->addChild(
2189
            $veicTracao,
2190
            "tara",
2191
            $std->tara,
2192
            true,
2193
            $identificador . "Tara em KG"
2194
        );
2195
        $this->dom->addChild(
2196
            $veicTracao,
2197
            "capKG",
2198
            $std->capKG,
2199
            false,
2200
            $identificador . "Capacidade em KG"
2201
        );
2202
        $this->dom->addChild(
2203
            $veicTracao,
2204
            "capM3",
2205
            $std->capM3,
2206
            false,
2207
            $identificador . "Capacidade em M3"
2208
        );
2209 View Code Duplication
        if ($std->prop != null) {
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...
2210
            $possible = [
2211
                'CPF',
2212
                'CNPJ',
2213
                'RNTRC',
2214
                'xNome',
2215
                'IE',
2216
                'UF',
2217
                'tpProp'
2218
            ];
2219
            $identificadorProp = '[4] <prop> - ';
2220
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2221
            $prop = $this->dom->createElement("prop");
2222
            if ($stdprop->CPF) {
2223
                $this->dom->addChild(
2224
                    $prop,
2225
                    "CPF",
2226
                    $stdprop->CPF,
2227
                    true,
2228
                    $identificadorProp . "Número do CPF"
2229
                );
2230
            } else {
2231
                $this->dom->addChild(
2232
                    $prop,
2233
                    "CNPJ",
2234
                    $stdprop->CNPJ,
2235
                    true,
2236
                    $identificadorProp . "Número do CNPJ"
2237
                );
2238
            }
2239
            $this->dom->addChild(
2240
                $prop,
2241
                "RNTRC",
2242
                $stdprop->RNTRC,
2243
                true,
2244
                $identificadorProp . "RNTRC"
2245
            );
2246
            $this->dom->addChild(
2247
                $prop,
2248
                "xNome",
2249
                $stdprop->xNome,
2250
                true,
2251
                $identificadorProp . "Razão Social"
2252
            );
2253
            $this->dom->addChild(
2254
                $prop,
2255
                "IE",
2256
                $stdprop->IE,
2257
                true,
2258
                $identificadorProp . "Inscrição Estadual"
2259
            );
2260
            $this->dom->addChild(
2261
                $prop,
2262
                "UF",
2263
                $stdprop->UF,
2264
                true,
2265
                $identificadorProp . "Unidade da Federação"
2266
            );
2267
            $this->dom->addChild(
2268
                $prop,
2269
                "tpProp",
2270
                $stdprop->tpProp,
2271
                true,
2272
                $identificadorProp . "Tipo Proprietário"
2273
            );
2274
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "veicTracao"');
2275
        }
2276
        if ($std->condutor) {
2277
            foreach ($std->condutor as $value) {
2278
                $this->dom->appChild($veicTracao, $this->tagcondutor($value), 'Falta tag "condutor"');
2279
            }
2280
        }
2281
        $this->dom->addChild(
2282
            $veicTracao,
2283
            "tpRod",
2284
            $std->tpRod,
2285
            true,
2286
            $identificador . "Tipo de rodado"
2287
        );
2288
        $this->dom->addChild(
2289
            $veicTracao,
2290
            "tpCar",
2291
            $std->tpCar,
2292
            true,
2293
            $identificador . "Tipo de carroceria"
2294
        );
2295
        $this->dom->addChild(
2296
            $veicTracao,
2297
            "UF",
2298
            $std->UF,
2299
            true,
2300
            $identificador . "UF de licenciamento do veículo"
2301
        );
2302
        $this->veicTracao = $veicTracao;
2303
        return $veicTracao;
2304
    }
2305
2306
    /**
2307
     * tagVeicReboque
2308
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2309
     *
2310
     * @param  stdClass $std
2311
     * @return DOMElement
2312
     */
2313
    public function tagveicReboque(stdClass $std)
2314
    {
2315
        $possible = [
2316
            'cInt',
2317
            'placa',
2318
            'RENAVAM',
2319
            'tara',
2320
            'capKG',
2321
            'capM3',
2322
            'prop',
2323
            'tpCar',
2324
            'UF'
2325
        ];
2326
        $std = $this->equilizeParameters($std, $possible);
2327
        $veicReboque = $this->dom->createElement("veicReboque");
2328
        $identificador = '[4] <veicReboque> - ';
2329
        $this->dom->addChild(
2330
            $veicReboque,
2331
            "cInt",
2332
            $std->cInt,
2333
            false,
2334
            $identificador . "Código interno do veículo"
2335
        );
2336
        $this->dom->addChild(
2337
            $veicReboque,
2338
            "placa",
2339
            $std->placa,
2340
            true,
2341
            $identificador . "Placa do veículo"
2342
        );
2343
        $this->dom->addChild(
2344
            $veicReboque,
2345
            "RENAVAM",
2346
            $std->RENAVAM,
2347
            false,
2348
            $identificador . "RENAVAM"
2349
        );
2350
        $this->dom->addChild(
2351
            $veicReboque,
2352
            "tara",
2353
            $std->tara,
2354
            true,
2355
            $identificador . "Tara em KG"
2356
        );
2357
        $this->dom->addChild(
2358
            $veicReboque,
2359
            "capKG",
2360
            $std->capKG,
2361
            false,
2362
            $identificador . "Capacidade em KG"
2363
        );
2364
        $this->dom->addChild(
2365
            $veicReboque,
2366
            "capM3",
2367
            $std->capM3,
2368
            false,
2369
            $identificador . "Capacidade em M3"
2370
        );
2371 View Code Duplication
        if ($std->prop != null) {
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...
2372
            $identificadorprop = '[4] <prop> - ';
2373
            $possible = [
2374
                'CPF',
2375
                'CNPJ',
2376
                'RNTRC',
2377
                'xNome',
2378
                'IE',
2379
                'UF',
2380
                'tpProp'
2381
            ];
2382
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2383
            $prop = $this->dom->createElement("prop");
2384
            $this->dom->addChild(
2385
                $prop,
2386
                "CPF",
2387
                $stdprop->CPF,
2388
                true,
2389
                $identificadorprop . "Número do CPF"
2390
            );
2391
            $this->dom->addChild(
2392
                $prop,
2393
                "CNPJ",
2394
                $stdprop->CNPJ,
2395
                true,
2396
                $identificadorprop . "Número do CNPJ"
2397
            );
2398
            $this->dom->addChild(
2399
                $prop,
2400
                "RNTRC",
2401
                $stdprop->RNTRC,
2402
                true,
2403
                $identificadorprop . "RNTRC"
2404
            );
2405
            $this->dom->addChild(
2406
                $prop,
2407
                "xNome",
2408
                $stdprop->xNome,
2409
                true,
2410
                $identificadorprop . "Razão Social"
2411
            );
2412
            $this->dom->addChild(
2413
                $prop,
2414
                "IE",
2415
                $stdprop->IE,
2416
                true,
2417
                $identificadorprop . "Inscrição Estadual"
2418
            );
2419
            $this->dom->addChild(
2420
                $prop,
2421
                "UF",
2422
                $stdprop->UF,
2423
                true,
2424
                $identificadorprop . "Unidade da Federação"
2425
            );
2426
            $this->dom->addChild(
2427
                $prop,
2428
                "tpProp",
2429
                $stdprop->tpProp,
2430
                true,
2431
                $identificadorprop . "Tipo Proprietário"
2432
            );
2433
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "veicReboque"');
2434
        }
2435
        $this->dom->addChild(
2436
            $veicReboque,
2437
            "tpCar",
2438
            $std->tpCar,
2439
            true,
2440
            $identificador . "Tipo de carroceria"
2441
        );
2442
        $this->dom->addChild(
2443
            $veicReboque,
2444
            "UF",
2445
            $std->UF,
2446
            true,
2447
            $identificador . "UF de licenciamento do veículo"
2448
        );
2449
        $this->veicReboque[] = $veicReboque;
2450
        return $veicReboque;
2451
    }
2452
2453
    /**
2454
     * tagcodAgPorto
2455
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2456
     *
2457
     * @param  stdClass $std
2458
     * @return DOMElement
2459
     */
2460
    public function tagcodAgPorto(stdClass $std)
2461
    {
2462
        $possible = [
2463
            'codAgPorto'
2464
        ];
2465
        $std = $this->equilizeParameters($std, $possible);
2466
        $this->dom->addChild(
2467
            $this->rodo,
2468
            "codAgPorto",
2469
            $std->codAgPorto,
2470
            false,
2471
            "Código de Agendamento no porto"
2472
        );
2473
        return $this->rodo;
2474
    }
2475
2476
    /**
2477
     * taglacRodo
2478
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2479
     *
2480
     * @param  stdClass $std
2481
     * @return DOMElement
2482
     */
2483 View Code Duplication
    public function taglacRodo(stdClass $std)
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...
2484
    {
2485
        $possible = [
2486
            'nLacre'
2487
        ];
2488
        $std = $this->equilizeParameters($std, $possible);
2489
        $lacRodo = $this->dom->createElement("lacRodo");
2490
        $this->dom->addChild(
2491
            $lacRodo,
2492
            "nLacre",
2493
            $std->nLacre,
2494
            true,
2495
            "Número do Lacre"
2496
        );
2497
        $this->lacRodo[] = $lacRodo;
2498
        return $lacRodo;
2499
    }
2500
2501
    /**
2502
     * buildMDFe
2503
     * Tag raiz da MDFe
2504
     * tag MDFe DOMNode
2505
     * Função chamada pelo método [ monta ]
2506
     *
2507
     * @return DOMElement
2508
     */
2509
    protected function buildMDFe()
2510
    {
2511
        if (empty($this->MDFe)) {
2512
            $this->MDFe = $this->dom->createElement("MDFe");
2513
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
2514
        }
2515
        return $this->MDFe;
2516
    }
2517
2518
    /**
2519
     * checkMDFKey
2520
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
2521
     * Isso é útil no caso da chave informada estar errada
2522
     * se a chave estiver errada a mesma é substituida
2523
     *
2524
     * @param object $dom
2525
     */
2526
    private function checkMDFKey($dom)
2527
    {
2528
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2529
        $ide = $dom->getElementsByTagName("ide")->item(0);
2530
        $emit = $dom->getElementsByTagName("emit")->item(0);
2531
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
2532
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
2533
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
2534
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
2535
        } else {
2536
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
2537
        }
2538
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
2539
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
2540
        $nNF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
2541
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
2542
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
2543
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
2544
        $dt = new DateTime($dhEmi);
2545
        $chaveMontada = Keys::build(
2546
            $cUF,
2547
            $dt->format('y'),
2548
            $dt->format('m'),
2549
            $doc,
2550
            $mod,
2551
            $serie,
2552
            $nNF,
2553
            $tpEmis,
2554
            $cNF
2555
        );
2556
2557
        //caso a chave contida na NFe esteja errada
2558
        //substituir a chave
2559
        if ($chaveMontada != $chave) {
2560
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
2561
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2562
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
2563
            $infMDFe->setAttribute("versao", $this->versao);
2564
            $this->chMDFe = $chaveMontada;
2565
        }
2566
    }
2567
2568
    /**
2569
     * Includes missing or unsupported properties in stdClass
2570
     * Replace all unsuported chars
2571
     * @param stdClass $std
2572
     * @param array $possible
2573
     * @return stdClass
2574
     */
2575
    protected function equilizeParameters(stdClass $std, $possible)
2576
    {
2577
        $arr = get_object_vars($std);
2578
        foreach ($possible as $key) {
2579
            if (!array_key_exists($key, $arr)) {
2580
                $std->$key = null;
2581
            } else {
2582
                if (is_string($std->$key)) {
2583
                    $std->$key = trim(Strings::replaceUnacceptableCharacters($std->$key));
2584
                    if ($this->replaceAccentedChars) {
2585
                        $std->$key = Strings::toASCII($std->$key);
2586
                    }
2587
                }
2588
            }
2589
        }
2590
        return $std;
2591
    }
2592
}
2593