Completed
Pull Request — master (#86)
by
unknown
11:01
created

Make::zTestaChaveXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 6
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 $enderEmit = '';
78
    /**
79
     * @type string|\DOMNode
80
     */
81
    private $infModal = '';
82
    /**
83
     * @type string|\DOMNode
84
     */
85
    private $tot = '';
86
    /**
87
     * @type string|\DOMNode
88
     */
89
    private $seg = '';
90
    /**
91
     * @type string|\DOMNode
92
     */
93
    private $lacres = [];
94
    /**
95
     * @type string|\DOMNode
96
     */
97
    private $autXML = [];
98
    /**
99
     * @type string|\DOMNode
100
     */
101
    private $infAdic = '';
102
    /**
103
     * @type string|\DOMNode
104
     */
105
    private $rodo = '';
106
    /**
107
     * @type string|\DOMNode
108
     */
109
    private $infDoc = '';
110
    /**
111
     * @type string|\DOMNode
112
     */
113
    private $infUnidTransp = '';
114
    /**
115
     * @type array|\DOMNode
116
     */
117
    private $aInfPercurso = [];
118
    /**
119
     * @type string|\DOMNode
120
     */
121
    private $veicTracao = '';
122
    /**
123
     * @type string|\DOMNode
124
     */
125
    private $aereo = '';
126
    /**
127
     * @type string|\DOMNode
128
     */
129
    private $trem = '';
130
    /**
131
     * @type string|\DOMNode
132
     */
133
    private $aqua = '';
134
135
    /**
136
     * @var boolean
137
     */
138
    protected $replaceAccentedChars = false;
139
140
    /**
141
     * Função construtora cria um objeto DOMDocument
142
     * que será carregado com o documento fiscal
143
     */
144
    public function __construct()
145
    {
146
        $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...
147
        $this->dom->preserveWhiteSpace = false;
148
        $this->dom->formatOutput = false;
149
    }
150
151
    /**
152
     * Retorns the xml
153
     * @return xml
154
     */
155
    public function getXML()
156
    {
157
        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...
158
            $this->montaMDFe();
159
        }
160
        return $this->xml;
161
    }
162
163
    /**
164
     * Retorns the key number of NFe (44 digits)
165
     * @return string
166
     */
167
    public function getChave()
168
    {
169
        return $this->chMDFe;
170
    }
171
172
    /**
173
     * Returns the model of MDFe
174
     * @return int
175
     */
176
    public function getModelo()
177
    {
178
        return $this->mod;
179
    }
180
181
    /**
182
     * Call method of xml assembly. For compatibility only.
183
     * @return boolean
184
     */
185
    public function montaMDFe()
186
    {
187
        return $this->monta();
188
    }
189
190
    /**
191
     * MDFe xml mount method
192
     * this function returns TRUE on success or FALSE on error
193
     * The xml of the MDFe must be retrieved by the getXML() function or
194
     * directly by the public property $xml
195
     * @return boolean
196
     */
197
    public function monta()
198
    {
199
        $this->errors = $this->dom->errors;
200
        if (count($this->errors) > 0) {
201
            return false;
202
        }
203
        //cria a tag raiz da MDFe
204
        $this->buildMDFe();
205
        $this->buildInfModal();
206
        
207
        $this->infMDFe = $this->dom->createElement("infMDFe");
208
209
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "ide"');
210
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "enderEmit"');
211
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "emit"');
212
        if (! empty($this->rodo)) {
213
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "rodo"');
214
        }
215
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infModal"');
216
        $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infDoc"');
217
        $this->dom->appChild($this->infMDFe, $this->seg, 'Falta tag "seg"');
218
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "tot"');
219
        foreach ($this->lacres as $lacres) {
0 ignored issues
show
Bug introduced by
The expression $this->lacres 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...
220
            $this->dom->appChild($this->infMDFe, $lacres, 'Falta tag "lacres"');
221
        }
222
        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...
223
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "autXML"');
224
        }
225
        $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
226
        
227
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
228
        
229
        $this->dom->appendChild($this->MDFe);
230
        // testa da chave
231
        $this->checkMDFKey($this->dom);
232
        $this->xml = $this->dom->saveXML();
233
        
234
        return true;
235
    }
236
237
    /**
238
     * Informações de identificação da MDFe
239
     * tag MDFe/infMDFe/ide
240
     * @param  int cUF Código da UF
241
     * @param  int tpAmb Tipo do Ambiente
242
     * @param  int tpEmit Tipo do Emitente
243
     * @param  string tpTransp Tipo do Transportador
244
     * @param  int mod Modelo do Manifesto Eletrônico
245
     * @param  int serie Série do Manifesto
246
     * @param  int nMDF Número do Manifesto
247
     * @param  int cMDF Código aleatório
248
     * @param  int cDV Digito verificador
249
     * @param  int modal Modalidade de transporte
250
     * @param  date dhEmi Data e hora de emissão
251
     * @param  int tpEmis Forma de emissão
252
     * @param  int procEmi Identificação do processo de emissão
253
     * @param  string verProc Versão do processo
254
     * @param  string ufIni Sigla da UF do Carregamento
255
     * @param  string ufFim Sigla da UF do Descarregamento
256
     * @return DOMElement
257
     */
258
    public function tagide(stdClass $std)
259
    {
260
261
        $possible = [
262
            'cUF',
263
            'tpAmb',
264
            'tpEmit',
265
            'tpTransp',
266
            'mod',
267
            'serie',
268
            'nMDF',
269
            'cMDF',
270
            'cDV',
271
            'modal',
272
            'dhEmi',
273
            'tpEmis',
274
            'procEmi',
275
            'verProc',
276
            'ufIni',
277
            'ufFim'
278
        ];
279
280
        $std = $this->equilizeParameters($std, $possible);
281
        
282
        $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...
283
        $identificador = '[4] <ide> - ';
284
        $ide = $this->dom->createElement("ide");
285
        $this->dom->addChild(
286
            $ide,
287
            "cUF",
288
            $std->cUF,
289
            true,
290
            $identificador . "Código da UF do emitente do Documento Fiscal"
291
        );
292
        $this->dom->addChild(
293
            $ide,
294
            "tpAmb",
295
            $std->tpAmb,
296
            true,
297
            $identificador . "Identificação do Ambiente"
298
        );
299
        $this->dom->addChild(
300
            $ide,
301
            "tpEmit",
302
            $std->tpEmit,
303
            true,
304
            $identificador . "Indicador da tipo de emitente"
305
        );
306
        $this->dom->addChild(
307
            $ide,
308
            "tpTransp",
309
            $std->tpTransp,
310
            false,
311
            $identificador . "Tipo do Transportador"
312
        );
313
        $this->dom->addChild(
314
            $ide,
315
            "mod",
316
            $std->mod,
317
            true,
318
            $identificador . "Código do Modelo do Documento Fiscal"
319
        );
320
        $this->dom->addChild(
321
            $ide,
322
            "serie",
323
            $std->serie,
324
            true,
325
            $identificador . "Série do Documento Fiscal"
326
        );
327
        $this->dom->addChild(
328
            $ide,
329
            "nMDF",
330
            $std->nMDF,
331
            true,
332
            $identificador . "Número do Documento Fiscal"
333
        );
334
        $this->dom->addChild(
335
            $ide,
336
            "cMDF",
337
            $std->cMDF,
338
            true,
339
            $identificador . "Código do numérico do MDF"
340
        );
341
        $this->dom->addChild(
342
            $ide,
343
            "cDV",
344
            $std->cDV,
345
            true,
346
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
347
        );
348
        $this->dom->addChild(
349
            $ide,
350
            "modal",
351
            $std->modal,
352
            true,
353
            $identificador . "Modalidade de transporte"
354
        );
355
        $this->dom->addChild(
356
            $ide,
357
            "dhEmi",
358
            $std->dhEmi,
359
            true,
360
            $identificador . "Data e hora de emissão do Documento Fiscal"
361
        );
362
        $this->dom->addChild(
363
            $ide,
364
            "tpEmis",
365
            $std->tpEmis,
366
            true,
367
            $identificador . "Tipo de Emissão do Documento Fiscal"
368
        );
369
        $this->dom->addChild(
370
            $ide,
371
            "procEmi",
372
            $std->procEmi,
373
            true,
374
            $identificador . "Processo de emissão"
375
        );
376
        $this->dom->addChild(
377
            $ide,
378
            "verProc",
379
            $std->verProc,
380
            true,
381
            $identificador . "Versão do Processo de emissão"
382
        );
383
        $this->dom->addChild(
384
            $ide,
385
            "UFIni",
386
            $std->UFIni,
387
            true,
388
            $identificador . "Sigla da UF do Carregamento"
389
        );
390
        $this->dom->addChild(
391
            $ide,
392
            "UFFim",
393
            $std->UFFim,
394
            true,
395
            $identificador . "Sigla da UF do Descarregamento"
396
        );
397
        
398
        $this->mod = $std->mod;
399
        $this->ide = $ide;
400
        $this->buildTagIde();
401
        return $ide;
402
    }
