Completed
Pull Request — master (#89)
by
unknown
30:41 queued 15:40
created

Make::monta()   F

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 101

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 101
ccs 0
cts 86
cp 0
crap 812
rs 0
c 0
b 0
f 0

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
        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...
357
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
358
        }
359
        if (!empty($this->infAdic)) {
360
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
361
        }
362
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
363
        $this->dom->appendChild($this->MDFe);
364
        // testa da chave
365
        $this->checkMDFKey($this->dom);
366
        $this->xml = $this->dom->saveXML();
367
        return true;
368
    }
369
370
    /**
371
     * Informações de identificação da MDFe
372
     * tag MDFe/infMDFe/ide
373
     * @param  stdClass $std
374
     * @return DOMElement
375
     */
376
    public function tagide(stdClass $std)
377
    {
378
379
        $possible = [
380
            'cUF',
381
            'tpAmb',
382
            'tpEmit',
383
            'tpTransp',
384
            'mod',
385
            'serie',
386
            'nMDF',
387
            'cMDF',
388
            'cDV',
389
            'modal',
390
            'dhEmi',
391
            'tpEmis',
392
            'procEmi',
393
            'verProc',
394
            'ufIni',
395
            'ufFim'
396
        ];
397
398
        $std = $this->equilizeParameters($std, $possible);
399
400
        $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...
401
        $identificador = '[4] <ide> - ';
402
        $ide = $this->dom->createElement("ide");
403
        $this->dom->addChild(
404
            $ide,
405
            "cUF",
406
            $std->cUF,
407
            true,
408
            $identificador . "Código da UF do emitente do Documento Fiscal"
409
        );
410
        $this->dom->addChild(
411
            $ide,
412
            "tpAmb",
413
            $std->tpAmb,
414
            true,
415
            $identificador . "Identificação do Ambiente"
416
        );
417
        $this->dom->addChild(
418
            $ide,
419
            "tpEmit",
420
            $std->tpEmit,
421
            true,
422
            $identificador . "Indicador da tipo de emitente"
423
        );
424
        $this->dom->addChild(
425
            $ide,
426
            "tpTransp",
427
            $std->tpTransp,
428
            false,
429
            $identificador . "Tipo do Transportador"
430
        );
431
        $this->dom->addChild(
432
            $ide,
433
            "mod",
434
            $std->mod,
435
            true,
436
            $identificador . "Código do Modelo do Documento Fiscal"
437
        );
438
        $this->dom->addChild(
439
            $ide,
440
            "serie",
441
            $std->serie,
442
            true,
443
            $identificador . "Série do Documento Fiscal"
444
        );
445
        $this->dom->addChild(
446
            $ide,
447
            "nMDF",
448
            $std->nMDF,
449
            true,
450
            $identificador . "Número do Documento Fiscal"
451
        );
452
        $this->dom->addChild(
453
            $ide,
454
            "cMDF",
455
            str_pad($std->cMDF, 8, '0', STR_PAD_LEFT),
456
            true,
457
            $identificador . "Código do numérico do MDF"
458
        );
459
        $this->dom->addChild(
460
            $ide,
461
            "cDV",
462
            $std->cDV,
463
            true,
464
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
465
        );
466
        $this->dom->addChild(
467
            $ide,
468
            "modal",
469
            $std->modal,
470
            true,
471
            $identificador . "Modalidade de transporte"
472
        );
473
        $this->dom->addChild(
474
            $ide,
475
            "dhEmi",
476
            $std->dhEmi,
477
            true,
478
            $identificador . "Data e hora de emissão do Documento Fiscal"
479
        );
480
        $this->dom->addChild(
481
            $ide,
482
            "tpEmis",
483
            $std->tpEmis,
484
            true,
485
            $identificador . "Tipo de Emissão do Documento Fiscal"
486
        );
487
        $this->dom->addChild(
488
            $ide,
489
            "procEmi",
490
            $std->procEmi,
491
            true,
492
            $identificador . "Processo de emissão"
493
        );
494
        $this->dom->addChild(
495
            $ide,
496
            "verProc",
497
            $std->verProc,
498
            true,
499
            $identificador . "Versão do Processo de emissão"
500
        );
501
        $this->dom->addChild(
502
            $ide,
503
            "UFIni",
504
            $std->UFIni,
505
            true,
506
            $identificador . "Sigla da UF do Carregamento"
507
        );
508
        $this->dom->addChild(
509
            $ide,
510
            "UFFim",
511
            $std->UFFim,
512
            true,
513
            $identificador . "Sigla da UF do Descarregamento"
514
        );
515
516
        $this->mod = $std->mod;
517
        $this->ide = $ide;
518
        return $ide;
519
    }
520
521
    /**
522
     * taginfMunCarrega
523
     *
524
     * tag MDFe/infMDFe/ide/infMunCarrega
525
     *
526
     * @param  stdClass $std
527
     * @return DOMElement
528
     */
529 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...
530
    {
531
        $possible = [
532
            'cMunCarrega',
533
            'xMunCarrega'
534
        ];
535
536
        $std = $this->equilizeParameters($std, $possible);
537
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
538
        $this->dom->addChild(
539
            $infMunCarrega,
540
            "cMunCarrega",
541
            $std->cMunCarrega,
542
            true,
543
            "Código do Município de Carregamento"
544
        );
545
        $this->dom->addChild(
546
            $infMunCarrega,
547
            "xMunCarrega",
548
            $std->xMunCarrega,
549
            true,
550
            "Nome do Município de Carregamento"
551
        );
552
        $this->infMunCarrega[] = $infMunCarrega;
553
        return $infMunCarrega;
554
    }
555
556
    /**
557
     * tagInfPercurso
558
     *
559
     * tag MDFe/infMDFe/ide/infPercurso
560
     *
561
     * @param  stdClass $std
562
     * @return DOMElement
563
     */
564 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...
565
    {
566
        $possible = [
567
            'UFPer'
568
        ];
569
570
        $std = $this->equilizeParameters($std, $possible);
571
        $infPercurso = $this->dom->createElement("infPercurso");
572
        $this->dom->addChild(
573
            $infPercurso,
574
            "UFPer",
575
            $std->UFPer,
576
            true,
577
            "Sigla das Unidades da Federação do percurso"
578
        );
579
        $this->infPercurso[] = $infPercurso;
580
        return $infPercurso;
581
    }
582
583
    /**
584
     * tagemit
585
     * Identificação do emitente da MDFe
586
     * tag MDFe/infMDFe/emit
587
     *
588
     * @param  stdClass $std
589
     * @return DOMElement
590
     */
591
    public function tagemit(stdClass $std)
592
    {
593
        $possible = [
594
            'CNPJ',
595
            'CPF',
596
            'IE',
597
            'xNome',
598
            'xFant'
599
        ];
600
        $std = $this->equilizeParameters($std, $possible);
601
602
        $identificador = '[25] <emit> - ';
603
        $this->emit = $this->dom->createElement("emit");
604
        if ($std->CPF) {
605
            $this->dom->addChild(
606
                $this->emit,
607
                "CPF",
608
                $std->CPF,
609
                true,
610
                $identificador . "CPF do emitente"
611
            );
612
        } else {
613
            $this->dom->addChild(
614
                $this->emit,
615
                "CNPJ",
616
                $std->CNPJ,
617
                true,
618
                $identificador . "CNPJ do emitente"
619
            );
620
        }
621
622
        $this->dom->addChild(
623
            $this->emit,
624
            "IE",
625
            $std->IE,
626
            true,
627
            $identificador . "Inscrição Estadual do emitente"
628
        );
629
        $this->dom->addChild(
630
            $this->emit,
631
            "xNome",
632
            $std->xNome,
633
            true,
634
            $identificador . "Razão Social ou Nome do emitente"
635
        );
636
        $this->dom->addChild(
637
            $this->emit,
638
            "xFant",
639
            $std->xFant,
640
            false,
641
            $identificador . "Nome fantasia do emitente"
642
        );
643
        return $this->emit;
644
    }
645
646
    /**
647
     * tagenderEmit
648
     * Endereço do emitente [30] pai [25]
649
     * tag MDFe/infMDFe/emit/endEmit
650
     *
651
     * @param  stdClass $std
652
     * @return DOMElement
653
     */
654
    public function tagenderEmit(stdClass $std)