403
404
    /**
405
     * taginfMunCarrega
406
     *
407
     * tag MDFe/infMDFe/ide/infMunCarrega
408
     *
409
     * @param  int cMunCarrega Código do Município de Carregamento
410
     * @param  string xMunCarrega Nome do Município de Carregamento
411
     *
412
     * @return DOMElement
413
     */
414 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...
415
    {
416
        $possible = [
417
            'cMunCarrega',
418
            'xMunCarrega'
419
        ];
420
421
        $std = $this->equilizeParameters($std, $possible);
422
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
423
        $this->dom->addChild(
424
            $infMunCarrega,
425
            "cMunCarrega",
426
            $std->cMunCarrega,
427
            true,
428
            "Código do Município de Carregamento"
429
        );
430
        $this->dom->addChild(
431
            $infMunCarrega,
432
            "xMunCarrega",
433
            $std->xMunCarrega,
434
            true,
435
            "Nome do Município de Carregamento"
436
        );
437
        $this->aInfMunCarrega[] = $infMunCarrega;
0 ignored issues
show
Bug introduced by
The property aInfMunCarrega 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...
438
        return $infMunCarrega;
439
    }
440
441
    /**
442
     * tagInfPercurso
443
     *
444
     * tag MDFe/infMDFe/ide/infPercurso
445
     *
446
     * @param  array ufPer Sigla das Unidades da Federação do percurso do veículo
447
     *
448
     * @return DOMElement
449
     */
450 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...
451
    {
452
        $possible = [
453
            'UFPer'
454
        ];
455
456
        $std = $this->equilizeParameters($std, $possible);
457
        foreach ($std->UFPer as $nItem => $UFPer) {
458
            $infPercurso = $this->dom->createElement("infPercurso");
459
            $this->dom->addChild(
460
                $infPercurso,
461
                "UFPer",
462
                $UFPer,
463
                true,
464
                "Sigla das Unidades da Federação do percurso"
465
            );
466
            $this->aInfPercurso[] = $infPercurso;
467
        }
468
        return $this->aInfPercurso;
469
    }
470
471
    /**
472
     * tagemit
473
     * Identificação do emitente da MDFe
474
     * tag MDFe/infMDFe/emit
475
     *
476
     * @param  int CNPJ CNPJ do emitente
477
     * @param  int IE Inscrição Estadual do emitente
478
     * @param  string xNome Razão social
479
     * @param  string xFant Nome fantasia
480
     *
481
     * @return DOMElement
482
     */
483
    public function tagemit(stdClass $std)
484
    {
485
        $possible = [
486
            'CNPJ',
487
            'IE',
488
            'xNome',
489
            'xFant'
490
        ];
491
        $std = $this->equilizeParameters($std, $possible);
492
        
493
        $identificador = '[25] <emit> - ';
494
        $this->emit = $this->dom->createElement("emit");
495
        $this->dom->addChild(
496
            $this->emit,
497
            "CNPJ",
498
            $std->CNPJ,
499
            true,
500
            $identificador . "CNPJ do emitente"
501
        );
502
        $this->dom->addChild(
503
            $this->emit,
504
            "IE",
505
            $std->IE,
506
            true,
507
            $identificador . "Inscrição Estadual do emitente"
508
        );
509
        $this->dom->addChild(
510
            $this->emit,
511
            "xNome",
512
            $std->xNome,
513
            true,
514
            $identificador . "Razão Social ou Nome do emitente"
515
        );
516
        $this->dom->addChild(
517
            $this->emit,
518
            "xFant",
519
            $std->xFant,
520
            false,
521
            $identificador . "Nome fantasia do emitente"
522
        );
523
        return $this->emit;
524
    }
525
526
    /**
527
     * tagenderEmit
528
     * Endereço do emitente [30] pai [25]
529
     * tag MDFe/infMDFe/emit/endEmit
530
     *
531
     * @param  string xLgr Logradouro
532
     * @param  string nro Número
533
     * @param  string xCpl Complemento
534
     * @param  string xBairro Bairro
535
     * @param  int cMun Código do município
536
     * @param  string xMun Nome do município
537
     * @param  int CEP CEP
538
     * @param  string UF Sigla da UF
539
     * @param  int fone Telefone
540
     * @param  string email Endereço de E-mail
541
     *
542
     * @return DOMElement
543
     */
544
    public function tagenderEmit(stdClass $std)
545
    {
546
        $possible = [
547
            'xLgr',
548
            'nro',
549
            'xCpl',
550
            'xBairro',
551
            'cMun',
552
            'xMun',
553
            'CEP',
554
            'UF',
555
            'fone',
556
            'email'
557
        ];
558
        $std = $this->equilizeParameters($std, $possible);
559
560
        $identificador = '[30] <enderEmit> - ';
561
        $this->enderEmit = $this->dom->createElement("enderEmit");
562
        
563
        $this->dom->addChild(
564
            $this->enderEmit,
565
            "xLgr",
566
            $std->xLgr,
567
            true,
568
            $identificador . "Logradouro do Endereço do emitente"
569
        );
570
        $this->dom->addChild(
571
            $this->enderEmit,
572
            "nro",
573
            $std->nro,
574
            true,
575
            $identificador . "Número do Endereço do emitente"
576
        );
577
        $this->dom->addChild(
578
            $this->enderEmit,
579
            "xCpl",
580
            $std->xCpl,
581
            false,
582
            $identificador . "Complemento do Endereço do emitente"
583
        );
584
        $this->dom->addChild(
585
            $this->enderEmit,
586
            "xBairro",
587
            $std->xBairro,
588
            true,
589
            $identificador . "Bairro do Endereço do emitente"
590
        );
591
        $this->dom->addChild(
592
            $this->enderEmit,
593
            "cMun",
594
            $std->cMun,
595
            true,
596
            $identificador . "Código do município do Endereço do emitente"
597
        );
598
        $this->dom->addChild(
599
            $this->enderEmit,
600
            "xMun",
601
            $std->xMun,
602
            true,
603
            $identificador . "Nome do município do Endereço do emitente"
604
        );
605
        $this->dom->addChild(
606
            $this->enderEmit,
607
            "CEP",
608
            $std->CEP,
609
            true,
610
            $identificador . "Código do CEP do Endereço do emitente"
611
        );
612
        $this->dom->addChild(
613
            $this->enderEmit,
614
            "UF",
615
            $std->UF,
616
            true,
617
            $identificador . "Sigla da UF do Endereço do emitente"
618
        );
619
        $this->dom->addChild(
620
            $this->enderEmit,
621
            "fone",
622
            $std->fone,
623
            false,
624
            $identificador . "Número de telefone do emitente"
625
        );
626
        $this->dom->addChild(
627
            $this->enderEmit,
628
            "email",
629
            $std->email,
630
            false,
631
            $identificador . "Endereço de email do emitente"
632
        );
633
        return $this->enderEmit;
634
    }
635
636
    /**
637
     * tagInfMunDescarga
638
     * tag MDFe/infMDFe/infDoc/infMunDescarga
639
     *
640
     * @param  int  cMunDescarga Código do Município
641
     * @param  string  xMunDescarga Nome do Município
642
     *
643
     * @return DOMElement
644
     */
645
    public function taginfMunDescarga(stdClass $std)
646
    {
647
        $possible = [
648
            'cMunDescarga',
649
            'xMunDescarga'
650
        ];
651
        $std = $this->equilizeParameters($std, $possible);
652
653
        if (empty($this->infDoc)) {
654
            $infDoc = $this->dom->createElement("infDoc");
655
        } else {
656
            $infDoc = $this->infDoc;
657
        }
658
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
659
        $this->dom->addChild(
660
            $infMunDescarga,
661
            "cMunDescarga",
662
            $std->cMunDescarga,
663
            true,
664
            "Código do Município de Descarga"
665
        );
666
        $this->dom->addChild(
667
            $infMunDescarga,
668
            "xMunDescarga",
669
            $std->xMunDescarga,
670
            true,
671
            "Nome do Município de Descarga"
672
        );
673
        $this->dom->appChild($infDoc, $infMunDescarga, 'Falta tag "infMunDescarga"');
674
        $this->infDoc = $infDoc;
675
        $this->aInfMunDescarga = $infMunDescarga;
0 ignored issues
show
Bug introduced by
The property aInfMunDescarga 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...
676
        return $infMunDescarga;
677
    }