655
    {
656
        $possible = [
657
            'xLgr',
658
            'nro',
659
            'xCpl',
660
            'xBairro',
661
            'cMun',
662
            'xMun',
663
            'CEP',
664
            'UF',
665
            'fone',
666
            'email'
667
        ];
668
        $std = $this->equilizeParameters($std, $possible);
669
670
        $identificador = '[30] <enderEmit> - ';
671
        $this->enderEmit = $this->dom->createElement("enderEmit");
672
673
        $this->dom->addChild(
674
            $this->enderEmit,
675
            "xLgr",
676
            $std->xLgr,
677
            true,
678
            $identificador . "Logradouro do Endereço do emitente"
679
        );
680
        $this->dom->addChild(
681
            $this->enderEmit,
682
            "nro",
683
            $std->nro,
684
            true,
685
            $identificador . "Número do Endereço do emitente"
686
        );
687
        $this->dom->addChild(
688
            $this->enderEmit,
689
            "xCpl",
690
            $std->xCpl,
691
            false,
692
            $identificador . "Complemento do Endereço do emitente"
693
        );
694
        $this->dom->addChild(
695
            $this->enderEmit,
696
            "xBairro",
697
            $std->xBairro,
698
            true,
699
            $identificador . "Bairro do Endereço do emitente"
700
        );
701
        $this->dom->addChild(
702
            $this->enderEmit,
703
            "cMun",
704
            $std->cMun,
705
            true,
706
            $identificador . "Código do município do Endereço do emitente"
707
        );
708
        $this->dom->addChild(
709
            $this->enderEmit,
710
            "xMun",
711
            $std->xMun,
712
            true,
713
            $identificador . "Nome do município do Endereço do emitente"
714
        );
715
        $this->dom->addChild(
716
            $this->enderEmit,
717
            "CEP",
718
            $std->CEP,
719
            true,
720
            $identificador . "Código do CEP do Endereço do emitente"
721
        );
722
        $this->dom->addChild(
723
            $this->enderEmit,
724
            "UF",
725
            $std->UF,
726
            true,
727
            $identificador . "Sigla da UF do Endereço do emitente"
728
        );
729
        $this->dom->addChild(
730
            $this->enderEmit,
731
            "fone",
732
            $std->fone,
733
            false,
734
            $identificador . "Número de telefone do emitente"
735
        );
736
        $this->dom->addChild(
737
            $this->enderEmit,
738
            "email",
739
            $std->email,
740
            false,
741
            $identificador . "Endereço de email do emitente"
742
        );
743
        return $this->enderEmit;
744
    }
745
746
    /**
747
     * tagrodo
748
     * tag MDFe/infMDFe/infModal/rodo
749
     *
750
     * @return DOMElement
751
     */
752
    public function tagrodo()
753
    {
754
        $this->rodo = $this->dom->createElement("rodo");
755
        return $this->rodo;
756
    }
757
758
    /**
759
     * tagferrov
760
     * tag MDFe/infMDFe/infModal/ferrov
761
     *
762
     * @return DOMElement
763
     */
764
    public function tagferrov()
765
    {
766
        $this->ferrov = $this->dom->createElement("ferrov");
767
        return $this->ferrov;
768
    }
769
770
    /**
771
     * tagrodo
772
     * tag MDFe/infMDFe/infModal/rodo
773
     *
774
     * @return DOMElement
775
     */
776
    public function taginfDoc()
777
    {
778
        $this->infDoc = $this->dom->createElement("infDoc");
779
        return $this->infDoc;
780
    }
781
782
    /**
783
     * valePed
784
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed
785
     *
786
     * @return DOMElement
787
     */
788
    public function tagvalePed()
789
    {
790
791
        $this->valePed = $this->dom->createElement("valePed");
792
        return $this->valePed;
793
    }
794
795
    /**
796
     * infANTT
797
     * tag MDFe/infMDFe/infModal/rodo/infANTT
798
     *
799
     * @return DOMElement
800
     */
801 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...
802
    {
803
        $possible = [
804
            'RNTRC'
805
        ];
806
        $std = $this->equilizeParameters($std, $possible);
807
        $identificador = '[2] <infANTT> - ';
808
        $infANTT = $this->dom->createElement("infANTT");
809
        $this->dom->addChild(
810
            $infANTT,
811
            "RNTRC",
812
            $std->RNTRC,
813
            false,
814
            $identificador . "Registro Nacional de Transportadores Rodoviários de Carga"
815
        );
816
        $this->infANTT = $infANTT;
817
        return $infANTT;
818
    }
819
820
    /**
821
     * disp
822
     * tag MDFe/infMDFe/infModal/rodo/infANTT/disp
823
     *
824
     * @return DOMElement
825
     */
826 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...
827
    {
828
        $possible = [
829
            'CNPJForn',
830
            'CNPJPg',
831
            'CPFPg',
832
            'nCompra',
833
            'vValePed'
834
        ];
835
        $std = $this->equilizeParameters($std, $possible);
836
        $identificador = '[4] <disp> - ';
837
        $disp = $this->dom->createElement("disp");
838
        $this->dom->addChild(
839
            $disp,
840
            "CNPJForn",
841
            $std->CNPJForn,
842
            false,
843
            $identificador . "CNPJ da empresa fornecedora do ValePedágio"
844
        );
845
        $this->dom->addChild(
846
            $disp,
847
            "CNPJPg",
848
            $std->CNPJPg,
849
            false,
850
            $identificador . "CNPJ do responsável pelo pagamento do Vale-Pedágio"
851
        );
852
        $this->dom->addChild(
853
            $disp,
854
            "CPFPg",
855
            $std->CPFPg,
856
            false,
857
            $identificador . "CPF do responsável pelo pagamento do Vale-Pedágio"
858
        );
859
        $this->dom->addChild(
860
            $disp,
861
            "nCompra",
862
            $std->nCompra,
863
            false,
864
            $identificador . "Número do comprovante de compra"
865
        );
866
        $this->dom->addChild(
867
            $disp,
868
            "vValePed",
869
            $std->vValePed,
870
            false,
871
            $identificador . "Valor do Vale-Pedagio"
872
        );
873
        $this->disp[] = $disp;
874
        return $disp;
875
    }
876
    /**
877
     * infContratante
878
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infContratante
879
     *
880
     * @return DOMElement
881
     */
882
    public function taginfContratante(stdClass $std)
883
    {
884
        $possible = [
885
            'CPF',
886
            'CNPJ'
887
        ];
888
        $std = $this->equilizeParameters($std, $possible);
889
        $identificador = '[4] <infContratante> - ';
890
        $infContratante = $this->dom->createElement("infContratante");
891
        if ($std->CPF) {
892
            $this->dom->addChild(
893
                $infContratante,
894
                "CPF",
895
                $std->CPF,
896
                true,
897
                $identificador . "Número do CPF do contratente do serviço"
898
            );
899
        } else {
900
            $this->dom->addChild(
901
                $infContratante,
902
                "CNPJ",
903
                $std->CNPJ,
904
                true,
905
                $identificador . "Número do CNPJ do contratente do serviço"
906
            );
907
        }
908
        $this->infContratante[] = $infContratante;
909
        return $infContratante;
910
    }
911
912
    /**
913
     * infANTT
914
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infCIOT
915
     *
916
     * @return DOMElement
917
     */
918
    public function taginfCIOT(stdClass $std)
919
    {
920
        $possible = [
921
            'CIOT',
922
            'CPF',
923
            'CNPJ'
924
        ];
925
        $std = $this->equilizeParameters($std, $possible);
926
        $identificador = '[4] <infCIOT> - ';
927
        $infCIOT = $this->dom->createElement("infCIOT");
928
        $this->dom->addChild(
929
            $infCIOT,
930
            "CIOT",
931
            $std->CIOT,
932
            true,
933
            $identificador . "Código Identificador da Operação de Transporte"
934
        );
935
        if ($std->CPF) {
936
            $this->dom->addChild(
937
                $infCIOT,
938
                "CPF",
939
                $std->CPF,
940
                true,
941
                $identificador . "Número do CPF responsável pela geração do CIOT"
942
            );
943
        } else {
944
            $this->dom->addChild(
945
                $infCIOT,
946
                "CNPJ",
947
                $std->CNPJ,
948
                true,
949
                $identificador . "Número do CNPJ responsável pela geração do CIOT"
950
            );
951
        }
952
        $this->infCIOT[] = $infCIOT;
953
        return $infCIOT;
954
    }