678
679
    /**
680
     * taginfANTT
681
     * tag MDFe/infMDFe/rodo/taginfANTT
682
     *
683
     * @param  int RNTRC Registro Nacional de Transportadores
684
     * @param  stdClass  infCIOT Dados do CIOT
685
     * @param  stdClass  valePed Informações de Vale Pedágio
686
     * @param  stdClass  infContratante informações dos contratantes
687
     *
688
     * @return DOMElement
689
     */
690
    public function taginfANTT(stdClass $std)
691
    {
692
        $possible = [
693
            'RNTRC',
694
            'infCIOT',
695
            'valePed',
696
            'infContratante'
697
        ];
698
        $std = $this->equilizeParameters($std, $possible);
699
        $rodo = $this->dom->createElement("rodo");
700
        $infANTT = $this->dom->createElement("infANTT");
701
        $this->dom->addChild(
702
            $infANTT,
703
            "RNTRC",
704
            $std->RNTRC,
705
            false,
706
            "RNTRC"
707
        );
708
709
        if ($std->infCIOT != null) {
710
            $possible = [
711
                'CIOT',
712
                'CPF',
713
                'CNPJ'
714
            ];
715
            foreach ($std->infCIOT as $nItem => $infCIOT) {
716
                $stdinfCIOT = $this->equilizeParameters($infCIOT, $possible);
717
                $infCIOT = $this->dom->createElement("infCIOT");
718
                $this->dom->addChild(
719
                    $infCIOT,
720
                    "CIOT",
721
                    $stdinfCIOT->CIOT,
722
                    true,
723
                    "CIOT"
724
                );
725
                
726
                $this->dom->addChild(
727
                    $infCIOT,
728
                    "CPF",
729
                    $stdinfCIOT->CPF,
730
                    false,
731
                    "CPF"
732
                );
733
                $this->dom->addChild(
734
                    $infCIOT,
735
                    "CNPJ",
736
                    $stdinfCIOT->CNPJ,
737
                    false,
738
                    "CNPJ"
739
                );
740
                $this->dom->appChild($infANTT, $infCIOT, 'Falta tag "infCIOT"');
741
            }
742
        }
743
        if ($std->valePed != null) {
744
            $possible = [
745
                'CNPJForn',
746
                'CNPJPg',
747
                'CPFPg',
748
                'nCompra',
749
                'vValePed'
750
            ];
751
            foreach ($std->valePed as $nItem => $valePed) {
752
                $stdvalePed = $this->equilizeParameters($valePed, $possible);
753
                $valePed = $this->dom->createElement("valePed");
754
                $disp = $this->dom->createElement("disp");
755
                $this->dom->addChild(
756
                    $disp,
757
                    "CNPJForn",
758
                    $stdvalePed->CNPJForn,
759
                    false,
760
                    "CNPJForn"
761
                );
762
                $this->dom->addChild(
763
                    $disp,
764
                    "CNPJPg",
765
                    $stdvalePed->CNPJPg,
766
                    false,
767
                    "CNPJPg"
768
                );
769
                $this->dom->addChild(
770
                    $disp,
771
                    "CPFPg",
772
                    $stdvalePed->CPFPg,
773
                    false,
774
                    "CPFPg"
775
                );
776
                $this->dom->addChild(
777
                    $disp,
778
                    "nCompra",
779
                    $stdvalePed->nCompra,
780
                    false,
781
                    "nCompra"
782
                );
783
                $this->dom->addChild(
784
                    $disp,
785
                    "vValePed",
786
                    $stdvalePed->vValePed,
787
                    false,
788
                    "vValePed"
789
                );
790
                $this->dom->appChild($valePed, $disp, 'Falta tag "disp"');
791
                $this->dom->appChild($infANTT, $valePed, 'Falta tag "valePed"');
792
            }
793
        }
794
        if ($std->infContratante != null) {
795
            $possible = [
796
                'CPF',
797
                'CNPJ'
798
            ];
799
            foreach ($std->infContratante as $nItem => $infContratante) {
800
                $stdinfContratante = $this->equilizeParameters($infContratante, $possible);
801
                $infContratante = $this->dom->createElement("infContratante");
802
                $this->dom->addChild(
803
                    $infContratante,
804
                    "CPF",
805
                    $stdinfContratante->CPF,
806
                    false,
807
                    "CPF"
808
                );
809
                $this->dom->addChild(
810
                    $infContratante,
811
                    "CNPJ",
812
                    $stdinfContratante->CNPJ,
813
                    false,
814
                    "CNPJ"
815
                );
816
                $this->dom->appChild($infANTT, $infContratante, 'Falta tag "infContratante"');
817
            }
818
        }
819
        
820
        $this->dom->appChild($rodo, $infANTT, 'Falta tag "infANTT"');
821
        $this->rodo = $rodo;
822
        return $this->rodo;
823
    }
824
    
825
    /**
826
     * taginfCTe
827
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
828
     *
829
     * @param  int chCTe Chave de acesso
830
     * @param  int SegCodBarra Segundo código de barras
831
     * @param  int indReentrega Indicador de Reentrega
832
     * @param  stdClass infUnidTransp Informações das Unidades de Transporte
833
     * @param  stdClass peri Produtos classificados pela ONU como perigosos
834
     * @param  stdClass infEntregaParcial Entrega Parcial
835
     *
836
     * @return DOMElement
837
     */
838
    public function taginfCTe(stdClass $std)
839
    {
840
        $possible = [
841
            'chCTe',
842
            'SegCodBarra',
843
            'indReentrega',
844
            'infUnidTransp',
845
            'peri',
846
            'infEntregaParcial'
847
        ];
848
        $std = $this->equilizeParameters($std, $possible);
849
        $infCTe = $this->dom->createElement("infCTe");
850
        $this->dom->addChild(
851
            $infCTe,
852
            "chCTe",
853
            $std->chCTe,
854
            true,
855
            "Chave de Acesso CTe"
856
        );
857
        $this->dom->addChild(
858
            $infCTe,
859
            "SegCodBarra",
860
            $std->SegCodBarra,
861
            false,
862
            "Segundo código de barras do CTe"
863
        );
864
        $this->dom->addChild(
865
            $infCTe,
866
            "indReentrega",
867
            $std->indReentrega,
868
            false,
869
            "Indicador de Reentrega"
870
        );
871 View Code Duplication
        if ($std->infUnidTransp != 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...
872
            $infUnidTransp = $this->taginfUnidTransp($std->infUnidTransp);
873
            $this->dom->appChild($infCTe, $infUnidTransp, 'Falta tag "infUnidTransp"');
874
        }
875
        if ($std->peri != null) {
876
            $peri = $this->tagperi($std->peri);
877
            $this->dom->appChild($infCTe, $peri, 'Falta tag "$peri"');
878
        }
879 View Code Duplication
        if ($std->infEntregaParcial != 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...
880
            $possible = [
881
                'qtdTotal',
882
                'qtdParcial'
883
            ];
884
            $stdinfEntregaParcial = $this->equilizeParameters($std->infEntregaParcial, $possible);
885
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
886
            $this->dom->addChild(
887
                $infEntregaParcial,
888
                "qtdTotal",
889
                $stdinfEntregaParcial->qtdTotal,
890
                true,
891
                "Quantidade total de volumes"
892
            );
893
            $this->dom->addChild(
894
                $infEntregaParcial,
895
                "qtdParcial",
896
                $stdinfEntregaParcial->qtdParcial,
897
                true,
898
                "Quantidade de volumes enviados no MDF-e"
899
            );
900
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infEntregaParcial"');
901
        }
902
        $this->dom->appChild($this->aInfMunDescarga, $infCTe, 'Falta tag "infCTe"');
903
        return $infCTe;
904
    }
905
906
    /**
907
     * tagperi
908
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
909
     *
910
     * @param  string nONU Número ONU/UN
911
     * @param  string xNomeAE Nome apropriado para embarque
912
     * @param  string xClaRisco Classe ou subclasse/divisão
913
     * @param  string grEmb Grupo de Embalagem
914
     * @param  string qTotProd Quantidade total por produto
915
     * @param  string qVolTipo Quantidade e Tipo de volumes
916
     *
917
     * @return DOMElement
918
     */
919 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...
920
    {
921
        $possible = [
922
            'nONU',
923
            'xNomeAE',
924
            'xClaRisco',
925
            'grEmb',
926
            'qTotProd',
927
            'qVolTipo'
928
        ];
929
        $std = $this->equilizeParameters($std, $possible);
930
        $peri = $this->dom->createElement("peri");
931
        $this->dom->addChild(
932
            $peri,
933
            "nONU",
934
            $std->nONU,
935
            true,
936
            "Número ONU/UN"
937
        );
938
        $this->dom->addChild(
939
            $peri,
940
            "xNomeAE",
941
            $std->xNomeAE,
942
            true,
943
            "Nome apropriado para embarque do produto"
944
        );
945
        $this->dom->addChild(
946
            $peri,
947
            "xClaRisco",
948
            $std->xClaRisco,
949
            true,
950
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
951
        );
952
        $this->dom->addChild(
953
            $peri,
954
            "grEmb",
955
            $std->grEmb,
956
            true,
957
            "Grupo de Embalagem"
958
        );
959
        $this->dom->addChild(
960
            $peri,
961
            "qTotProd",
962
            $std->qTotProd,
963
            true,
964
            "Quantidade total por produto"
965
        );
966
        $this->dom->addChild(
967
            $peri,
968
            "qVolTipo",
969
            $std->qVolTipo,
970
            true,
971
            "Quantidade e Tipo de volumes"
972
        );
973
        return $peri;
974
    }
975
    
976
    /**
977
     * taginfNFe
978
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
979
     *
980
     * @param  int chNFe Chave de acesso
981
     * @param  int SegCodBarra Segundo código de barras
982
     * @param  int indReentrega Indicador de Reentrega
983
     * @param  stdClass infUnidTransp Informações das Unidades de Transporte
984
     * @param  stdClass peri Produtos classificados pela ONU como perigosos
985
     *
986
     * @return DOMElement
987
     */
988
    public function taginfNFe(stdClass $std)
989
    {
990
        $possible = [
991
            'chNFe',
992
            'SegCodBarra',
993
            'indReentrega',
994
            'infUnidTransp',
995
            'peri'
996
        ];
997
        $std = $this->equilizeParameters($std, $possible);
998
        $infNFe = $this->dom->createElement("infNFe");
999
        $this->dom->addChild(
1000
            $infNFe,
1001
            "chNFe",
1002
            $std->chNFe,
1003
            true,
1004
            "Chave de Acesso NFe"
1005
        );
1006
        $this->dom->addChild(
1007
            $infNFe,
1008
            "SegCodBarra",
1009
            $std->SegCodBarra,
1010
            false,
1011
            "Segundo código de barras do NFe"
1012
        );
1013
        $this->dom->addChild(
1014
            $infNFe,
1015
            "indReentrega",
1016
            $std->indReentrega,
1017
            false,
1018
            "Indicador de Reentrega"
1019
        );
1020 View Code Duplication
        if ($std->infUnidTransp != 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...
1021
            $infUnidTransp = $this->taginfUnidTransp($std->infUnidTransp);
1022
            $this->dom->appChild($infNFe, $infUnidTransp, 'Falta tag "infUnidTransp"');
1023
        }
1024
        if ($std->peri != null) {
1025
            $peri = $this->tagperi($std->peri);
1026
            $this->dom->appChild($infNFe, $peri, 'Falta tag "peri"');
1027
        }
1028
        $this->dom->appChild($this->aInfMunDescarga, $infNFe, 'Falta tag "infNFe"');
1029
        return $infNFe;
1030
    }
1031
1032
    /**
1033
     * taginfMDFeTransp
1034
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1035
     *
1036
     * @param  int chMDFe Chave de acesso
1037
     * @param  int indReentrega Indicador de Reentrega
1038
     * @param  stdClass infUnidTransp Informações das Unidades de Transporte
1039
     * @param  stdClass peri Produtos classificados pela ONU como perigosos
1040
     *
1041
     * @return DOMElement
1042
     */
1043
    public function taginfMDFeTransp(stdClass $std)
1044
    {
1045
        $possible = [
1046
            'chNFe',
1047
            'indReentrega',
1048
            'infUnidTransp',
1049
            'peri'
1050
        ];
1051
        $std = $this->equilizeParameters($std, $possible);
1052
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1053
        $this->dom->addChild(
1054
            $infMDFeTransp,
1055
            "chNFe",
1056
            $std->chNFe,
1057
            true,
1058
            "Chave de Acesso NFe"
1059
        );
1060
        $this->dom->addChild(
1061
            $infMDFeTransp,
1062
            "indReentrega",
1063
            $std->indReentrega,
1064
            false,
1065
            "Indicador de Reentrega"
1066
        );
1067 View Code Duplication
        if ($std->infUnidTransp != 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...
1068
            $infUnidTransp = $this->taginfUnidTransp($std->infUnidTransp);
1069
            $this->dom->appChild($infMDFeTransp, $infUnidTransp, 'Falta tag "infUnidTransp"');
1070
        }
1071
        if ($std->peri != null) {
1072
            $peri = $this->tagperi($std->peri);
1073
            $this->dom->appChild($infMDFeTransp, $peri, 'Falta tag "peri"');
1074
        }
1075
        $this->dom->appChild($this->aInfMunDescarga, $infMDFeTransp, 'Falta tag "infMDFeTransp"');
1076
        return $infMDFeTransp;
1077
    }
1078
1079
    /**
1080
     * taginfUnidTransp
1081
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1082
     *
1083
     * @param  int tpUnidTrans Tipo da Unidade de Transporte
1084
     * @param  string idUnidTrans Identificação da Unidade de Transporte
1085
     * @param  int qtdRat Quantidade rateada
1086
     * @param  stdClass lacUnidTransp Lacres das Unidades de Transporte
1087
     * @param  stdClass infUnidCarga Informações das Unidades de Carga
1088
     *
1089
     * @return DOMElement
1090
     */
1091
    public function taginfUnidTransp(stdClass $std)
1092
    {
1093
        $possible = [
1094
            'tpUnidTrans',
1095
            'idUnidTrans',
1096
            'qtdRat',
1097
            'lacUnidTransp',
1098
            'infUnidCarga'
1099
        ];
1100
        $std = $this->equilizeParameters($std, $possible);
1101
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1102
        $this->dom->addChild(
1103
            $infUnidTransp,
1104
            "tpUnidTrans",
1105
            $std->tpUnidTrans,
1106
            true,
1107
            "Tipo da Unidade de Transporte"
1108
        );
1109
        $this->dom->addChild(
1110
            $infUnidTransp,
1111
            "idUnidTrans",
1112
            $std->idUnidTrans,
1113
            false,
1114
            "Identificação da Unidade de Transporte"
1115
        );
1116 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...
1117
            $possible = [
1118
                'nLacre'
1119
            ];
1120
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1121
            foreach ($stdlacUnidTransp->nLacre as $nItem => $nLacre) {
1122
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1123
                $this->dom->addChild(
1124
                    $lacUnidTransp,
1125
                    "nLacre",
1126
                    $nLacre,
1127
                    true,
1128
                    "Número do lacre"
1129
                );
1130
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "lacUnidTransp"');
1131
            }
1132
        }
1133
        if ($std->infUnidCarga != null) {
1134
            $infUnidCarga = $this->taginfUnidCarga($std->infUnidCarga);
1135
            $this->dom->appChild($infUnidTransp, $infUnidCarga, 'Falta tag "infUnidCarga"');
1136
        }
1137
        $this->dom->addChild(
1138
            $infUnidTransp,
1139
            "qtdRat",
1140
            $std->qtdRat,
1141
            false,
1142
            "Quantidade rateada (Peso,Volume) "
1143
        );
1144
        return $infUnidTransp;
1145
    }
1146
1147
    /**
1148
     * taginfUnidCarga
1149
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1150
     *
1151
     * @param  int tpUnidCarga Tipo da Unidade de Carga
1152
     * @param  string idUnidCarga Identificação da Unidade de Carga
1153
     * @param  stdClass lacUnidCarga Lacres das Unidades de Carga
1154
     * @param  int qtdRat Quantidade rateada
1155
     *
1156
     * @return DOMElement
1157
     */
1158
    public function taginfUnidCarga(stdClass $std)