955
956
    /**
957
     * tagInfMunDescarga
958
     * tag MDFe/infMDFe/infDoc/infMunDescarga
959
     *
960
     * @param  stdClass $std
961
     * @return DOMElement
962
     */
963 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...
964
    {
965
        $possible = [
966
            'cMunDescarga',
967
            'xMunDescarga'
968
        ];
969
        $std = $this->equilizeParameters($std, $possible);
970
        $identificador = '[4] <infMunDescarga> - ';
971
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
972
        $this->dom->addChild(
973
            $infMunDescarga,
974
            "cMunDescarga",
975
            $std->cMunDescarga,
976
            true,
977
            $identificador . "Código do Município de Descarga"
978
        );
979
        $this->dom->addChild(
980
            $infMunDescarga,
981
            "xMunDescarga",
982
            $std->xMunDescarga,
983
            true,
984
            $identificador . "Nome do Município de Descarga"
985
        );
986
        $this->infMunDescarga[] = $infMunDescarga;
987
        return $infMunDescarga;
988
    }
989
      
990
    /**
991
     * taginfCTe
992
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
993
     *
994
     * @param  stdClass $std
995
     * @return DOMElement
996
     */
997
    public function taginfCTe(stdClass $std)
998
    {
999
        $possible = [
1000
            'chCTe',
1001
            'SegCodBarra',
1002
            'indReentrega',
1003
            'infEntregaParcial',
1004
            'infUnidTransp',
1005
            'peri'
1006
        ];
1007
        $std = $this->equilizeParameters($std, $possible);
1008
        $infCTe = $this->dom->createElement("infCTe");
1009
        $identificador = '[4] <infCTe> - ';
1010
        $this->dom->addChild(
1011
            $infCTe,
1012
            "chCTe",
1013
            $std->chCTe,
1014
            true,
1015
            $identificador . "Chave de Acesso CTe"
1016
        );
1017
        $this->dom->addChild(
1018
            $infCTe,
1019
            "SegCodBarra",
1020
            $std->SegCodBarra,
1021
            false,
1022
            $identificador . "Segundo código de barras do CTe"
1023
        );
1024
        $this->dom->addChild(
1025
            $infCTe,
1026
            "indReentrega",
1027
            $std->indReentrega,
1028
            false,
1029
            $identificador . "Indicador de Reentrega"
1030
        );
1031
        if ($std->infUnidTransp) {
1032
            foreach ($std->infUnidTransp as  $value) {
1033
                $this->dom->appChild($infCTe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1034
            }
1035
        }
1036
        if ($std->peri) {
1037
            foreach ($std->peri as  $value) {
1038
                $this->dom->appChild($infCTe, $this->tagperi($value), 'Falta tag "peri"');
1039
            }
1040
1041
        }
1042
        if ($std->infEntregaParcial != null) {
1043
            $possible = [
1044
                'qtdTotal',
1045
                'qtdParcial'
1046
            ];
1047
            $stdinfEntregaParcial = $this->equilizeParameters($std->infEntregaParcial, $possible);
1048
            $identificadorparcial = '[4] <infEntregaParcial> - ';
1049
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
1050
            $this->dom->addChild(
1051
                $infEntregaParcial,
1052
                "qtdTotal",
1053
                $stdinfEntregaParcial->qtdTotal,
1054
                true,
1055
                $identificadorparcial . "Quantidade total de volumes"
1056
            );
1057
            $this->dom->addChild(
1058
                $infEntregaParcial,
1059
                "qtdParcial",
1060
                $stdinfEntregaParcial->qtdParcial,
1061
                true,
1062
                $identificadorparcial . "Quantidade de volumes enviados no MDF-e"
1063
            );
1064
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infCTe"');
1065
        }
1066
        $this->infCTe[count($this->infMunDescarga) - 1][] = $infCTe;
1067
        return $infCTe;
1068
    }
1069
1070
    /**
1071
     * tagperi
1072
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
1073
     *
1074
     * @param  stdClass $std
1075
     * @return DOMElement
1076
     */
1077 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...
1078
    {
1079
        $possible = [
1080
            'nONU',
1081
            'xNomeAE',
1082
            'xClaRisco',
1083
            'grEmb',
1084
            'qTotProd',
1085
            'qVolTipo'
1086
        ];
1087
        $std = $this->equilizeParameters($std, $possible);
1088
        $peri = $this->dom->createElement("peri");
1089
        $this->dom->addChild(
1090
            $peri,
1091
            "nONU",
1092
            $std->nONU,
1093
            true,
1094
            "Número ONU/UN"
1095
        );
1096
        $this->dom->addChild(
1097
            $peri,
1098
            "xNomeAE",
1099
            $std->xNomeAE,
1100
            true,
1101
            "Nome apropriado para embarque do produto"
1102
        );
1103
        $this->dom->addChild(
1104
            $peri,
1105
            "xClaRisco",
1106
            $std->xClaRisco,
1107
            true,
1108
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
1109
        );
1110
        $this->dom->addChild(
1111
            $peri,
1112
            "grEmb",
1113
            $std->grEmb,
1114
            true,
1115
            "Grupo de Embalagem"
1116
        );
1117
        $this->dom->addChild(
1118
            $peri,
1119
            "qTotProd",
1120
            $std->qTotProd,
1121
            true,
1122
            "Quantidade total por produto"
1123
        );
1124
        $this->dom->addChild(
1125
            $peri,
1126
            "qVolTipo",
1127
            $std->qVolTipo,
1128
            true,
1129
            "Quantidade e Tipo de volumes"
1130
        );
1131
        return $peri;
1132
    }
1133
1134
    /**
1135
     * taginfNFe
1136
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
1137
     *
1138
     * @param  stdClass $std
1139
     * @return DOMElement
1140
     */
1141
    public function taginfNFe(stdClass $std)
1142
    {
1143
        $possible = [
1144
            'chNFe',
1145
            'SegCodBarra',
1146
            'indReentrega',
1147
            'infUnidTransp',
1148
            'peri'
1149
        ];
1150
        $std = $this->equilizeParameters($std, $possible);
1151
        $infNFe = $this->dom->createElement("infNFe");
1152
        $this->dom->addChild(
1153
            $infNFe,
1154
            "chNFe",
1155
            $std->chNFe,
1156
            true,
1157
            "Chave de Acesso NFe"
1158
        );
1159
        $this->dom->addChild(
1160
            $infNFe,
1161
            "SegCodBarra",
1162
            $std->SegCodBarra,
1163
            false,
1164
            "Segundo código de barras do NFe"
1165
        );
1166
        $this->dom->addChild(
1167
            $infNFe,
1168
            "indReentrega",
1169
            $std->indReentrega,
1170
            false,
1171
            "Indicador de Reentrega"
1172
        );
1173
        if ($std->infUnidTransp) {
1174
            foreach ($std->infUnidTransp as  $value) {
1175
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1176
            }
1177
        }
1178
        if ($std->peri) {
1179
            foreach ($std->peri as  $value) {
1180
                $this->dom->appChild($infNFe, $this->tagperi($value), 'Falta tag "peri"');
1181
            }
1182
        }
1183
        $this->infNFe[count($this->infMunDescarga) - 1][] = $infNFe;
1184
        return $infNFe;
1185
    }
1186
1187
    /**
1188
     * taginfMDFeTransp
1189
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1190
     *
1191
     * @param  stdClass $std
1192
     * @return DOMElement
1193
     */
1194
    public function taginfMDFeTransp(stdClass $std)
1195
    {
1196
        $possible = [
1197
            'chNFe',
1198
            'indReentrega',
1199
        ];
1200
        $std = $this->equilizeParameters($std, $possible);
1201
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1202
        $this->dom->addChild(
1203
            $infMDFeTransp,
1204
            "chNFe",
1205
            $std->chNFe,
1206
            true,
1207
            "Chave de Acesso NFe"
1208
        );
1209
        $this->dom->addChild(
1210
            $infMDFeTransp,
1211
            "indReentrega",
1212
            $std->indReentrega,
1213
            false,
1214
            "Indicador de Reentrega"
1215
        );
1216
        if ($std->infUnidTransp) {
1217
            foreach ($std->infUnidTransp as  $value) {
1218
                $this->dom->appChild($infMDFeTransp, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1219
            }
1220
        }
1221
        if ($std->peri) {
1222
            foreach ($std->peri as  $value) {
1223
                $this->dom->appChild($infMDFeTransp, $this->tagperi($value), 'Falta tag "peri"');
1224
            }
1225
        }
1226
        $this->infMDFeTransp[count($this->infMunDescarga) - 1][] = $infMDFeTransp;
1227
        return $infMDFeTransp;
1228
    }
1229
1230
    /**
1231
     * taginfUnidTransp
1232
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1233
     *
1234
     * @param  stdClass $std
1235
     * @return DOMElement
1236
     */
1237
    public function taginfUnidTransp(stdClass $std)
1238
    {
1239
        $possible = [
1240
            'tpUnidTransp',
1241
            'idUnidTransp',
1242
            'qtdRat',
1243
            'lacUnidTransp',
1244
            'infUnidCarga'
1245
        ];
1246
        $std = $this->equilizeParameters($std, $possible);
1247
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1248
        $this->dom->addChild(
1249
            $infUnidTransp,
1250
            "tpUnidTransp",
1251
            $std->tpUnidTransp,
1252
            true,
1253
            "Tipo da Unidade de Transporte"
1254
        );
1255
        $this->dom->addChild(
1256
            $infUnidTransp,
1257
            "idUnidTransp",
1258
            $std->idUnidTransp,
1259
            false,
1260
            "Identificação da Unidade de Transporte"
1261
        );
1262 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...
1263
            $possible = [
1264
                'nLacre'
1265
            ];
1266
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1267
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
1268
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1269
                $this->dom->addChild(
1270
                    $lacUnidTransp,
1271
                    "nLacre",
1272
                    $nLacre,
1273
                    true,
1274
                    "Número do lacre"
1275
                );
1276
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
1277
            }
1278
        }
1279
        if ($std->infUnidCarga) {
1280
            foreach ($std->infUnidCarga as  $value) {
1281
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
1282
            }
1283
1284
        }
1285
        $this->dom->addChild(
1286
            $infUnidTransp,
1287
            "qtdRat",
1288
            $std->qtdRat,
1289
            false,
1290
            "Quantidade rateada (Peso,Volume) "
1291
        );
1292
        return $infUnidTransp;
1293
    }