1159
    {
1160
        $possible = [
1161
            'tpUnidCarga',
1162
            'idUnidCarga',
1163
            'lacUnidCarga',
1164
            'qtdRat'
1165
        ];
1166
        $std = $this->equilizeParameters($std, $possible);
1167
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1168
        $this->dom->addChild(
1169
            $infUnidCarga,
1170
            "tpUnidCarga",
1171
            $std->tpUnidCarga,
1172
            false,
1173
            "Tipo da Unidade de Carga"
1174
        );
1175
        $this->dom->addChild(
1176
            $infUnidCarga,
1177
            "idUnidCarga",
1178
            $std->idUnidCarga,
1179
            false,
1180
            "Identificação da Unidade de Carga "
1181
        );
1182 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...
1183
            $possible = [
1184
                'nLacre'
1185
            ];
1186
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1187
            foreach ($stdlacUnidCarga->nLacre as $nItem => $nLacre) {
1188
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1189
                $this->dom->addChild(
1190
                    $lacUnidCarga,
1191
                    "nLacre",
1192
                    $nLacre,
1193
                    true,
1194
                    "Número do lacre"
1195
                );
1196
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "lacUnidCarga"');
1197
            }
1198
        }
1199
        $this->dom->addChild(
1200
            $infUnidCarga,
1201
            "qtdRat",
1202
            $std->qtdRat,
1203
            false,
1204
            "Quantidade rateada (Peso,Volume) "
1205
        );
1206
        
1207
        return $infUnidCarga ;
1208
    }
1209
    
1210
    /**
1211
     * tagseg
1212
     * tag MDFe/infMDFe/seg
1213
     *
1214
     * @param  int respSeg Responsável pelo seguro
1215
     * @param  int CNPJ Número do CNPJ
1216
     * @param  int CPF Número do CPF
1217
     * @param  stdClass infSeg Informações da seguradora
1218
     * @param  string nApol Número da Apólice
1219
     * @param  string nAver Número da Averbação
1220
     *
1221
     * @return DOMElement
1222
     */
1223
    public function tagseg(stdClass $std)
1224
    {
1225
        $possible = [
1226
            'respSeg',
1227
            'CNPJ',
1228
            'CPF',
1229
            'infSeg',
1230
            'nApol',
1231
            'nAver'
1232
        ];
1233
        $std = $this->equilizeParameters($std, $possible);
1234
        $seg = $this->dom->createElement("seg");
1235
        $infResp = $this->dom->createElement("infResp");
1236
        $this->dom->addChild(
1237
            $infResp,
1238
            "respSeg",
1239
            $std->respSeg,
1240
            true,
1241
            "Responsável pelo seguro"
1242
        );
1243
        $this->dom->addChild(
1244
            $infResp,
1245
            "CNPJ",
1246
            $std->CNPJ,
1247
            false,
1248
            "Número do CNPJ do responsável pelo seguro"
1249
        );
1250
        $this->dom->addChild(
1251
            $infResp,
1252
            "CPF",
1253
            $std->CPF,
1254
            false,
1255
            "Número do CPF do responsável pelo seguro"
1256
        );
1257
        $this->dom->appChild($seg, $infResp, 'Falta tag "infResp"');
1258 View Code Duplication
        if ($std->infSeg != 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...
1259
            $possible = [
1260
                'xSeg',
1261
                'CNPJ'
1262
            ];
1263
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1264
            $infSeg = $this->dom->createElement("infSeg");
1265
            $this->dom->addChild(
1266
                $infSeg,
1267
                "xSeg",
1268
                $stdinfSeg->xSeg,
1269
                true,
1270
                "Nome da Seguradora"
1271
            );
1272
            $this->dom->addChild(
1273
                $infSeg,
1274
                "CNPJ",
1275
                $stdinfSeg->CNPJ,
1276
                false,
1277
                "Número do CNPJ da seguradora"
1278
            );
1279
            $this->dom->appChild($seg, $infSeg, 'Falta tag "infSeg"');
1280
        }
1281
        $this->dom->addChild(
1282
            $seg,
1283
            "nApol",
1284
            $std->nApol,
1285
            false,
1286
            "Número da Apólice"
1287
        );
1288
        if ($std->nAver != null) {
1289
            foreach ($std->nAver as $nItem => $nAver) {
1290
                $this->dom->addChild(
1291
                    $seg,
1292
                    "nAver",
1293
                    $nAver,
1294
                    true,
1295
                    "Número da Averbação"
1296
                );
1297
            }
1298
        }
1299
        $this->seg = $seg;
1300
        return $seg;
1301
    }
1302
1303
    /**
1304
     * tagTot
1305
     * tag MDFe/infMDFe/tot
1306
     *
1307
     * @param  int qCTe Quantidade total de CT-e
1308
     * @param  int qNFe Quantidade total de NF-e
1309
     * @param  int qMDFe Quantidade total de MDF-e
1310
     * @param  int vCarga Valor total da carga
1311
     * @param  int cUnid Código da unidade de medida
1312
     * @param  int qCarga Peso Bruto Total da Carga
1313
     *
1314
     * @return DOMElement
1315
     */
1316 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...
1317
    {
1318
        $possible = [
1319
            'qCTe',
1320
            'qNFe',
1321
            'qMDFe',
1322
            'vCarga',
1323
            'cUnid',
1324
            'qCarga'
1325
        ];
1326
        $std = $this->equilizeParameters($std, $possible);
1327
        $tot = $this->dom->createElement("tot");
1328
        $this->dom->addChild(
1329
            $tot,
1330
            "qCTe",
1331
            $std->qCTe,
1332
            false,
1333
            "Quantidade total de CT-e relacionados no Manifesto"
1334
        );
1335
        $this->dom->addChild(
1336
            $tot,
1337
            "qNFe",
1338
            $std->qNFe,
1339
            false,
1340
            "Quantidade total de NF-e relacionados no Manifesto"
1341
        );
1342
        $this->dom->addChild(
1343
            $tot,
1344
            "qMDFe",
1345
            $std->qMDFe,
1346
            false,
1347
            "Quantidade total de MDF-e relacionados no Manifesto"
1348
        );
1349
        $this->dom->addChild(
1350
            $tot,
1351
            "vCarga",
1352
            $std->vCarga,
1353
            true,
1354
            "Valor total da mercadoria/carga transportada"
1355
        );
1356
        $this->dom->addChild(
1357
            $tot,
1358
            "cUnid",
1359
            $std->cUnid,
1360
            true,
1361
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1362
        );
1363
        $this->dom->addChild(
1364
            $tot,
1365
            "qCarga",
1366
            $std->qCarga,
1367
            true,
1368
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1369
        );
1370
        $this->tot = $tot;
1371
        return $tot;
1372
    }
1373
1374
    /**
1375
     * tagLacres
1376
     * tag MDFe/infMDFe/lacres
1377
     *
1378
     * @param  int nLacre número do lacre
1379
     *
1380
     * @return DOMElement
1381
     */
1382 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...
1383
    {
1384
        $possible = [
1385
            'nLacre'
1386
        ];
1387
        $std = $this->equilizeParameters($std, $possible);
1388
        if ($std->nLacre != null) {
1389
            foreach ($std->nLacre as $nItem => $nLacre) {
1390
                $lacres = $this->dom->createElement("lacres");
1391
                $this->dom->addChild(
1392
                    $lacres,
1393
                    "nLacre",
1394
                    $nLacre,
1395
                    false,
1396
                    "Número do lacre"
1397
                );
1398
                $this->lacres[] = $lacres; //array de DOMNode
1399
            }
1400
        }
1401
        return $this->lacres;
1402
    }
1403
1404
    /**
1405
     * taginfAdic
1406
     * Grupo de Informações Adicionais Z01 pai A01
1407
     * tag MDFe/infMDFe/infAdic (opcional)
1408
     *
1409
     * @param  string infAdFisco Informações adicionais
1410
     * @param  string infCpl Informações complementares
1411
     *
1412
     * @return DOMElement
1413
     */
1414 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...
1415
    {
1416
        $possible = [
1417
            'infAdFisco',
1418
            'infCpl'
1419
        ];
1420
        $std = $this->equilizeParameters($std, $possible);
1421
        $infAdic = $this->dom->createElement("infAdic");
1422
        $this->dom->addChild(
1423
            $infAdic,
1424
            "infAdFisco",
1425
            $std->infAdFisco,
1426
            false,
1427
            "Informações Adicionais de Interesse do Fisco"
1428
        );
1429
        $this->dom->addChild(
1430
            $infAdic,
1431
            "infCpl",
1432
            $std->infCpl,
1433
            false,
1434
            "Informações Complementares de interesse do Contribuinte"
1435
        );
1436
        $this->infAdic = $infAdic;
1437
        return $infAdic;
1438
    }
1439
1440
    /**
1441
     * tagautXML
1442
     * tag MDFe/infMDFe/autXML
1443
     *
1444
     * Autorizados para download do XML do MDF-e
1445
     *
1446
     * @param int CNPJ CNPJ do autorizado
1447
     * @param int CPF CPF do autorizado
1448
     *
1449
     * @return DOMElement
1450
     */
1451 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...
1452
    {
1453
        $possible = [
1454
            'CNPJ',
1455
            'CPF'
1456
        ];
1457
        $std = $this->equilizeParameters($std, $possible);
1458
        $autXML = $this->dom->createElement("autXML");
1459
        $this->dom->addChild(
1460
            $autXML,
1461
            "CNPJ",
1462
            $std->CNPJ,
1463
            false,
1464
            "CNPJ do autorizado"
1465
        );
1466
        $this->dom->addChild(
1467
            $autXML,
1468
            "CPF",
1469
            $std->CPF,
1470
            false,
1471
            "CPF do autorizado"
1472
        );
1473
        $this->autXML[] = $autXML;
1474
        return $this->autXML;
1475
    }
1476
1477
    /**
1478
     * buildInfModal
1479
     * tag MDFe/infMDFe/infModal
1480
     *
1481
     * @return DOMElement
1482
     */
1483
    public function buildInfModal()
1484
    {
1485
        $infModal = $this->dom->createElement("infModal");
1486
        $infModal->setAttribute("versaoModal", $this->versao);
1487
        $this->infModal = $infModal;
1488
        return $infModal;
1489
    }
1490
1491
    /**
1492
     * tagAereo
1493
     * tag MDFe/infMDFe/infModal/aereo
1494
     *
1495
     * @param  string $nac
1496
     * @param  string $matr
1497
     * @param  string $nVoo
1498
     * @param  string $cAerEmb
1499
     * @param  string $cAerDes
1500
     * @param  string $dVoo
1501
     *
1502
     * @return DOMElement
1503
     */
1504
   
1505
    public function tagAereo(
1506
        $nac = '',
1507
        $matr = '',
1508
        $nVoo = '',
1509
        $cAerEmb = '',
1510
        $cAerDes = '',
1511
        $dVoo = ''
1512
    ) {
1513
        $aereo = $this->dom->createElement("aereo");
1514
        $this->dom->addChild(
1515
            $aereo,
1516
            "nac",
1517
            $nac,
1518
            true,
1519
            "Marca da Nacionalidade da aeronave"
1520
        );
1521
        $this->dom->addChild(
1522
            $aereo,
1523
            "matr",
1524
            $matr,
1525
            true,
1526
            "Marca de Matrícula da aeronave"
1527
        );
1528
        $this->dom->addChild(
1529
            $aereo,
1530
            "nVoo",
1531
            $nVoo,
1532
            true,
1533
            "Número do Vôo"
1534
        );
1535
        $this->dom->addChild(
1536
            $aereo,
1537
            "cAerEmb",
1538
            $cAerEmb,
1539
            true,
1540
            "Aeródromo de Embarque - Código IATA"
1541
        );
1542
        $this->dom->addChild(
1543
            $aereo,
1544
            "cAerDes",
1545
            $cAerDes,
1546
            true,
1547
            "Aeródromo de Destino - Código IATA"
1548
        );
1549
        $this->dom->addChild(
1550
            $aereo,
1551
            "dVoo",
1552
            $dVoo,
1553
            true,
1554
            "Data do Vôo"
1555
        );
1556
        $this->aereo = $aereo;
1557
        return $aereo;
1558
    }
1559
    
1560
    /**
1561
     * tagTrem
1562
     * tag MDFe/infMDFe/infModal/ferrov/trem
1563
     *
1564
     * @param  string $xPref
1565
     * @param  string $dhTrem
1566
     * @param  string $xOri
1567
     * @param  string $xDest
1568
     * @param  string $qVag
1569
     *
1570
     * @return DOMElement
1571
     */
1572
    
1573
    public function tagTrem(
1574
        $xPref = '',
1575
        $dhTrem = '',
1576
        $xOri = '',
1577
        $xDest = '',
1578
        $qVag = ''
1579
    ) {
1580
        $trem = $this->dom->createElement("trem");
1581
        $this->dom->addChild(
1582
            $trem,
1583
            "xPref",
1584
            $xPref,
1585
            true,
1586
            "Prefixo do Trem"
1587
        );
1588
        $this->dom->addChild(
1589
            $trem,
1590
            "dhTrem",
1591
            $dhTrem,
1592
            false,
1593
            "Data e hora de liberação do trem na origem"
1594
        );
1595
        $this->dom->addChild(
1596
            $trem,
1597
            "xOri",
1598
            $xOri,
1599
            true,
1600
            "Origem do Trem"
1601
        );
1602
        $this->dom->addChild(
1603
            $trem,
1604
            "xDest",
1605
            $xDest,
1606
            true,
1607
            "Destino do Trem"
1608
        );
1609
        $this->dom->addChild(
1610
            $trem,
1611
            "qVag",
1612
            $qVag,
1613
            true,
1614
            "Quantidade de vagões"
1615
        );
1616
        $this->trem = $trem;
1617
        return $trem;
1618
    }
1619
    
1620
    /**
1621
     * tagVag
1622
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
1623
     *
1624
     * @param  string $serie
1625
     * @param  string $nVag
1626
     * @param  string $nSeq
1627
     * @param  string $tonUtil
1628
     *
1629
     * @return DOMElement
1630
     */
1631
    
1632
    public function tagVag(
1633
        $serie = '',
1634
        $nVag = '',
1635
        $nSeq = '',
1636
        $tonUtil = ''
1637
    ) {
1638
        $vag = $this->dom->createElement("vag");
1639
        $this->dom->addChild(
1640
            $vag,
1641
            "serie",
1642
            $serie,
1643
            true,
1644
            "Série de Identificação do vagão"
1645
        );
1646
        $this->dom->addChild(
1647
            $vag,
1648
            "nVag",
1649
            $nVag,
1650
            true,
1651
            "Número de Identificação do vagão"
1652
        );
1653
        $this->dom->addChild(
1654
            $vag,
1655
            "nSeq",
1656
            $nSeq,
1657
            false,
1658
            "Sequência do vagão na composição"
1659
        );
1660
        $this->dom->addChild(
1661
            $vag,
1662
            "TU",
1663
            $tonUtil,
1664
            true,
1665
            "Tonelada Útil"
1666
        );
1667
        $this->aVag[] = $vag;
0 ignored issues
show
Bug introduced by
The property aVag 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...
1668
        return $vag;
1669
    }
1670
    
1671
    /**
1672
     * tagAqua
1673
     * tag MDFe/infMDFe/infModal/Aqua
1674
     *
1675
     * @param  string $cnpjAgeNav
1676
     * @param  string $tpEmb
1677
     * @param  string $cEmbar
1678
     * @param  string $nViagem
1679
     * @param  string $cPrtEmb
1680
     * @param  string $cPrtDest
1681
     *
1682
     * @return DOMElement
1683
     */
1684
    
1685
    public function tagAqua(
1686
        $cnpjAgeNav = '',
1687
        $tpEmb = '',
1688
        $cEmbar = '',
1689
        $nViagem = '',
1690
        $cPrtEmb = '',
1691
        $cPrtDest = ''
1692
    ) {
1693
        $aqua = $this->dom->createElement("Aqua");
1694
        $this->dom->addChild(
1695
            $aqua,
1696
            "CNPJAgeNav",
1697
            $cnpjAgeNav,
1698
            true,
1699
            "CNPJ da Agência de Navegação"
1700
        );
1701
        $this->dom->addChild(
1702
            $aqua,
1703
            "tpEmb",
1704
            $tpEmb,
1705
            true,
1706
            "Código do tipo de embarcação"
1707
        );
1708
        $this->dom->addChild(
1709
            $aqua,
1710
            "cEmbar",
1711
            $cEmbar,
1712
            true,
1713
            "Código da Embarcação"
1714
        );
1715
        $this->dom->addChild(
1716
            $aqua,
1717
            "nViagem",
1718
            $nViagem,
1719
            true,
1720
            "Número da Viagem"
1721
        );
1722
        $this->dom->addChild(
1723
            $aqua,
1724
            "cPrtEmb",
1725
            $cPrtEmb,
1726
            true,
1727
            "Código do Porto de Embarque"
1728
        );
1729
        $this->dom->addChild(
1730
            $aqua,
1731
            "cPrtDest",
1732
            $cPrtDest,
1733
            true,
1734
            "Código do Porto de Destino"
1735
        );
1736
        $this->aqua = $aqua;
1737
        return $aqua;
1738
    }
1739
    
1740
    /**
1741
     * tagInfTermCarreg
1742
     * tag MDFe/infMDFe/infModal/Aqua/infTermCarreg
1743
     *
1744
     * @param  string $cTermCarreg
1745
     *
1746
     * @return DOMElement
1747
     */