1294
1295
    /**
1296
     * taginfUnidCarga
1297
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1298
     *
1299
     * @param  stdClass $std
1300
     * @return DOMElement
1301
     */
1302
    public function taginfUnidCarga(stdClass $std)
1303
    {
1304
        $possible = [
1305
            'tpUnidCarga',
1306
            'idUnidCarga',
1307
            'lacUnidCarga',
1308
            'qtdRat'
1309
        ];
1310
        $std = $this->equilizeParameters($std, $possible);
1311
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1312
        $this->dom->addChild(
1313
            $infUnidCarga,
1314
            "tpUnidCarga",
1315
            $std->tpUnidCarga,
1316
            false,
1317
            "Tipo da Unidade de Carga"
1318
        );
1319
        $this->dom->addChild(
1320
            $infUnidCarga,
1321
            "idUnidCarga",
1322
            $std->idUnidCarga,
1323
            false,
1324
            "Identificação da Unidade de Carga "
1325
        );
1326 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...
1327
            $possible = [
1328
                'nLacre'
1329
            ];
1330
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1331
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
1332
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1333
                $this->dom->addChild(
1334
                    $lacUnidCarga,
1335
                    "nLacre",
1336
                    $nLacre,
1337
                    true,
1338
                    "Número do lacre"
1339
                );
1340
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
1341
            }
1342
        }
1343
        $this->dom->addChild(
1344
            $infUnidCarga,
1345
            "qtdRat",
1346
            $std->qtdRat,
1347
            false,
1348
            "Quantidade rateada (Peso,Volume) "
1349
        );
1350
        return $infUnidCarga;
1351
    }
1352
1353
    /**
1354
     * tagseg
1355
     * tag MDFe/infMDFe/seg
1356
     *
1357
     * @param  stdClass $std
1358
     * @return DOMElement
1359
     */
1360
    public function tagseg(stdClass $std)
1361
    {
1362
        $possible = [
1363
            'respSeg',
1364
            'CNPJ',
1365
            'CPF',
1366
            'infSeg',
1367
            'nApol',
1368
            'nAver'
1369
        ];
1370
        $std = $this->equilizeParameters($std, $possible);
1371
        $seg = $this->dom->createElement("seg");
1372
        $infResp = $this->dom->createElement("infResp");
1373
        $this->dom->addChild(
1374
            $infResp,
1375
            "respSeg",
1376
            $std->respSeg,
1377
            true,
1378
            "Responsável pelo seguro"
1379
        );
1380
        $this->dom->addChild(
1381
            $infResp,
1382
            "CNPJ",
1383
            $std->CNPJ,
1384
            false,
1385
            "Número do CNPJ do responsável pelo seguro"
1386
        );
1387
        $this->dom->addChild(
1388
            $infResp,
1389
            "CPF",
1390
            $std->CPF,
1391
            false,
1392
            "Número do CPF do responsável pelo seguro"
1393
        );
1394
        $this->dom->appChild($seg, $infResp, 'Falta tag "seg"');
1395
        if ($std->infSeg != null) {
1396
            $possible = [
1397
                'xSeg',
1398
                'CNPJ'
1399
            ];
1400
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1401
            $infSeg = $this->dom->createElement("infSeg");
1402
            $this->dom->addChild(
1403
                $infSeg,
1404
                "xSeg",
1405
                $stdinfSeg->xSeg,
1406
                true,
1407
                "Nome da Seguradora"
1408
            );
1409
            $this->dom->addChild(
1410
                $infSeg,
1411
                "CNPJ",
1412
                $stdinfSeg->CNPJ,
1413
                false,
1414
                "Número do CNPJ da seguradora"
1415
            );
1416
            $this->dom->appChild($seg, $infSeg, 'Falta tag "seg"');
1417
        }
1418
        $this->dom->addChild(
1419
            $seg,
1420
            "nApol",
1421
            $std->nApol,
1422
            false,
1423
            "Número da Apólice"
1424
        );
1425
        if ($std->nAver != null) {
1426
            foreach ($std->nAver as $nAver) {
1427
                $this->dom->addChild(
1428
                    $seg,
1429
                    "nAver",
1430
                    $nAver,
1431
                    true,
1432
                    "Número da Averbação"
1433
                );
1434
            }
1435
        }
1436
        $this->seg[] = $seg;
1437
        return $seg;
1438
    }
1439
1440
    /**
1441
     * tagTot
1442
     * tag MDFe/infMDFe/tot
1443
     *
1444
     * @param  stdClass $std
1445
     * @return DOMElement
1446
     */
1447 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...
1448
    {
1449
        $possible = [
1450
            'qCTe',
1451
            'qNFe',
1452
            'qMDFe',
1453
            'vCarga',
1454
            'cUnid',
1455
            'qCarga'
1456
        ];
1457
        $std = $this->equilizeParameters($std, $possible);
1458
        $tot = $this->dom->createElement("tot");
1459
        $this->dom->addChild(
1460
            $tot,
1461
            "qCTe",
1462
            $std->qCTe,
1463
            false,
1464
            "Quantidade total de CT-e relacionados no Manifesto"
1465
        );
1466
        $this->dom->addChild(
1467
            $tot,
1468
            "qNFe",
1469
            $std->qNFe,
1470
            false,
1471
            "Quantidade total de NF-e relacionados no Manifesto"
1472
        );
1473
        $this->dom->addChild(
1474
            $tot,
1475
            "qMDFe",
1476
            $std->qMDFe,
1477
            false,
1478
            "Quantidade total de MDF-e relacionados no Manifesto"
1479
        );
1480
        $this->dom->addChild(
1481
            $tot,
1482
            "vCarga",
1483
            $std->vCarga,
1484
            true,
1485
            "Valor total da mercadoria/carga transportada"
1486
        );
1487
        $this->dom->addChild(
1488
            $tot,
1489
            "cUnid",
1490
            $std->cUnid,
1491
            true,
1492
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1493
        );
1494
        $this->dom->addChild(
1495
            $tot,
1496
            "qCarga",
1497
            $std->qCarga,
1498
            true,
1499
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1500
        );
1501
        $this->tot = $tot;
1502
        return $tot;
1503
    }
1504
1505
    /**
1506
     * tagLacres
1507
     * tag MDFe/infMDFe/lacres
1508
     *
1509
     * @param  stdClass $std
1510
     * @return DOMElement
1511
     */
1512 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...
1513
    {
1514
        $possible = [
1515
            'nLacre'
1516
        ];
1517
        $std = $this->equilizeParameters($std, $possible);
1518
		foreach ($std->nLacre as $nLacre) {
1519
			$lacres = $this->dom->createElement("lacres");
1520
			$this->dom->addChild(
1521
				$lacres,
1522
				"nLacre",
1523
				$nLacre,
1524
				false,
1525
				"Número do lacre"
1526
			);
1527
			$this->aLacres[] = $lacres; //array de DOMNode
1528
		}
1529
        return $this->aLacres;
1530
    }
1531
1532
    /**
1533
     * taginfAdic
1534
     * Grupo de Informações Adicionais Z01 pai A01
1535
     * tag MDFe/infMDFe/infAdic (opcional)
1536
     *
1537
     * @param  stdClass $std
1538
     * @return DOMElement
1539
     */
1540 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...
1541
    {
1542
        $possible = [
1543
            'infAdFisco',
1544
            'infCpl'
1545
        ];
1546
        $std = $this->equilizeParameters($std, $possible);
1547
        $infAdic = $this->dom->createElement("infAdic");
1548
        $this->dom->addChild(
1549
            $infAdic,
1550
            "infAdFisco",
1551
            $std->infAdFisco,
1552
            false,
1553
            "Informações Adicionais de Interesse do Fisco"
1554
        );
1555
        $this->dom->addChild(
1556
            $infAdic,
1557
            "infCpl",
1558
            $std->infCpl,
1559
            false,
1560
            "Informações Complementares de interesse do Contribuinte"
1561
        );
1562
        $this->infAdic = $infAdic;
1563
        return $infAdic;
1564
    }
1565
1566
    /**
1567
     * tagautXML
1568
     * tag MDFe/infMDFe/autXML
1569
     *
1570
     * Autorizados para download do XML do MDF-e
1571
     *
1572
     * @param  stdClass $std
1573
     * @return DOMElement
1574
     */
1575 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...
1576
    {
1577
        $possible = [
1578
            'CNPJ',
1579
            'CPF'
1580
        ];
1581
        $std = $this->equilizeParameters($std, $possible);
1582
        $autXML = $this->dom->createElement("autXML");
1583
        $this->dom->addChild(
1584
            $autXML,
1585
            "CNPJ",
1586
            $std->CNPJ,
1587
            false,
1588
            "CNPJ do autorizado"
1589
        );
1590
        $this->dom->addChild(
1591
            $autXML,
1592
            "CPF",
1593
            $std->CPF,
1594
            false,
1595
            "CPF do autorizado"
1596
        );
1597
        $this->autXML[] = $autXML;
1598
        return $this->autXML;
1599
    }
1600
1601
    /**
1602
     * buildInfModal
1603
     * tag MDFe/infMDFe/infModal
1604
     *
1605
     * @return DOMElement
1606
     */
1607
    public function buildInfModal()
1608
    {
1609
        $infModal = $this->dom->createElement("infModal");
1610
        $infModal->setAttribute("versaoModal", $this->versao);
1611
        $this->infModal = $infModal;
1612
        return $infModal;
1613
    }
1614
1615
    /**
1616
     * tagAereo
1617
     * tag MDFe/infMDFe/infModal/aereo
1618
     *
1619
     * @return DOMElement
1620
     */
1621
1622
    public function tagaereo(stdClass $std)
1623
    {
1624
        $possible = [
1625
            'nac',
1626
            'matr',
1627
            'nVoo',
1628
            'cAerEmb',
1629
            'cAerDes',
1630
            'dVoo'
1631
        ];
1632
        $std = $this->equilizeParameters($std, $possible);
1633
        $aereo = $this->dom->createElement("aereo");
1634
        $identificador = '[1] <aereo> - ';
1635
        $this->dom->addChild(
1636
            $aereo,
1637
            "nac",
1638
            $std->nac,
1639
            true,
1640
            $identificador . "Marca da Nacionalidade da aeronave"
1641
        );
1642
        $this->dom->addChild(
1643
            $aereo,
1644
            "matr",
1645
            $std->matr,
1646
            true,
1647
            $identificador . "Marca de Matrícula da aeronave"
1648
        );
1649
        $this->dom->addChild(
1650
            $aereo,
1651
            "nVoo",
1652
            $std->nVoo,
1653
            true,
1654
            $identificador . "Número do Vôo"
1655
        );
1656
        $this->dom->addChild(
1657
            $aereo,
1658
            "cAerEmb",
1659
            $std->cAerEmb,
1660
            true,
1661
            $identificador . "Aeródromo de Embarque - Código IATA"
1662
        );
1663
        $this->dom->addChild(
1664
            $aereo,
1665
            "cAerDes",
1666
            $std->cAerDes,
1667
            true,
1668
            $identificador . "Aeródromo de Destino - Código IATA"
1669
        );
1670
        $this->dom->addChild(
1671
            $aereo,
1672
            "dVoo",
1673
            $std->dVoo,
1674
            true,
1675
            $identificador . "Data do Vôo"
1676
        );
1677
        $this->aereo = $aereo;
1678
        return $aereo;
1679
    }
1680
1681
1682
1683
    /**
1684
     * tagtrem
1685
     * tag MDFe/infMDFe/infModal/ferrov/trem
1686
     *
1687
     * @return DOMElement
1688
     */
1689
1690 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...
1691
    {
1692
        $possible = [
1693
            'xPref',
1694
            'dhTrem',
1695
            'xOri',
1696
            'xDest',
1697
            'qVag'
1698
        ];
1699
        $std = $this->equilizeParameters($std, $possible);
1700
        $trem = $this->dom->createElement("trem");
1701
        $identificador = '[1] <trem> - ';
1702
        $this->dom->addChild(
1703
            $trem,
1704
            "xPref",
1705
            $std->xPref,
1706
            true,
1707
            $identificador . "Prefixo do Trem"
1708
        );
1709
        $this->dom->addChild(
1710
            $trem,
1711
            "dhTrem",
1712
            $std->dhTrem,
1713
            false,
1714
            $identificador . "Data e hora de liberação do trem na origem"
1715
        );
1716
        $this->dom->addChild(
1717
            $trem,
1718
            "xOri",
1719
            $std->xOri,
1720
            true,
1721
            $identificador . "Origem do Trem"
1722
        );
1723
        $this->dom->addChild(
1724
            $trem,
1725
            "xDest",
1726
            $std->xDest,
1727
            true,
1728
            $identificador . "Destino do Trem"
1729
        );
1730
        $this->dom->addChild(
1731
            $trem,
1732
            "qVag",
1733
            $std->qVag,
1734
            true,
1735
            $identificador . "Quantidade de vagões carregados"
1736
        );
1737
        $this->trem = $trem;
1738
        return $trem;
1739
    }
1740
1741
    /**
1742
     * tagVag
1743
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
1744
     *
1745
     * @param  string $serie
1746
     * @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...
1747
     * @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...
1748
     * @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...
1749
     *
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...
1750
     * @return DOMElement
1751
     */
1752
1753
    public function tagVag(stdClass $std)
1754
    {
1755
        $possible = [
1756
            'pesoBC',
1757
            'pesoR',
1758
            'tpVag',
1759
            'serie',
1760
            'nVag',
1761
            'nSeq',
1762
            'TU'
1763
        ];
1764
        $identificador = '[1] <vag> - ';
1765
        $std = $this->equilizeParameters($std, $possible);
1766
        $vag = $this->dom->createElement("vag");
1767
        $this->dom->addChild(
1768
            $vag,
1769
            "pesoBC",
1770
            $std->pesoBC,
1771
            true,
1772
            $identificador . "Peso Base de Cálculo de Frete em Toneladas"
1773
        );
1774
        $this->dom->addChild(
1775
            $vag,
1776
            "pesoR",
1777
            $std->pesoR,
1778
            true,
1779
            $identificador . "Peso Real em Toneladas"
1780
        );
1781
        $this->dom->addChild(
1782
            $vag,
1783
            "tpVag",
1784
            $std->tpVag,
1785
            false,
1786
            $identificador . "Tipo de Vagão"
1787
        );
1788
        $this->dom->addChild(
1789
            $vag,
1790
            "serie",
1791
            $std->serie,
1792
            true,
1793
            $identificador . "Serie de Identificação do vagão"
1794
        );
1795
        $this->dom->addChild(
1796
            $vag,
1797
            "nVag",
1798
            $std->nVag,
1799
            true,
1800
            $identificador . "Número de Identificação do vagão"
1801
        );
1802
        $this->dom->addChild(
1803
            $vag,
1804
            "nSeq",
1805
            $std->nSeq,
1806
            false,
1807
            $identificador . "Sequência do vagão na composição"
1808
        );
1809
        $this->dom->addChild(
1810
            $vag,
1811
            "TU",
1812
            $std->TU,
1813
            true,
1814
            $identificador . "Tonelada Útil"
1815
        );
1816
        $this->vag[] = $vag;
1817
        return $vag;
1818
    }