1748
    public function taginfTermCarreg(
1749
        $cTermCarreg = ''
1750
    ) {
1751
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
1752
        $this->dom->addChild(
1753
            $infTermCarreg,
1754
            "cTermCarreg",
1755
            $cTermCarreg,
1756
            true,
1757
            "Código do Terminal de Carregamento"
1758
        );
1759
        $this->aInfTermCarreg[] = $infTermCarreg;
0 ignored issues
show
Bug introduced by
The property aInfTermCarreg 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...
1760
        return $infTermCarreg;
1761
    }
1762
    /**
1763
     * tagInfTermDescarreg
1764
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
1765
     *
1766
     * @param  string cTermDescarreg
1767
     *
1768
     * @return DOMElement
1769
     */
1770
    public function taginfTermDescarreg(
1771
        $cTermDescarreg = ''
1772
    ) {
1773
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
1774
        $this->dom->addChild(
1775
            $infTermDescarreg,
1776
            "cTermCarreg",
1777
            $cTermDescarreg,
1778
            true,
1779
            "Código do Terminal de Descarregamento"
1780
        );
1781
        $this->aInfTermDescarreg[] = $infTermDescarreg;
0 ignored issues
show
Bug introduced by
The property aInfTermDescarreg 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...
1782
        return $infTermDescarreg;
1783
    }
1784
    /**
1785
     * tagInfEmbComb
1786
     * tag MDFe/infMDFe/infModal/Aqua/infEmbComb
1787
     *
1788
     * @param  string cEmbComb
1789
     *
1790
     * @return DOMElement
1791
     */
1792
    public function taginfEmbComb(
1793
        $cEmbComb = ''
1794
    ) {
1795
        $infEmbComb = $this->dom->createElement("infEmbComb");
1796
        $this->dom->addChild(
1797
            $infEmbComb,
1798
            "cEmbComb",
1799
            $cEmbComb,
1800
            true,
1801
            "Código da embarcação do comboio"
1802
        );
1803
        $this->aInfEmbComb[] = $infEmbComb;
0 ignored issues
show
Bug introduced by
The property aInfEmbComb 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...
1804
        return $infEmbComb;
1805
    }
1806
    
1807
    /**
1808
     * tagVeicTracao
1809
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
1810
     *
1811
     * @param  string cInt Código interno do veículo
1812
     * @param  string placa Placa do veículo
1813
     * @param  string RENAVAM RENAVAM do veículo
1814
     * @param  int tara Tara em KG
1815
     * @param  int capKG Capacidade em KG
1816
     * @param  int capM3 Capacidade em M3
1817
     * @param  stdClass prop Proprietários do Veículo
1818
     * @param  stdClass condutor Informações do(s) Condutor(es) do
1819
     * @param  int tpRod Tipo de Rodado
1820
     * @param  int tpCar Tipo de Carroceria
1821
     * @param  string UF UF em que veículo está licenciado
1822
     *
1823
     * @return DOMElement
1824
     */
1825
1826
    public function tagveicTracao(stdClass $std)
1827
    {
1828
        $possible = [
1829
            'cInt',
1830
            'placa',
1831
            'RENAVAM',
1832
            'tara',
1833
            'capKG',
1834
            'capM3',
1835
            'prop',
1836
            'condutor',
1837
            'tpRod',
1838
            'tpCar',
1839
            'UF'
1840
        ];
1841
        $std = $this->equilizeParameters($std, $possible);
1842
        $veicTracao = $this->dom->createElement("veicTracao");
1843
        $this->dom->addChild(
1844
            $veicTracao,
1845
            "cInt",
1846
            $std->cInt,
1847
            false,
1848
            "Código interno do veículo"
1849
        );
1850
        $this->dom->addChild(
1851
            $veicTracao,
1852
            "placa",
1853
            $std->placa,
1854
            true,
1855
            "Placa do veículo"
1856
        );
1857
        $this->dom->addChild(
1858
            $veicTracao,
1859
            "RENAVAM",
1860
            $std->RENAVAM,
1861
            false,
1862
            "RENAVAM"
1863
        );
1864
        $this->dom->addChild(
1865
            $veicTracao,
1866
            "tara",
1867
            $std->tara,
1868
            true,
1869
            "Tara em KG"
1870
        );
1871
        $this->dom->addChild(
1872
            $veicTracao,
1873
            "capKG",
1874
            $std->capKG,
1875
            false,
1876
            "Capacidade em KG"
1877
        );
1878
        $this->dom->addChild(
1879
            $veicTracao,
1880
            "capM3",
1881
            $std->capM3,
1882
            false,
1883
            "Capacidade em M3"
1884
        );
1885 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...
1886
            $possible = [
1887
                'CPF',
1888
                'CNPJ',
1889
                'RNTRC',
1890
                'xNome',
1891
                'IE',
1892
                'UF',
1893
                'TpProp'
1894
            ];
1895
            $stdprop = $this->equilizeParameters($std->prop, $possible);
1896
            $prop = $this->dom->createElement("prop");
1897
            $this->dom->addChild(
1898
                $prop,
1899
                "CPF",
1900
                $stdprop->CPF,
1901
                true,
1902
                "Número do CPF"
1903
            );
1904
            $this->dom->addChild(
1905
                $prop,
1906
                "CNPJ",
1907
                $stdprop->CNPJ,
1908
                true,
1909
                "Número do CNPJ"
1910
            );
1911
            $this->dom->addChild(
1912
                $prop,
1913
                "RNTRC",
1914
                $stdprop->RNTRC,
1915
                true,
1916
                "RNTRC"
1917
            );
1918
            $this->dom->addChild(
1919
                $prop,
1920
                "xNome",
1921
                $stdprop->xNome,
1922
                true,
1923
                "Razão Social"
1924
            );
1925
            $this->dom->addChild(
1926
                $prop,
1927
                "IE",
1928
                $stdprop->IE,
1929
                true,
1930
                "Inscrição Estadual"
1931
            );
1932
            $this->dom->addChild(
1933
                $prop,
1934
                "UF",
1935
                $stdprop->UF,
1936
                true,
1937
                "Unidade da Federação"
1938
            );
1939
            $this->dom->addChild(
1940
                $prop,
1941
                "TpProp",
1942
                $stdprop->TpProp,
1943
                true,
1944
                "Tipo Proprietário"
1945
            );
1946
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "prop"');
1947
        }
1948
        
1949 View Code Duplication
        if ($std->condutor != 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...
1950
            $possible = [
1951
                'xNome',
1952
                'CPF'
1953
            ];
1954
            $stdcondutor = $this->equilizeParameters($std->condutor, $possible);
1955
            $condutor = $this->dom->createElement("condutor");
1956
            $this->dom->addChild(
1957
                $condutor,
1958
                "xNome",
1959
                $stdcondutor->xNome,
1960
                true,
1961
                "Nome do Condutor "
1962
            );
1963
            $this->dom->addChild(
1964
                $condutor,
1965
                "CPF",
1966
                $stdcondutor->CPF,
1967
                true,
1968
                "CPF do Condutor "
1969
            );
1970
            $this->dom->appChild($veicTracao, $condutor, 'Falta tag "condutor"');
1971
        }
1972
        $this->dom->addChild(
1973
            $veicTracao,
1974
            "tpRod",
1975
            $std->tpRod,
1976
            true,
1977
            "Tipo de rodado"
1978
        );
1979
        $this->dom->addChild(
1980
            $veicTracao,
1981
            "tpCar",
1982
            $std->tpCar,
1983
            true,
1984
            "Tipo de carroceria"
1985
        );
1986
        $this->dom->addChild(
1987
            $veicTracao,
1988
            "UF",
1989
            $std->UF,
1990
            true,
1991
            "UF de licenciamento do veículo"
1992
        );
1993
1994
        $this->dom->appChild($this->rodo, $veicTracao, 'Falta tag "veicTracao"');
1995
        return $this->rodo;
1996
    }
1997
1998
    /**
1999
     * tagVeicReboque
2000
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2001
     *
2002
     * @param string cInt Código interno do veículo
2003
     * @param string placa Placa do veículo
2004
     * @param string RENAVAM RENAVAM do veículo
2005
     * @param int tara Tara em KG
2006
     * @param int capKG Capacidade em KG
2007
     * @param int capM3 Capacidade em M3
2008
     * @param stdClass Proprietários do Veículo
2009
     * @param int tpCar Tipo de Carroceria
2010
     * @param string UF UF em que veículo está licenciado
2011
     *
2012
     * @return DOMElement
2013
     */