1819
1820
    /**
1821
     * tagaquav
1822
     * tag MDFe/infMDFe/infModal/aquav
1823
     *
1824
     * @param  string $cnpjAgeNav
1825
     * @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...
1826
     * @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...
1827
     * @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...
1828
     * @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...
1829
     * @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...
1830
     *
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...
1831
     * @return DOMElement
1832
     */
1833
1834
    public function tagaquav(stdClass $std)
1835
    {
1836
        $possible = [
1837
            'irin',
1838
            'tpEmb',
1839
            'cEmbar',
1840
            'xEmbar',
1841
            'nViag',
1842
            'cPrtEmb',
1843
            'cPrtDest',
1844
            'prtTrans',
1845
            'tpNav',
1846
            'infTermCarreg',
1847
            'infTermDescarreg',
1848
            'infEmbComb',
1849
            'infUnidCargaVazia',
1850
            'infUnidTranspVazia'
1851
        ];
1852
        $identificador = '[1] <aquav> - ';
1853
        $std = $this->equilizeParameters($std, $possible);
1854
        $aquav = $this->dom->createElement("aquav");
1855
        $this->dom->addChild(
1856
            $aquav,
1857
            "irin",
1858
            $std->irin,
1859
            true,
1860
            $identificador . "Irin do navio sempre deverá ser informado"
1861
        );
1862
        $this->dom->addChild(
1863
            $aquav,
1864
            "tpEmb",
1865
            $std->tpEmb,
1866
            true,
1867
            $identificador . "Código do tipo de embarcação"
1868
        );
1869
        $this->dom->addChild(
1870
            $aquav,
1871
            "cEmbar",
1872
            $std->cEmbar,
1873
            true,
1874
            $identificador . "Código da embarcação"
1875
        );
1876
        $this->dom->addChild(
1877
            $aquav,
1878
            "xEmbar",
1879
            $std->xEmbar,
1880
            true,
1881
            $identificador . "Nome da embarcação"
1882
        );
1883
        $this->dom->addChild(
1884
            $aquav,
1885
            "nViag",
1886
            $std->nViag,
1887
            true,
1888
            $identificador . "Número da Viagem"
1889
        );
1890
        $this->dom->addChild(
1891
            $aquav,
1892
            "cPrtEmb",
1893
            $std->cPrtEmb,
1894
            true,
1895
            $identificador . "Código do Porto de Embarque"
1896
        );
1897
        $this->dom->addChild(
1898
            $aquav,
1899
            "cPrtDest",
1900
            $std->cPrtDest,
1901
            true,
1902
            $identificador . "Código do Porto de Destino"
1903
        );
1904
        $this->dom->addChild(
1905
            $aquav,
1906
            "prtTrans",
1907
            $std->prtTrans,
1908
            false,
1909
            $identificador . "Porto de Transbordo"
1910
        );
1911
        $this->dom->addChild(
1912
            $aquav,
1913
            "tpNav",
1914
            $std->tpNav,
1915
            false,
1916
            $identificador . "Tipo de Navegação"
1917
        );
1918
        if ($std->infTermCarreg) {
1919
            foreach ($std->infTermCarreg as  $value) {
1920
                $this->dom->appChild($aquav, $this->taginfTermCarreg($value), 'Falta tag "infTermCarreg"');
1921
            }
1922
        }
1923
        if ($std->infTermDescarreg) {
1924
            foreach ($std->infTermDescarreg as  $value) {
1925
                $this->dom->appChild($aquav, $this->taginfTermDescarreg($value), 'Falta tag "infTermDescarreg"');
1926
            }
1927
        }
1928
        if ($std->infEmbComb) {
1929
            foreach ($std->infEmbComb as  $value) {
1930
                $this->dom->appChild($aquav, $this->taginfEmbComb($value), 'Falta tag "infEmbComb"');
1931
            }
1932
        }
1933
        if ($std->infUnidCargaVazia) {
1934
            foreach ($std->infUnidCargaVazia as  $value) {
1935
                $this->dom->appChild($aquav, $this->taginfUnidCargaVazia($value), 'Falta tag "infUnidCargaVazia"');
1936
            }
1937
        }
1938
        if ($std->infUnidTranspVazia) {
1939
            foreach ($std->infUnidTranspVazia as  $value) {
1940
                $this->dom->appChild($aquav, $this->taginfUnidTranspVazia($value), 'Falta tag "infUnidTranspVazia"');
1941
            }
1942
        }
1943
        $this->aquav = $aquav;
1944
        return $aquav;
1945
    }
1946
1947
    /**
1948
     * infUnidTranspVazia
1949
     * tag MDFe/infMDFe/infModal/Aqua/infUnidTranspVazia
1950
     *
1951
     * @return DOMElement
1952
     */
1953 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...
1954
    {
1955
        $possible = [
1956
            'idUnidTranspVazia',
1957
            'tpUnidTranspVazia'
1958
        ];
1959
        $identificador = '[1] <infUnidTranspVazia> - ';
1960
        $std = $this->equilizeParameters($std, $possible);
1961
        $infUnidTranspVazia = $this->dom->createElement("infUnidTranspVazia");
1962
        $this->dom->addChild(
1963
            $infUnidTranspVazia,
1964
            "idUnidTranspVazia",
1965
            $std->idUnidTranspVazia,
1966
            true,
1967
            $identificador . "dentificação da unidades de transporte vazia"
1968
        );
1969
        $this->dom->addChild(
1970
            $infUnidTranspVazia,
1971
            "tpUnidTranspVazia",
1972
            $std->tpUnidTranspVazia,
1973
            true,
1974
            $identificador . "Tipo da unidade de transporte vazia"
1975
        );
1976
        return $infUnidTranspVazia;
1977
    }
1978
    /**
1979
     * infUnidCargaVazia
1980
     * tag MDFe/infMDFe/infModal/Aqua/infUnidCargaVazia
1981
     *
1982
     * @return DOMElement
1983
     */
1984 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...
1985
    {
1986
        $possible = [
1987
            'idUnidCargaVazia',
1988
            'tpUnidCargaVazia'
1989
        ];
1990
        $identificador = '[1] <infUnidCargaVazia> - ';
1991
        $std = $this->equilizeParameters($std, $possible);
1992
        $infUnidCargaVazia = $this->dom->createElement("infUnidCargaVazia");
1993
        $this->dom->addChild(
1994
            $infUnidCargaVazia,
1995
            "idUnidCargaVazia",
1996
            $std->idUnidCargaVazia,
1997
            true,
1998
            $identificador . "Identificação da unidades de carga vazia"
1999
        );
2000
        $this->dom->addChild(
2001
            $infUnidCargaVazia,
2002
            "tpUnidCargaVazia",
2003
            $std->tpUnidCargaVazia,
2004
            true,
2005
            $identificador . "Tipo da unidade de carga vazia"
2006
        );
2007
        return $infUnidCargaVazia;
2008
    }
2009
    /**
2010
     * taginfTermDescarreg
2011
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
2012
     *
2013
     * @return DOMElement
2014
     */
2015 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...
2016
    {
2017
        $possible = [
2018
            'cTermDescarreg',
2019
            'xTermDescarreg'
2020
        ];
2021
        $identificador = '[1] <infTermDescarreg> - ';
2022
        $std = $this->equilizeParameters($std, $possible);
2023
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
2024
        $this->dom->addChild(
2025
            $infTermDescarreg,
2026
            "cTermDescarreg",
2027
            $std->cTermDescarreg,
2028
            true,
2029
            $identificador . "Código do Terminal de Descarregamento"
2030
        );
2031
        $this->dom->addChild(
2032
            $infTermDescarreg,
2033
            "xTermDescarreg",
2034
            $std->xTermDescarreg,
2035
            true,
2036
            $identificador . "Nome do Terminal de Descarregamento"
2037
        );
2038
        return $infTermDescarreg;
2039
    }