2014
    public function tagveicReboque(stdClass $std)
2015
    {
2016
        $possible = [
2017
            'cInt',
2018
            'placa',
2019
            'RENAVAM',
2020
            'tara',
2021
            'capKG',
2022
            'capM3',
2023
            'prop',
2024
            'tpCar',
2025
            'UF'
2026
        ];
2027
        $std = $this->equilizeParameters($std, $possible);
2028
        $veicReboque = $this->dom->createElement("veicReboque");
2029
        $this->dom->addChild(
2030
            $veicReboque,
2031
            "cInt",
2032
            $std->cInt,
2033
            false,
2034
            "Código interno do veículo"
2035
        );
2036
        $this->dom->addChild(
2037
            $veicReboque,
2038
            "placa",
2039
            $std->placa,
2040
            true,
2041
            "Placa do veículo"
2042
        );
2043
        $this->dom->addChild(
2044
            $veicReboque,
2045
            "RENAVAM",
2046
            $std->RENAVAM,
2047
            false,
2048
            "RENAVAM"
2049
        );
2050
        $this->dom->addChild(
2051
            $veicReboque,
2052
            "tara",
2053
            $std->tara,
2054
            true,
2055
            "Tara em KG"
2056
        );
2057
        $this->dom->addChild(
2058
            $veicReboque,
2059
            "capKG",
2060
            $std->capKG,
2061
            false,
2062
            "Capacidade em KG"
2063
        );
2064
        $this->dom->addChild(
2065
            $veicReboque,
2066
            "capM3",
2067
            $std->capM3,
2068
            false,
2069
            "Capacidade em M3"
2070
        );
2071 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...
2072
            $possible = [
2073
                'CPF',
2074
                'CNPJ',
2075
                'RNTRC',
2076
                'xNome',
2077
                'IE',
2078
                'UF',
2079
                'TpProp'
2080
            ];
2081
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2082
            $prop = $this->dom->createElement("prop");
2083
            $this->dom->addChild(
2084
                $prop,
2085
                "CPF",
2086
                $stdprop->CPF,
2087
                true,
2088
                "Número do CPF"
2089
            );
2090
            $this->dom->addChild(
2091
                $prop,
2092
                "CNPJ",
2093
                $stdprop->CNPJ,
2094
                true,
2095
                "Número do CNPJ"
2096
            );
2097
            $this->dom->addChild(
2098
                $prop,
2099
                "RNTRC",
2100
                $stdprop->RNTRC,
2101
                true,
2102
                "RNTRC"
2103
            );
2104
            $this->dom->addChild(
2105
                $prop,
2106
                "xNome",
2107
                $stdprop->xNome,
2108
                true,
2109
                "Razão Social"
2110
            );
2111
            $this->dom->addChild(
2112
                $prop,
2113
                "IE",
2114
                $stdprop->IE,
2115
                true,
2116
                "Inscrição Estadual"
2117
            );
2118
            $this->dom->addChild(
2119
                $prop,
2120
                "UF",
2121
                $stdprop->UF,
2122
                true,
2123
                "Unidade da Federação"
2124
            );
2125
            $this->dom->addChild(
2126
                $prop,
2127
                "TpProp",
2128
                $stdprop->TpProp,
2129
                true,
2130
                "Tipo Proprietário"
2131
            );
2132
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "prop"');
2133
        }
2134
        $this->dom->addChild(
2135
            $veicReboque,
2136
            "tpCar",
2137
            $std->tpCar,
2138
            true,
2139
            "Tipo de carroceria"
2140
        );
2141
        $this->dom->addChild(
2142
            $veicReboque,
2143
            "UF",
2144
            $std->UF,
2145
            true,
2146
            "UF de licenciamento do veículo"
2147
        );
2148
2149
        $this->dom->appChild($this->rodo, $veicReboque, 'Falta tag "veicReboque"');
2150
        return $this->rodo;
2151
    }
2152
2153
    /**
2154
     * tagcodAgPorto
2155
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2156
     *
2157
     * @param  string codAgPorto Código de Agendamento no porto
2158
     *
2159
     * @return DOMElement
2160
     */
2161
    public function tagcodAgPorto(stdClass $std)
2162
    {
2163
        $possible = [
2164
            'codAgPorto'
2165
        ];
2166
        $std = $this->equilizeParameters($std, $possible);
2167
        $this->dom->addChild(
2168
            $this->rodo,
2169
            "codAgPorto",
2170
            $std->codAgPorto,
2171
            false,
2172
            "Código de Agendamento no porto"
2173
        );
2174
        return $this->rodo;
2175
    }
2176
2177
    /**
2178
     * taglacRodo
2179
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2180
     *
2181
     * @param  string nLacre Número do Lacre
2182
     *
2183
     * @return DOMElement
2184
     */
2185
    public function taglacRodo(stdClass $std)
2186
    {
2187
        $possible = [
2188
            'nLacre'
2189
        ];
2190
        $std = $this->equilizeParameters($std, $possible);
2191
        $lacRodo = $this->dom->createElement("lacRodo");
2192
        $this->dom->addChild(
2193
            $lacRodo,
2194
            "nLacre",
2195
            $std->nLacre,
2196
            false,
2197
            "Número do Lacre"
2198
        );
2199
        $this->dom->appChild($this->rodo, $lacRodo, 'Falta tag "lacRodo"');
2200
        return $this->rodo;
2201
    }
2202
2203
    /**
2204
     * buildMDFe
2205
     * Tag raiz da MDFe
2206
     * tag MDFe DOMNode
2207
     * Função chamada pelo método [ monta ]
2208
     *
2209
     * @return DOMElement
2210
     */
2211
    protected function buildMDFe()
2212
    {
2213
        if (empty($this->MDFe)) {
2214
            $this->MDFe = $this->dom->createElement("MDFe");
2215
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
2216
        }
2217
        return $this->MDFe;
2218
    }
2219
2220
    /**
2221
     * buildTagIde
2222
     * Adiciona as tags
2223
     * infMunCarrega e infPercurso
2224
     * a tag ide
2225
     */
2226
    
2227
    protected function buildTagIde()
2228
    {
2229
        if (! empty($this->aInfMunCarrega)) {
2230
            $this->dom->addArrayChild($this->ide, $this->aInfMunCarrega);
2231
        }
2232
        if (! empty($this->aInfPercurso)) {
2233
            $this->dom->addArrayChild($this->ide, $this->aInfPercurso);
2234
        }
2235
    }
2236
    
2237
    /**
2238
     * checkMDFKey
2239
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
2240
     * Isso é útil no caso da chave informada estar errada
2241
     * se a chave estiver errada a mesma é substituida
2242
     *
2243
     * @param object $dom
2244
     */
2245
    private function checkMDFKey($dom)
2246
    {
2247
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2248
        $ide = $dom->getElementsByTagName("ide")->item(0);
2249
        $emit = $dom->getElementsByTagName("emit")->item(0);
2250
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
2251
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
2252
        $cnpj = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
2253
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
2254
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
2255
        $nNF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
2256
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
2257
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
2258
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
2259
        $dt = new DateTime($dhEmi);
2260
        $chaveMontada = Keys::build(
2261
            $cUF,
2262
            $dt->format('y'),
2263
            $dt->format('m'),
2264
            $cnpj,
2265
            $mod,
2266
            $serie,
2267
            $nNF,
2268
            $tpEmis,
2269
            $cNF
2270
        );
2271
        //caso a chave contida na NFe esteja errada
2272
        //substituir a chave
2273
        if ($chaveMontada != $chave) {
2274
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
2275
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
2276
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
2277
            $this->chMDFe = $chaveMontada;
2278
        }
2279
    }
2280
2281
    /**
2282
     * Includes missing or unsupported properties in stdClass
2283
     * Replace all unsuported chars
2284
     * @param stdClass $std
2285
     * @param array $possible
2286
     * @return stdClass
2287
     */
2288
    protected function equilizeParameters(stdClass $std, $possible)
2289
    {
2290
        $arr = get_object_vars($std);
2291
        foreach ($possible as $key) {
2292
            if (!array_key_exists($key, $arr)) {
2293
                $std->$key = null;
2294
            } else {
2295
                if (is_string($std->$key)) {
2296
                    $std->$key = trim(Strings::replaceUnacceptableCharacters($std->$key));
2297
                    if ($this->replaceAccentedChars) {
2298
                        $std->$key = Strings::toASCII($std->$key);
2299
                    }
2300
                }
2301
            }
2302
        }
2303
        return $std;
2304
    }
2305
}
2306