2040
    /**
2041
     * tagInfTermCarreg
2042
     * tag MDFe/infMDFe/infModal/Aqua/infTermCarreg
2043
     *
2044
     * @return DOMElement
2045
     */
2046 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...
2047
    {
2048
        $possible = [
2049
            'cTermCarreg',
2050
            'xTermCarreg'
2051
        ];
2052
        $identificador = '[1] <infTermCarreg> - ';
2053
        $std = $this->equilizeParameters($std, $possible);
2054
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
2055
        $this->dom->addChild(
2056
            $infTermCarreg,
2057
            "cTermCarreg",
2058
            $std->cTermCarreg,
2059
            true,
2060
            $identificador . "Código do Terminal de Carregamento"
2061
        );
2062
        $this->dom->addChild(
2063
            $infTermCarreg,
2064
            "xTermCarreg",
2065
            $std->xTermCarreg,
2066
            true,
2067
            $identificador . "Nome do Terminal de Carregamento"
2068
        );
2069
        return $infTermCarreg;
2070
    }
2071
2072
    /**
2073
     * tagInfEmbComb
2074
     * tag MDFe/infMDFe/infModal/Aqua/infEmbComb
2075
     *
2076
     * @param  string cEmbComb
2077
     *
2078
     * @return DOMElement
2079
     */
2080 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...
2081
    {
2082
        $possible = [
2083
            'cEmbComb',
2084
            'xBalsa'
2085
        ];
2086
        $identificador = '[1] <infEmbComb> - ';
2087
        $std = $this->equilizeParameters($std, $possible);
2088
        $infEmbComb = $this->dom->createElement("infEmbComb");
2089
        $this->dom->addChild(
2090
            $infEmbComb,
2091
            "cEmbComb",
2092
            $std->cEmbComb,
2093
            true,
2094
            $identificador . "Código da embarcação do comboio"
2095
        );
2096
        $this->dom->addChild(
2097
            $infEmbComb,
2098
            "xBalsa",
2099
            $std->xBalsa,
2100
            true,
2101
            $identificador . "Identificador da Balsa"
2102
        );
2103
        return $infEmbComb;
2104
    }
2105
2106
    /**
2107
     * condutor
2108
     * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor
2109
     *
2110
     * @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...
2111
     *
2112
     * @return DOMElement
2113
     */
2114 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...
2115
    {
2116
        $possible = [
2117
            'xNome',
2118
            'CPF',
2119
        ];
2120
        $std = $this->equilizeParameters($std, $possible);
2121
        $condutor = $this->dom->createElement("condutor");
2122
        $identificador = '[4] <condutor> - ';
2123
        $this->dom->addChild(
2124
            $condutor,
2125
            "xNome",
2126
            $std->xNome,
2127
            true,
2128
            $identificador . "Nome do Condutor "
2129
        );
2130
        $this->dom->addChild(
2131
            $condutor,
2132
            "CPF",
2133
            $std->CPF,
2134
            true,
2135
            $identificador . "CPF do Condutor "
2136
        );
2137
        return $condutor;
2138
    }
2139
2140
    /**
2141
     * tagVeicTracao
2142
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
2143
     *
2144
     * @param  stdClass $std
2145
     * @return DOMElement
2146
     */
2147
2148
    public function tagveicTracao(stdClass $std)
2149
    {
2150
        $possible = [
2151
            'cInt',
2152
            'placa',
2153
            'RENAVAM',
2154
            'tara',
2155
            'capKG',
2156
            'capM3',
2157
            'prop',
2158
            'tpRod',
2159
            'tpCar',
2160
            'UF',
2161
            'condutor'
2162
        ];
2163
        $std = $this->equilizeParameters($std, $possible);
2164
        $veicTracao = $this->dom->createElement("veicTracao");
2165
        $identificador = '[4] <disp> - ';
2166
        $this->dom->addChild(
2167
            $veicTracao,
2168
            "cInt",
2169
            $std->cInt,
2170
            false,
2171
            $identificador . "Código interno do veículo"
2172
        );
2173
        $this->dom->addChild(
2174
            $veicTracao,
2175
            "placa",
2176
            $std->placa,
2177
            true,
2178
            $identificador . "Placa do veículo"
2179
        );
2180
        $this->dom->addChild(
2181
            $veicTracao,
2182
            "RENAVAM",
2183
            $std->RENAVAM,
2184
            false,
2185
            $identificador . "RENAVAM"
2186
        );
2187
        $this->dom->addChild(
2188
            $veicTracao,
2189
            "tara",
2190
            $std->tara,
2191
            true,
2192
            $identificador . "Tara em KG"
2193
        );
2194
        $this->dom->addChild(
2195
            $veicTracao,
2196
            "capKG",
2197
            $std->capKG,
2198
            false,
2199
            $identificador . "Capacidade em KG"
2200
        );
2201
        $this->dom->addChild(
2202
            $veicTracao,
2203
            "capM3",
2204
            $std->capM3,
2205
            false,
2206
            $identificador . "Capacidade em M3"
2207
        );
2208 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...
2209
            $possible = [
2210
                'CPF',
2211
                'CNPJ',
2212
                'RNTRC',
2213
                'xNome',
2214
                'IE',
2215
                'UF',
2216
                'tpProp'
2217
            ];
2218
            $identificadorProp = '[4] <prop> - ';
2219
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2220
            $prop = $this->dom->createElement("prop");
2221
            if ($stdprop->CPF) {
2222
                $this->dom->addChild(
2223
                    $prop,
2224
                    "CPF",
2225
                    $stdprop->CPF,
2226
                    true,
2227
                    $identificadorProp . "Número do CPF"
2228
                );
2229
            } else {
2230
                $this->dom->addChild(
2231
                    $prop,
2232
                    "CNPJ",
2233
                    $stdprop->CNPJ,
2234
                    true,
2235
                    $identificadorProp . "Número do CNPJ"
2236
                );
2237
            }
2238
            $this->dom->addChild(
2239
                $prop,
2240
                "RNTRC",
2241
                $stdprop->RNTRC,
2242
                true,
2243
                $identificadorProp . "RNTRC"
2244
            );
2245
            $this->dom->addChild(
2246
                $prop,
2247
                "xNome",
2248
                $stdprop->xNome,
2249
                true,
2250
                $identificadorProp . "Razão Social"
2251
            );
2252
            $this->dom->addChild(
2253
                $prop,
2254
                "IE",
2255
                $stdprop->IE,
2256
                true,
2257
                $identificadorProp . "Inscrição Estadual"
2258
            );
2259
            $this->dom->addChild(
2260
                $prop,
2261
                "UF",
2262
                $stdprop->UF,
2263
                true,
2264
                $identificadorProp . "Unidade da Federação"
2265
            );
2266
            $this->dom->addChild(
2267
                $prop,
2268
                "tpProp",
2269
                $stdprop->tpProp,
2270
                true,
2271
                $identificadorProp . "Tipo Proprietário"
2272
            );
2273
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "veicTracao"');
2274
        }
2275
        if ($std->condutor) {
2276
            foreach ($std->condutor as $value) {
2277
                $this->dom->appChild($veicTracao, $this->tagcondutor($value), 'Falta tag "condutor"');
2278
            }
2279
        }
2280
        $this->dom->addChild(
2281
            $veicTracao,
2282
            "tpRod",
2283
            $std->tpRod,
2284
            true,
2285
            $identificador . "Tipo de rodado"
2286
        );
2287
        $this->dom->addChild(
2288
            $veicTracao,
2289
            "tpCar",
2290
            $std->tpCar,
2291
            true,
2292
            $identificador . "Tipo de carroceria"
2293
        );
2294
        $this->dom->addChild(
2295
            $veicTracao,
2296
            "UF",
2297
            $std->UF,
2298
            true,
2299
            $identificador . "UF de licenciamento do veículo"
2300
        );
2301
        $this->veicTracao = $veicTracao;
2302
        return $veicTracao;
2303
    }
2304
2305
    /**
2306
     * tagVeicReboque
2307
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2308
     *
2309
     * @param  stdClass $std
2310
     * @return DOMElement
2311
     */
2312
    public function tagveicReboque(stdClass $std)
2313
    {
2314
        $possible = [
2315
            'cInt',
2316
            'placa',
2317
            'RENAVAM',
2318
            'tara',
2319
            'capKG',
2320
            'capM3',
2321
            'prop',
2322
            'tpCar',
2323
            'UF'
2324
        ];
2325
        $std = $this->equilizeParameters($std, $possible);
2326
        $veicReboque = $this->dom->createElement("veicReboque");
2327
        $identificador = '[4] <veicReboque> - ';
2328
        $this->dom->addChild(
2329
            $veicReboque,
2330
            "cInt",
2331
            $std->cInt,
2332
            false,
2333
            $identificador . "Código interno do veículo"
2334
        );
2335
        $this->dom->addChild(
2336
            $veicReboque,
2337
            "placa",
2338
            $std->placa,
2339
            true,
2340
            $identificador . "Placa do veículo"
2341
        );
2342
        $this->dom->addChild(
2343
            $veicReboque,
2344
            "RENAVAM",
2345
            $std->RENAVAM,
2346
            false,
2347
            $identificador . "RENAVAM"
2348
        );
2349
        $this->dom->addChild(
2350
            $veicReboque,
2351
            "tara",
2352
            $std->tara,
2353
            true,
2354
            $identificador . "Tara em KG"
2355
        );
2356
        $this->dom->addChild(
2357
            $veicReboque,
2358
            "capKG",
2359
            $std->capKG,
2360
            false,
2361
            $identificador . "Capacidade em KG"
2362
        );
2363
        $this->dom->addChild(
2364
            $veicReboque,
2365
            "capM3",
2366
            $std->capM3,
2367
            false,
2368
            $identificador . "Capacidade em M3"
2369
        );
2370 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...
2371
            $identificadorprop = '[4] <prop> - ';
2372
            $possible = [
2373
                'CPF',
2374
                'CNPJ',
2375
                'RNTRC',
2376
                'xNome',
2377
                'IE',
2378
                'UF',
2379
                'tpProp'
2380
            ];
2381
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2382
            $prop = $this->dom->createElement("prop");
2383
            $this->dom->addChild(
2384
                $prop,
2385
                "CPF",
2386
                $stdprop->CPF,
2387
                true,
2388
                $identificadorprop . "Número do CPF"
2389
            );
2390
            $this->dom->addChild(
2391
                $prop,
2392
                "CNPJ",
2393
                $stdprop->CNPJ,
2394
                true,
2395
                $identificadorprop . "Número do CNPJ"
2396
            );
2397
            $this->dom->addChild(
2398
                $prop,
2399
                "RNTRC",
2400
                $stdprop->RNTRC,
2401
                true,
2402
                $identificadorprop . "RNTRC"
2403
            );
2404
            $this->dom->addChild(
2405
                $prop,
2406
                "xNome",
2407
                $stdprop->xNome,
2408
                true,
2409
                $identificadorprop . "Razão Social"
2410
            );
2411
            $this->dom->addChild(
2412
                $prop,
2413
                "IE",
2414
                $stdprop->IE,
2415
                true,
2416
                $identificadorprop . "Inscrição Estadual"
2417
            );
2418
            $this->dom->addChild(
2419
                $prop,
2420
                "UF",
2421
                $stdprop->UF,
2422
                true,
2423
                $identificadorprop . "Unidade da Federação"
2424
            );
2425
            $this->dom->addChild(
2426
                $prop,
2427
                "tpProp",
2428
                $stdprop->tpProp,
2429
                true,
2430
                $identificadorprop . "Tipo Proprietário"
2431
            );
2432
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "veicReboque"');
2433
        }
2434
        $this->dom->addChild(
2435
            $veicReboque,
2436
            "tpCar",
2437
            $std->tpCar,
2438
            true,
2439
            $identificador . "Tipo de carroceria"
2440
        );
2441
        $this->dom->addChild(
2442
            $veicReboque,
2443
            "UF",
2444
            $std->UF,
2445
            true,
2446
            $identificador . "UF de licenciamento do veículo"
2447
        );
2448
        $this->veicReboque[] = $veicReboque;
2449
        return $veicReboque;
2450
    }
2451
2452
    /**
2453
     * tagcodAgPorto
2454
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2455
     *
2456
     * @param  stdClass $std
2457
     * @return DOMElement
2458
     */
2459
    public function tagcodAgPorto(stdClass $std)
2460
    {
2461
        $possible = [
2462
            'codAgPorto'
2463
        ];
2464
        $std = $this->equilizeParameters($std, $possible);
2465
        $this->dom->addChild(
2466
            $this->rodo,
2467
            "codAgPorto",
2468
            $std->codAgPorto,
2469
            false,
2470
            "Código de Agendamento no porto"
2471
        );
2472
        return $this->rodo;
2473
    }
2474
2475
    /**
2476
     * taglacRodo
2477
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2478
     *
2479
     * @param  stdClass $std
2480
     * @return DOMElement
2481
     */
2482 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...
2483
    {
2484
        $possible = [
2485
            'nLacre'
2486
        ];
2487
        $std = $this->equilizeParameters($std, $possible);
2488
        $lacRodo = $this->dom->createElement("lacRodo");
2489
        $this->dom->addChild(
2490
            $lacRodo,
2491
            "nLacre",
2492
            $std->nLacre,
2493
            true,
2494
            "Número do Lacre"
2495
        );
2496
        $this->lacRodo[] = $lacRodo;
2497
        return $lacRodo;
2498
    }
2499
2500
    /**
2501
     * buildMDFe
2502
     * Tag raiz da MDFe
2503
     * tag MDFe DOMNode
2504
     * Função chamada pelo método [ monta ]
2505
     *
2506
     * @return DOMElement
2507
     */
2508
    protected function buildMDFe()
2509
    {
2510
        if (empty($this->MDFe)) {
2511
            $this->MDFe = $this->dom->createElement("MDFe");
2512
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
2513
        }
2514
        return $this->MDFe;
2515
    }
2516
2517
    /**
2518
     * checkMDFKey
2519
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
2520
     * Isso é útil no caso da chave informada estar errada
2521
     * se a chave estiver errada a mesma é substituida
2522
     *
2523
     * @param object $dom
2524
     */
2525
    private function checkMDFKey($dom)
2526
    {
2527
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2528
        $ide = $dom->getElementsByTagName("ide")->item(0);
2529
        $emit = $dom->getElementsByTagName("emit")->item(0);
2530
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
2531
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
2532
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
2533
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
2534
        } else {
2535
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
2536
        }
2537
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
2538
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
2539
        $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
2540
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
2541
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
2542
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
2543
        $dt = new DateTime($dhEmi);
2544
        $chaveMontada = Keys::build(
2545
            $cUF,
2546
            $dt->format('y'),
2547
            $dt->format('m'),
2548
            $doc,
2549
            $mod,
2550
            $serie,
2551
            $nMDF,
2552
            $tpEmis,
2553
            $cNF
2554
        );
2555
2556
        //caso a chave contida na NFe esteja errada
2557
        //substituir a chave
2558
        if ($chaveMontada != $chave) {
2559
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
2560
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2561
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
2562
            $infMDFe->setAttribute("versao", $this->versao);
2563
            $this->chMDFe = $chaveMontada;
2564
        }
2565
    }
2566
2567
    /**
2568
     * Includes missing or unsupported properties in stdClass
2569
     * Replace all unsuported chars
2570
     * @param stdClass $std
2571
     * @param array $possible
2572
     * @return stdClass
2573
     */
2574
    protected function equilizeParameters(stdClass $std, $possible)
2575
    {
2576
        $arr = get_object_vars($std);
2577
        foreach ($possible as $key) {
2578
            if (!array_key_exists($key, $arr)) {
2579
                $std->$key = null;
2580
            } else {
2581
                if (is_string($std->$key)) {
2582
                    $std->$key = trim(Strings::replaceUnacceptableCharacters($std->$key));
2583
                    if ($this->replaceAccentedChars) {
2584
                        $std->$key = Strings::toASCII($std->$key);
2585
                    }
2586
                }
2587
            }
2588
        }
2589
        return $std;
2590
    }
2591
}
2592