Passed
Push — master ( d5b85e...276051 )
by
unknown
01:59
created

Make::contaDoc()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
229
        $this->dom->preserveWhiteSpace = false;
230
        $this->dom->formatOutput = false;
231
    }
232
233
    /**
234
     * Retorns the xml
235
     *
236
     * @return xml
237
     */
238
    public function getXML()
239
    {
240
        if (empty($this->xml)) {
0 ignored issues
show
Bug introduced by
The property xml does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
241
            $this->montaMDFe();
242
        }
243
        return $this->xml;
244
    }
245
246
    /**
247
     * Retorns the key number of NFe (44 digits)
248
     *
249
     * @return string
250
     */
251
    public function getChave()
252
    {
253
        return $this->chMDFe;
254
    }
255
256
    /**
257
     * Returns the model of MDFe
258
     *
259
     * @return int
260
     */
261
    public function getModelo()
262
    {
263
        return $this->mod;
264
    }
265
266
    /**
267
     * Set character convertion to ASCII only ou not
268
     * @param bool $option
269
     */
270
    public function setOnlyAscii($option = false)
271
    {
272
        $this->replaceAccentedChars = $option;
273
    }
274
275
    /**
276
     * Call method of xml assembly. For compatibility only.
277
     *
278
     * @return boolean
279
     */
280
    public function montaMDFe()
281
    {
282
        return $this->monta();
283
    }
284
285
    /**
286
     * @param $indDoc
287
     * @return int|void
288
     */
289
    private function contaDoc($indDoc)
290
    {
291
        $total = 0;
292
        foreach ($indDoc as $doc) {
293
            $total += count($doc);
294
        }
295
        return $total;
296
    }
297
298
    /**
299
     * MDFe xml mount method
300
     * this function returns TRUE on success or FALSE on error
301
     * The xml of the MDFe must be retrieved by the getXML() function or
302
     * directly by the public property $xml
303
     *
304
     * @return boolean
305
     */
306
    public function monta()
307
    {
308
        $this->errors = $this->dom->errors;
309
        //cria a tag raiz da MDFe
310
        $this->buildMDFe();
311
        $this->buildInfModal();
312
        $this->infMDFe = $this->dom->createElement("infMDFe");
313
        $this->buildIde();
314
        $this->dom->appChild($this->emit, $this->enderEmit, 'Falta tag "enderEmit"');
315
        $this->dom->appChild($this->infMDFe, $this->emit, 'Falta tag "emit"');
316
        if ($this->rodo) {
317
            if (empty($this->prodPred)) {
318
                $this->errors[] = "Tag prodPred é obrigatória para modal rodoviário!";
319
            }
320
            if (empty($this->infLotacao) and ($this->contaDoc($this->infCTe) + $this->contaDoc($this->infNFe) + $this->contaDoc($this->infMDFeTransp)) == 1) {
321
                $this->errors[] = "Tag infLotacao é obrigatória quando só existir um Documento informado!";
322
            }
323
            if ($this->infANTT) {
324
                if ($this->infCIOT) {
325
                    $this->dom->addArrayChild($this->infANTT, $this->infCIOT, 'Falta tag "infCIOT"');
326
                }
327
                if ($this->valePed) {
328
                    $this->dom->appChild($this->infANTT, $this->valePed, 'Falta tag "valePed"');
329
                    if ($this->disp) {
330
                        $this->dom->addArrayChild($this->valePed, $this->disp, 'Falta tag "disp"');
331
                    }
332
                }
333
                if ($this->infContratante) {
334
                    $this->dom->addArrayChild($this->infANTT, $this->infContratante, 'Falta tag "infContratante"');
335
                }
336
                if ($this->infPag) {
337
                    $this->dom->addArrayChild($this->infANTT, $this->infPag, 'Falta tag "infpag"');
338
                }
339
                $this->dom->appChild($this->rodo, $this->infANTT, 'Falta tag "infANTT"');
340
            }
341
            if ($this->veicTracao) {
342
                $this->dom->appChild($this->rodo, $this->veicTracao, 'Falta tag "rodo"');
343
            }
344
            if ($this->veicReboque) {
345
                $this->dom->addArrayChild($this->rodo, $this->veicReboque, 'Falta tag "veicReboque"');
346
            }
347
            if ($this->lacRodo) {
348
                $this->dom->addArrayChild($this->rodo, $this->lacRodo, 'Falta tag "lacRodo"');
349
            }
350
            $this->dom->appChild($this->infModal, $this->rodo, 'Falta tag "infModal"');
351
        }
352
        if ($this->aereo) {
353
            $this->dom->appChild($this->infModal, $this->aereo, 'Falta tag "aereo"');
354
        }
355
        if ($this->ferrov) {
356
            if ($this->trem) {
357
                $this->dom->appChild($this->ferrov, $this->trem, 'Falta tag "ferrov"');
358
            }
359
            if ($this->vag) {
360
                $this->dom->addArrayChild($this->ferrov, $this->vag, 'Falta tag "vag"');
361
            }
362
            $this->dom->appChild($this->infModal, $this->ferrov, 'Falta tag "ferrov"');
363
        }
364
        if ($this->aquav) {
365
            foreach ($this->infTermCarreg as $termCarreg) {
366
                $this->dom->appChild($this->aquav, $termCarreg, 'Falta tag "aquav"');
367
            }
368
            foreach ($this->infTermDescarreg as $termDescarreg) {
369
                $this->dom->appChild($this->aquav, $termDescarreg, 'Falta tag "aquav"');
370
            }
371
            foreach ($this->infEmbComb as $embComb) {
372
                $this->dom->appChild($this->aquav, $embComb, 'Falta tag "aquav"');
373
            }
374
            foreach ($this->infUnidCargaVazia as $unidCargaVazia) {
375
                $this->dom->appChild($this->aquav, $unidCargaVazia, 'Falta tag "aquav"');
376
            }
377
            foreach ($this->infUnidTranspVazia as $unidTranspVazia) {
378
                $this->dom->appChild($this->aquav, $unidTranspVazia, 'Falta tag "aquav"');
379
            }
380
            $this->dom->appChild($this->infModal, $this->aquav, 'Falta tag "aquav"');
381
        }
382
        $this->dom->appChild($this->infMDFe, $this->infModal, 'Falta tag "infModal"');
383
        if ($this->infDoc) {
384
            $this->dom->appChild($this->infMDFe, $this->infDoc, 'Falta tag "infDoc"');
385
            if ($this->infMunDescarga) {
386
                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...
387
                    $this->dom->appChild($this->infDoc, $value, 'Falta tag "infMunDescarga"');
388
                    if (isset($this->infCTe[$key])) {
389
                        $this->dom->addArrayChild($value, $this->infCTe[$key], 'Falta tag "infCTe"');
390
                    }
391
                    if (isset($this->infNFe[$key])) {
392
                        $this->dom->addArrayChild($value, $this->infNFe[$key], 'Falta tag "infNFe"');
393
                    }
394
                    if (isset($this->infMDFeTransp[$key])) {
395
                        $this->dom->addArrayChild($value, $this->infMDFeTransp[$key], 'Falta tag "infMDFeTransp"');
396
                    }
397
                }
398
            }
399
        }
400
        if (!empty($this->seg)) {
401
            $this->dom->addArrayChild($this->infMDFe, $this->seg, 'Falta tag "seg"');
402
        }
403
        if (!empty($this->prodPred)) {
404
            $this->dom->appChild($this->infMDFe, $this->prodPred, 'Falta tag "prodPred"');
405
        }
406
        $this->dom->appChild($this->infMDFe, $this->tot, 'Falta tag "tot"');
407
        if (!empty($this->lacres)) {
408
            foreach ($this->lacres as $lacres) {
0 ignored issues
show
Bug introduced by
The property lacres does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
409
                $this->dom->appChild($this->infMDFe, $lacres, 'Falta tag "lacres"');
410
            }
411
        }
412
        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...
413
            $this->dom->appChild($this->infMDFe, $autXML, 'Falta tag "infMDFe"');
414
        }
415
        if (!empty($this->infAdic)) {
416
            $this->dom->appChild($this->infMDFe, $this->infAdic, 'Falta tag "infAdic"');
417
        }
418
        $this->dom->appChild($this->MDFe, $this->infMDFe, 'Falta tag "infMDFe"');
419
        $this->dom->appendChild($this->MDFe);
420
        // testa da chave
421
        $this->checkMDFKey($this->dom);
422
        $this->xml = $this->dom->saveXML();
423
        if (count($this->errors) > 0) {
424
            throw new RuntimeException('Existem erros nas tags. Obtenha os erros com getErrors().');
425
        }
426
        return true;
427
    }
428
429
    /**
430
     * Informações de identificação da MDFe
431
     * tag MDFe/infMDFe/ide
432
     *
433
     * @param  stdClass $std
434
     * @return DOMElement
435
     */
436
    public function tagide(stdClass $std)
437
    {
438
439
        $possible = [
440
            'cUF',
441
            'tpAmb',
442
            'tpEmit',
443
            'tpTransp',
444
            'mod',
445
            'serie',
446
            'nMDF',
447
            'cMDF',
448
            'cDV',
449
            'modal',
450
            'dhEmi',
451
            'tpEmis',
452
            'procEmi',
453
            'verProc',
454
            'UFIni',
455
            'UFFim',
456
            'dhIniViagem',
457
            'indCanalVerde',
458
            'indCarregaPosterior'
459
        ];
460
461
        $std = $this->equilizeParameters($std, $possible);
462
463
        $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...
464
        $identificador = '[4] <ide> - ';
465
        $ide = $this->dom->createElement("ide");
466
        $this->dom->addChild(
467
            $ide,
468
            "cUF",
469
            $std->cUF,
470
            true,
471
            $identificador . "Código da UF do emitente do Documento Fiscal"
472
        );
473
        $this->dom->addChild(
474
            $ide,
475
            "tpAmb",
476
            $std->tpAmb,
477
            true,
478
            $identificador . "Identificação do Ambiente"
479
        );
480
        $this->dom->addChild(
481
            $ide,
482
            "tpEmit",
483
            $std->tpEmit,
484
            true,
485
            $identificador . "Indicador da tipo de emitente"
486
        );
487
        $this->dom->addChild(
488
            $ide,
489
            "tpTransp",
490
            $std->tpTransp,
491
            false,
492
            $identificador . "Tipo do Transportador"
493
        );
494
        $this->dom->addChild(
495
            $ide,
496
            "mod",
497
            $std->mod,
498
            true,
499
            $identificador . "Código do Modelo do Documento Fiscal"
500
        );
501
        $this->dom->addChild(
502
            $ide,
503
            "serie",
504
            $std->serie,
505
            true,
506
            $identificador . "Série do Documento Fiscal"
507
        );
508
        $this->dom->addChild(
509
            $ide,
510
            "nMDF",
511
            $std->nMDF,
512
            true,
513
            $identificador . "Número do Documento Fiscal"
514
        );
515
        $this->dom->addChild(
516
            $ide,
517
            "cMDF",
518
            str_pad($std->cMDF, 8, '0', STR_PAD_LEFT),
519
            true,
520
            $identificador . "Código do numérico do MDF"
521
        );
522
        $this->dom->addChild(
523
            $ide,
524
            "cDV",
525
            $std->cDV,
526
            true,
527
            $identificador . "Dígito Verificador da Chave de Acesso da NF-e"
528
        );
529
        $this->dom->addChild(
530
            $ide,
531
            "modal",
532
            $std->modal,
533
            true,
534
            $identificador . "Modalidade de transporte"
535
        );
536
        $this->dom->addChild(
537
            $ide,
538
            "dhEmi",
539
            $std->dhEmi,
540
            true,
541
            $identificador . "Data e hora de emissão do Documento Fiscal"
542
        );
543
        $this->dom->addChild(
544
            $ide,
545
            "tpEmis",
546
            $std->tpEmis,
547
            true,
548
            $identificador . "Tipo de Emissão do Documento Fiscal"
549
        );
550
        $this->dom->addChild(
551
            $ide,
552
            "procEmi",
553
            $std->procEmi,
554
            true,
555
            $identificador . "Processo de emissão"
556
        );
557
        $this->dom->addChild(
558
            $ide,
559
            "verProc",
560
            $std->verProc,
561
            true,
562
            $identificador . "Versão do Processo de emissão"
563
        );
564
        $this->dom->addChild(
565
            $ide,
566
            "UFIni",
567
            $std->UFIni,
568
            true,
569
            $identificador . "Sigla da UF do Carregamento"
570
        );
571
        $this->dom->addChild(
572
            $ide,
573
            "UFFim",
574
            $std->UFFim,
575
            true,
576
            $identificador . "Sigla da UF do Descarregamento"
577
        );
578
        $this->dom->addChild(
579
            $ide,
580
            "dhIniViagem",
581
            $std->dhIniViagem,
582
            false,
583
            $identificador . "Data e hora previstos de início da viagem"
584
        );
585
        $this->dom->addChild(
586
            $ide,
587
            "indCanalVerde",
588
            $std->indCanalVerde,
589
            false,
590
            $identificador . "Indicador de participação do Canal Verde"
591
        );
592
        $this->dom->addChild(
593
            $ide,
594
            "indCarregaPosterior",
595
            $std->indCarregaPosterior,
596
            false,
597
            $identificador . "Indicador de MDF-e com inclusão da Carga posterior a emissão por evento de inclusão de DF-e"
598
        );
599
600
        $this->mod = $std->mod;
601
        $this->ide = $ide;
602
        return $ide;
603
    }
604
605
    /**
606
     * taginfMunCarrega
607
     *
608
     * tag MDFe/infMDFe/ide/infMunCarrega
609
     *
610
     * @param  stdClass $std
611
     * @return DOMElement
612
     */
613
    public function taginfMunCarrega(stdClass $std)
614
    {
615
        $possible = [
616
            'cMunCarrega',
617
            'xMunCarrega'
618
        ];
619
620
        $std = $this->equilizeParameters($std, $possible);
621
        $infMunCarrega = $this->dom->createElement("infMunCarrega");
622
        $this->dom->addChild(
623
            $infMunCarrega,
624
            "cMunCarrega",
625
            $std->cMunCarrega,
626
            true,
627
            "Código do Município de Carregamento"
628
        );
629
        $this->dom->addChild(
630
            $infMunCarrega,
631
            "xMunCarrega",
632
            $std->xMunCarrega,
633
            true,
634
            "Nome do Município de Carregamento"
635
        );
636
        $this->infMunCarrega[] = $infMunCarrega;
637
        return $infMunCarrega;
638
    }
639
640
    /**
641
     * tagInfPercurso
642
     *
643
     * tag MDFe/infMDFe/ide/infPercurso
644
     *
645
     * @param  stdClass $std
646
     * @return DOMElement
647
     */
648
    public function taginfPercurso(stdClass $std)
649
    {
650
        $possible = [
651
            'UFPer'
652
        ];
653
654
        $std = $this->equilizeParameters($std, $possible);
655
        $infPercurso = $this->dom->createElement("infPercurso");
656
        $this->dom->addChild(
657
            $infPercurso,
658
            "UFPer",
659
            $std->UFPer,
660
            true,
661
            "Sigla das Unidades da Federação do percurso"
662
        );
663
        $this->infPercurso[] = $infPercurso;
664
        return $infPercurso;
665
    }
666
667
    /**
668
     * tagemit
669
     * Identificação do emitente da MDFe
670
     * tag MDFe/infMDFe/emit
671
     *
672
     * @param  stdClass $std
673
     * @return DOMElement
674
     */
675
    public function tagemit(stdClass $std)
676
    {
677
        $possible = [
678
            'CNPJ',
679
            'CPF',
680
            'IE',
681
            'xNome',
682
            'xFant'
683
        ];
684
        $std = $this->equilizeParameters($std, $possible);
685
686
        $identificador = '[25] <emit> - ';
687
        $this->emit = $this->dom->createElement("emit");
688
        if ($std->CPF) {
689
            $this->dom->addChild(
690
                $this->emit,
691
                "CPF",
692
                $std->CPF,
693
                true,
694
                $identificador . "CPF do emitente"
695
            );
696
        } else {
697
            $this->dom->addChild(
698
                $this->emit,
699
                "CNPJ",
700
                $std->CNPJ,
701
                true,
702
                $identificador . "CNPJ do emitente"
703
            );
704
        }
705
        $this->dom->addChild(
706
            $this->emit,
707
            "IE",
708
            $std->IE,
709
            false,
710
            $identificador . "Inscrição Estadual do emitente"
711
        );
712
        $this->dom->addChild(
713
            $this->emit,
714
            "xNome",
715
            $std->xNome,
716
            true,
717
            $identificador . "Razão Social ou Nome do emitente"
718
        );
719
        $this->dom->addChild(
720
            $this->emit,
721
            "xFant",
722
            $std->xFant,
723
            false,
724
            $identificador . "Nome fantasia do emitente"
725
        );
726
        return $this->emit;
727
    }
728
729
    /**
730
     * tagenderEmit
731
     * Endereço do emitente [30] pai [25]
732
     * tag MDFe/infMDFe/emit/endEmit
733
     *
734
     * @param  stdClass $std
735
     * @return DOMElement
736
     */
737
    public function tagenderEmit(stdClass $std)
738
    {
739
        $possible = [
740
            'xLgr',
741
            'nro',
742
            'xCpl',
743
            'xBairro',
744
            'cMun',
745
            'xMun',
746
            'CEP',
747
            'UF',
748
            'fone',
749
            'email'
750
        ];
751
        $std = $this->equilizeParameters($std, $possible);
752
753
        $identificador = '[30] <enderEmit> - ';
754
        $this->enderEmit = $this->dom->createElement("enderEmit");
755
756
        $this->dom->addChild(
757
            $this->enderEmit,
758
            "xLgr",
759
            $std->xLgr,
760
            true,
761
            $identificador . "Logradouro do Endereço do emitente"
762
        );
763
        $this->dom->addChild(
764
            $this->enderEmit,
765
            "nro",
766
            $std->nro,
767
            true,
768
            $identificador . "Número do Endereço do emitente"
769
        );
770
        $this->dom->addChild(
771
            $this->enderEmit,
772
            "xCpl",
773
            $std->xCpl,
774
            false,
775
            $identificador . "Complemento do Endereço do emitente"
776
        );
777
        $this->dom->addChild(
778
            $this->enderEmit,
779
            "xBairro",
780
            $std->xBairro,
781
            true,
782
            $identificador . "Bairro do Endereço do emitente"
783
        );
784
        $this->dom->addChild(
785
            $this->enderEmit,
786
            "cMun",
787
            $std->cMun,
788
            true,
789
            $identificador . "Código do município do Endereço do emitente"
790
        );
791
        $this->dom->addChild(
792
            $this->enderEmit,
793
            "xMun",
794
            $std->xMun,
795
            true,
796
            $identificador . "Nome do município do Endereço do emitente"
797
        );
798
        $this->dom->addChild(
799
            $this->enderEmit,
800
            "CEP",
801
            $std->CEP,
802
            true,
803
            $identificador . "Código do CEP do Endereço do emitente"
804
        );
805
        $this->dom->addChild(
806
            $this->enderEmit,
807
            "UF",
808
            $std->UF,
809
            true,
810
            $identificador . "Sigla da UF do Endereço do emitente"
811
        );
812
        $this->dom->addChild(
813
            $this->enderEmit,
814
            "fone",
815
            $std->fone,
816
            false,
817
            $identificador . "Número de telefone do emitente"
818
        );
819
        $this->dom->addChild(
820
            $this->enderEmit,
821
            "email",
822
            $std->email,
823
            false,
824
            $identificador . "Endereço de email do emitente"
825
        );
826
        return $this->enderEmit;
827
    }
828
829
    /**
830
     * tagrodo
831
     * tag MDFe/infMDFe/infModal/rodo
832
     *
833
     * @return DOMElement
834
     */
835
    private function tagrodo()
836
    {
837
        $this->rodo = $this->dom->createElement("rodo");
838
        return $this->rodo;
839
    }
840
841
    /**
842
     * tagferrov
843
     * tag MDFe/infMDFe/infModal/ferrov
844
     *
845
     * @return DOMElement
846
     */
847
    private function tagferrov()
848
    {
849
        if (empty($this->ferrov)) {
850
            $this->ferrov = $this->dom->createElement("ferrov");
851
        }
852
        return $this->ferrov;
853
    }
854
855
    /**
856
     * tagrodo
857
     * tag MDFe/infMDFe/infModal/rodo
858
     *
859
     * @return DOMElement
860
     */
861
    private function taginfDoc()
862
    {
863
        if (empty($this->infDoc)) {
864
            $this->infDoc = $this->dom->createElement("infDoc");
865
        }
866
        return $this->infDoc;
867
    }
868
869
    /**
870
     * valePed
871
     * tag MDFe/infMDFe/infModal/rodo/infANTT/valePed
872
     *
873
     * @return DOMElement
874
     */
875
    private function tagvalePed()
876
    {
877
        if (empty($this->valePed)) {
878
            $this->valePed = $this->dom->createElement("valePed");
879
        }
880
        return $this->valePed;
881
    }
882
883
    /**
884
     * infANTT
885
     * tag MDFe/infMDFe/infModal/rodo/infANTT
886
     *
887
     * @return DOMElement
888
     */
889
    public function taginfANTT(stdClass $std)
890
    {
891
        $possible = [
892
            'RNTRC'
893
        ];
894
        $std = $this->equilizeParameters($std, $possible);
895
        $identificador = '[2] <infANTT> - ';
896
        $infANTT = $this->dom->createElement("infANTT");
897
        $this->dom->addChild(
898
            $infANTT,
899
            "RNTRC",
900
            $std->RNTRC,
901
            false,
902
            $identificador . "Registro Nacional de Transportadores Rodoviários de Carga"
903
        );
904
        $this->infANTT = $infANTT;
905
        return $infANTT;
906
    }
907
908
    /**
909
     * disp
910
     * tag MDFe/infMDFe/infModal/rodo/infANTT/disp
911
     *
912
     * @return DOMElement
913
     */
914
    public function tagdisp(stdClass $std)
915
    {
916
        $possible = [
917
            'CNPJForn',
918
            'CNPJPg',
919
            'CPFPg',
920
            'nCompra',
921
            'vValePed'
922
        ];
923
        $this->tagvalePed();
924
        $std = $this->equilizeParameters($std, $possible);
925
        $identificador = '[4] <disp> - ';
926
        $disp = $this->dom->createElement("disp");
927
        $this->dom->addChild(
928
            $disp,
929
            "CNPJForn",
930
            $std->CNPJForn,
931
            false,
932
            $identificador . "CNPJ da empresa fornecedora do ValePedágio"
933
        );
934
        $this->dom->addChild(
935
            $disp,
936
            "CNPJPg",
937
            $std->CNPJPg,
938
            false,
939
            $identificador . "CNPJ do responsável pelo pagamento do Vale-Pedágio"
940
        );
941
        $this->dom->addChild(
942
            $disp,
943
            "CPFPg",
944
            $std->CPFPg,
945
            false,
946
            $identificador . "CPF do responsável pelo pagamento do Vale-Pedágio"
947
        );
948
        $this->dom->addChild(
949
            $disp,
950
            "nCompra",
951
            $std->nCompra,
952
            false,
953
            $identificador . "Número do comprovante de compra"
954
        );
955
        $this->dom->addChild(
956
            $disp,
957
            "vValePed",
958
            $std->vValePed,
959
            false,
960
            $identificador . "Valor do Vale-Pedagio"
961
        );
962
        $this->disp[] = $disp;
963
        return $disp;
964
    }
965
966
    /**
967
     * infContratante
968
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infContratante
969
     *
970
     * @return DOMElement
971
     */
972
    public function taginfContratante(stdClass $std)
973
    {
974
        $possible = [
975
            'xNome',
976
            'CPF',
977
            'CPF',
978
            'idEstrangeiro'
979
        ];
980
        $std = $this->equilizeParameters($std, $possible);
981
        $identificador = '[4] <infContratante> - ';
982
        $infContratante = $this->dom->createElement("infContratante");
983
984
        $this->dom->addChild(
985
            $infContratante,
986
            "xNome",
987
            $std->xNome,
988
            false,
989
            $identificador . "Nome do contratante do serviço"
990
        );
991
        if ($std->CPF) {
992
            $this->dom->addChild(
993
                $infContratante,
994
                "CPF",
995
                $std->CPF,
996
                true,
997
                $identificador . "Número do CPF do contratante do serviço"
998
            );
999
        } else if ($std->CNPJ) {
1000
            $this->dom->addChild(
1001
                $infContratante,
1002
                "CNPJ",
1003
                $std->CNPJ,
1004
                true,
1005
                $identificador . "Número do CNPJ do contratante do serviço"
1006
            );
1007
        } else {
1008
            $this->dom->addChild(
1009
                $infContratante,
1010
                "idEstrangeiro",
1011
                $std->idEstrangeiro,
1012
                true,
1013
                $identificador . "Identificador do contratante do serviço em caso de ser estrangeiro"
1014
            );
1015
        }
1016
        $this->infContratante[] = $infContratante;
1017
        return $infContratante;
1018
    }
1019
1020
    /**
1021
     * infANTT
1022
     * tag MDFe/infMDFe/infModal/rodo/infANTT/infCIOT
1023
     *
1024
     * @return DOMElement
1025
     */
1026
    public function taginfCIOT(stdClass $std)
1027
    {
1028
        $possible = [
1029
            'CIOT',
1030
            'CPF',
1031
            'CNPJ'
1032
        ];
1033
        $std = $this->equilizeParameters($std, $possible);
1034
        $identificador = '[4] <infCIOT> - ';
1035
        $infCIOT = $this->dom->createElement("infCIOT");
1036
        $this->dom->addChild(
1037
            $infCIOT,
1038
            "CIOT",
1039
            $std->CIOT,
1040
            true,
1041
            $identificador . "Código Identificador da Operação de Transporte"
1042
        );
1043
        if ($std->CPF) {
1044
            $this->dom->addChild(
1045
                $infCIOT,
1046
                "CPF",
1047
                $std->CPF,
1048
                true,
1049
                $identificador . "Número do CPF responsável pela geração do CIOT"
1050
            );
1051
        } else {
1052
            $this->dom->addChild(
1053
                $infCIOT,
1054
                "CNPJ",
1055
                $std->CNPJ,
1056
                true,
1057
                $identificador . "Número do CNPJ responsável pela geração do CIOT"
1058
            );
1059
        }
1060
        $this->infCIOT[] = $infCIOT;
1061
        return $infCIOT;
1062
    }
1063
1064
    /**
1065
     * tagInfMunDescarga
1066
     * tag MDFe/infMDFe/infDoc/infMunDescarga
1067
     *
1068
     * @param  stdClass $std
1069
     * @return DOMElement
1070
     */
1071
    public function taginfMunDescarga(stdClass $std)
1072
    {
1073
        $possible = [
1074
            'cMunDescarga',
1075
            'xMunDescarga',
1076
            'nItem'
1077
        ];
1078
        $this->taginfDoc();
1079
        $std = $this->equilizeParameters($std, $possible);
1080
        $identificador = '[4] <infMunDescarga> - ';
1081
        $infMunDescarga = $this->dom->createElement("infMunDescarga");
1082
        $this->dom->addChild(
1083
            $infMunDescarga,
1084
            "cMunDescarga",
1085
            $std->cMunDescarga,
1086
            true,
1087
            $identificador . "Código do Município de Descarga"
1088
        );
1089
        $this->dom->addChild(
1090
            $infMunDescarga,
1091
            "xMunDescarga",
1092
            $std->xMunDescarga,
1093
            true,
1094
            $identificador . "Nome do Município de Descarga"
1095
        );
1096
        $this->infMunDescarga[$std->nItem] = $infMunDescarga;
1097
        return $infMunDescarga;
1098
    }
1099
1100
    /**
1101
     * taginfCTe
1102
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infCTe
1103
     *
1104
     * @param  stdClass $std
1105
     * @return DOMElement
1106
     */
1107
    public function taginfCTe(stdClass $std)
1108
    {
1109
        $possible = [
1110
            'chCTe',
1111
            'SegCodBarra',
1112
            'indReentrega',
1113
            'infEntregaParcial',
1114
            'infUnidTransp',
1115
            'peri',
1116
            'nItem'
1117
        ];
1118
        $std = $this->equilizeParameters($std, $possible);
1119
        $infCTe = $this->dom->createElement("infCTe");
1120
        $identificador = '[4] <infCTe> - ';
1121
        $this->dom->addChild(
1122
            $infCTe,
1123
            "chCTe",
1124
            $std->chCTe,
1125
            true,
1126
            $identificador . "Chave de Acesso CTe"
1127
        );
1128
        $this->dom->addChild(
1129
            $infCTe,
1130
            "SegCodBarra",
1131
            $std->SegCodBarra,
1132
            false,
1133
            $identificador . "Segundo código de barras do CTe"
1134
        );
1135
        $this->dom->addChild(
1136
            $infCTe,
1137
            "indReentrega",
1138
            $std->indReentrega,
1139
            false,
1140
            $identificador . "Indicador de Reentrega"
1141
        );
1142
        if ($std->infUnidTransp) {
1143
            foreach ($std->infUnidTransp as $value) {
1144
                $this->dom->appChild($infCTe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1145
            }
1146
        }
1147
        if ($std->peri) {
1148
            foreach ($std->peri as $value) {
1149
                $this->dom->appChild($infCTe, $this->tagperi($value), 'Falta tag "peri"');
1150
            }
1151
        }
1152
        if ($std->infEntregaParcial != null) {
1153
            $possible = [
1154
                'qtdTotal',
1155
                'qtdParcial'
1156
            ];
1157
            $stdinfEntregaParcial = $this->equilizeParameters($std->infEntregaParcial, $possible);
1158
            $identificadorparcial = '[4] <infEntregaParcial> - ';
1159
            $infEntregaParcial = $this->dom->createElement("infEntregaParcial");
1160
            $this->dom->addChild(
1161
                $infEntregaParcial,
1162
                "qtdTotal",
1163
                $stdinfEntregaParcial->qtdTotal,
1164
                true,
1165
                $identificadorparcial . "Quantidade total de volumes"
1166
            );
1167
            $this->dom->addChild(
1168
                $infEntregaParcial,
1169
                "qtdParcial",
1170
                $stdinfEntregaParcial->qtdParcial,
1171
                true,
1172
                $identificadorparcial . "Quantidade de volumes enviados no MDF-e"
1173
            );
1174
            $this->dom->appChild($infCTe, $infEntregaParcial, 'Falta tag "infCTe"');
1175
        }
1176
        $this->infCTe[$std->nItem][] = $infCTe;
1177
        return $infCTe;
1178
    }
1179
1180
    /**
1181
     * tagperi
1182
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/peri
1183
     *
1184
     * @param  stdClass $std
1185
     * @return DOMElement
1186
     */
1187
    private function tagperi(stdClass $std)
1188
    {
1189
        $possible = [
1190
            'nONU',
1191
            'xNomeAE',
1192
            'xClaRisco',
1193
            'grEmb',
1194
            'qTotProd',
1195
            'qVolTipo'
1196
        ];
1197
        $std = $this->equilizeParameters($std, $possible);
1198
        $peri = $this->dom->createElement("peri");
1199
        $this->dom->addChild(
1200
            $peri,
1201
            "nONU",
1202
            $std->nONU,
1203
            true,
1204
            "Número ONU/UN"
1205
        );
1206
        $this->dom->addChild(
1207
            $peri,
1208
            "xNomeAE",
1209
            $std->xNomeAE,
1210
            true,
1211
            "Nome apropriado para embarque do produto"
1212
        );
1213
        $this->dom->addChild(
1214
            $peri,
1215
            "xClaRisco",
1216
            $std->xClaRisco,
1217
            true,
1218
            "Classe ou subclasse/divisão, e risco subsidiário/risco secundário"
1219
        );
1220
        $this->dom->addChild(
1221
            $peri,
1222
            "grEmb",
1223
            $std->grEmb,
1224
            true,
1225
            "Grupo de Embalagem"
1226
        );
1227
        $this->dom->addChild(
1228
            $peri,
1229
            "qTotProd",
1230
            $std->qTotProd,
1231
            true,
1232
            "Quantidade total por produto"
1233
        );
1234
        $this->dom->addChild(
1235
            $peri,
1236
            "qVolTipo",
1237
            $std->qVolTipo,
1238
            true,
1239
            "Quantidade e Tipo de volumes"
1240
        );
1241
        return $peri;
1242
    }
1243
1244
    /**
1245
     * taginfNFe
1246
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infNFe
1247
     *
1248
     * @param  stdClass $std
1249
     * @return DOMElement
1250
     */
1251
    public function taginfNFe(stdClass $std)
1252
    {
1253
        $possible = [
1254
            'chNFe',
1255
            'SegCodBarra',
1256
            'indReentrega',
1257
            'infUnidTransp',
1258
            'peri',
1259
            'nItem'
1260
        ];
1261
        $std = $this->equilizeParameters($std, $possible);
1262
        $infNFe = $this->dom->createElement("infNFe");
1263
        $this->dom->addChild(
1264
            $infNFe,
1265
            "chNFe",
1266
            $std->chNFe,
1267
            true,
1268
            "Chave de Acesso NFe"
1269
        );
1270
        $this->dom->addChild(
1271
            $infNFe,
1272
            "SegCodBarra",
1273
            $std->SegCodBarra,
1274
            false,
1275
            "Segundo código de barras do NFe"
1276
        );
1277
        $this->dom->addChild(
1278
            $infNFe,
1279
            "indReentrega",
1280
            $std->indReentrega,
1281
            false,
1282
            "Indicador de Reentrega"
1283
        );
1284
        if ($std->infUnidTransp) {
1285
            foreach ($std->infUnidTransp as $value) {
1286
                $this->dom->appChild($infNFe, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1287
            }
1288
        }
1289
        if ($std->peri) {
1290
            foreach ($std->peri as $value) {
1291
                $this->dom->appChild($infNFe, $this->tagperi($value), 'Falta tag "peri"');
1292
            }
1293
        }
1294
        $this->infNFe[$std->nItem][] = $infNFe;
1295
        return $infNFe;
1296
    }
1297
1298
    /**
1299
     * taginfMDFeTransp
1300
     * tag MDFe/infMDFe/infDoc/infMunDescarga/infMDFeTransp
1301
     *
1302
     * @param  stdClass $std
1303
     * @return DOMElement
1304
     */
1305
    public function taginfMDFeTransp(stdClass $std)
1306
    {
1307
        $possible = [
1308
            'chMDFe',
1309
            'indReentrega',
1310
            'nItem'
1311
        ];
1312
        $std = $this->equilizeParameters($std, $possible);
1313
        $infMDFeTransp = $this->dom->createElement("infMDFeTransp");
1314
        $this->dom->addChild(
1315
            $infMDFeTransp,
1316
            "chMDFe",
1317
            $std->chMDFe,
1318
            true,
1319
            "Chave de Acesso NFe"
1320
        );
1321
        $this->dom->addChild(
1322
            $infMDFeTransp,
1323
            "indReentrega",
1324
            $std->indReentrega,
1325
            false,
1326
            "Indicador de Reentrega"
1327
        );
1328
        if ($std->infUnidTransp) {
1329
            foreach ($std->infUnidTransp as $value) {
1330
                $this->dom->appChild($infMDFeTransp, $this->taginfUnidTransp($value), 'Falta tag "infUnidTransp"');
1331
            }
1332
        }
1333
        if ($std->peri) {
1334
            foreach ($std->peri as $value) {
1335
                $this->dom->appChild($infMDFeTransp, $this->tagperi($value), 'Falta tag "peri"');
1336
            }
1337
        }
1338
        $this->infMDFeTransp[$std->nItem][] = $infMDFeTransp;
1339
        return $infMDFeTransp;
1340
    }
1341
1342
    /**
1343
     * taginfUnidTransp
1344
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidTransp
1345
     *
1346
     * @param  stdClass $std
1347
     * @return DOMElement
1348
     */
1349
    private function taginfUnidTransp(stdClass $std)
1350
    {
1351
        $possible = [
1352
            'tpUnidTransp',
1353
            'idUnidTransp',
1354
            'qtdRat',
1355
            'lacUnidTransp',
1356
            'infUnidCarga'
1357
        ];
1358
        $std = $this->equilizeParameters($std, $possible);
1359
        $infUnidTransp = $this->dom->createElement("infUnidTransp");
1360
        $this->dom->addChild(
1361
            $infUnidTransp,
1362
            "tpUnidTransp",
1363
            $std->tpUnidTransp,
1364
            true,
1365
            "Tipo da Unidade de Transporte"
1366
        );
1367
        $this->dom->addChild(
1368
            $infUnidTransp,
1369
            "idUnidTransp",
1370
            $std->idUnidTransp,
1371
            false,
1372
            "Identificação da Unidade de Transporte"
1373
        );
1374
        if ($std->lacUnidTransp != null) {
1375
            $possible = [
1376
                'nLacre'
1377
            ];
1378
            $stdlacUnidTransp = $this->equilizeParameters($std->lacUnidTransp, $possible);
1379
            foreach ($stdlacUnidTransp->nLacre as $nLacre) {
1380
                $lacUnidTransp = $this->dom->createElement("lacUnidTransp");
1381
                $this->dom->addChild(
1382
                    $lacUnidTransp,
1383
                    "nLacre",
1384
                    $nLacre,
1385
                    true,
1386
                    "Número do lacre"
1387
                );
1388
                $this->dom->appChild($infUnidTransp, $lacUnidTransp, 'Falta tag "infUnidTransp"');
1389
            }
1390
        }
1391
        if ($std->infUnidCarga) {
1392
            foreach ($std->infUnidCarga as $value) {
1393
                $this->dom->appChild($infUnidTransp, $this->taginfUnidCarga($value), 'Falta tag "infUnidCarga"');
1394
            }
1395
        }
1396
        $this->dom->addChild(
1397
            $infUnidTransp,
1398
            "qtdRat",
1399
            $std->qtdRat,
1400
            false,
1401
            "Quantidade rateada (Peso,Volume) "
1402
        );
1403
        return $infUnidTransp;
1404
    }
1405
1406
    /**
1407
     * taginfUnidCarga
1408
     * tag MDFe/infMDFe/infDoc/infMunDescarga/(infCTe/infNFe)/infUnidCarga
1409
     *
1410
     * @param  stdClass $std
1411
     * @return DOMElement
1412
     */
1413
    private function taginfUnidCarga(stdClass $std)
1414
    {
1415
        $possible = [
1416
            'tpUnidCarga',
1417
            'idUnidCarga',
1418
            'lacUnidCarga',
1419
            'qtdRat'
1420
        ];
1421
        $std = $this->equilizeParameters($std, $possible);
1422
        $infUnidCarga = $this->dom->createElement("infUnidCarga");
1423
        $this->dom->addChild(
1424
            $infUnidCarga,
1425
            "tpUnidCarga",
1426
            $std->tpUnidCarga,
1427
            false,
1428
            "Tipo da Unidade de Carga"
1429
        );
1430
        $this->dom->addChild(
1431
            $infUnidCarga,
1432
            "idUnidCarga",
1433
            $std->idUnidCarga,
1434
            false,
1435
            "Identificação da Unidade de Carga "
1436
        );
1437
        if ($std->lacUnidCarga != null) {
1438
            $possible = [
1439
                'nLacre'
1440
            ];
1441
            $stdlacUnidCarga = $this->equilizeParameters($std->lacUnidCarga, $possible);
1442
            foreach ($stdlacUnidCarga->nLacre as $nLacre) {
1443
                $lacUnidCarga = $this->dom->createElement("lacUnidCarga");
1444
                $this->dom->addChild(
1445
                    $lacUnidCarga,
1446
                    "nLacre",
1447
                    $nLacre,
1448
                    true,
1449
                    "Número do lacre"
1450
                );
1451
                $this->dom->appChild($infUnidCarga, $lacUnidCarga, 'Falta tag "infUnidCarga"');
1452
            }
1453
        }
1454
        $this->dom->addChild(
1455
            $infUnidCarga,
1456
            "qtdRat",
1457
            $std->qtdRat,
1458
            false,
1459
            "Quantidade rateada (Peso,Volume) "
1460
        );
1461
        return $infUnidCarga;
1462
    }
1463
1464
    /**
1465
     * tagseg
1466
     * tag MDFe/infMDFe/seg
1467
     *
1468
     * @param  stdClass $std
1469
     * @return DOMElement
1470
     */
1471
    public function tagseg(stdClass $std)
1472
    {
1473
        $possible = [
1474
            'respSeg',
1475
            'CNPJ',
1476
            'CPF',
1477
            'infSeg',
1478
            'nApol',
1479
            'nAver'
1480
        ];
1481
        $std = $this->equilizeParameters($std, $possible);
1482
        $seg = $this->dom->createElement("seg");
1483
        $infResp = $this->dom->createElement("infResp");
1484
        $this->dom->addChild(
1485
            $infResp,
1486
            "respSeg",
1487
            $std->respSeg,
1488
            true,
1489
            "Responsável pelo seguro"
1490
        );
1491
        $this->dom->addChild(
1492
            $infResp,
1493
            "CNPJ",
1494
            $std->CNPJ,
1495
            false,
1496
            "Número do CNPJ do responsável pelo seguro"
1497
        );
1498
        $this->dom->addChild(
1499
            $infResp,
1500
            "CPF",
1501
            $std->CPF,
1502
            false,
1503
            "Número do CPF do responsável pelo seguro"
1504
        );
1505
        $this->dom->appChild($seg, $infResp, 'Falta tag "seg"');
1506
        if ($std->infSeg != null) {
1507
            $possible = [
1508
                'xSeg',
1509
                'CNPJ'
1510
            ];
1511
            $stdinfSeg = $this->equilizeParameters($std->infSeg, $possible);
1512
            $infSeg = $this->dom->createElement("infSeg");
1513
            $this->dom->addChild(
1514
                $infSeg,
1515
                "xSeg",
1516
                $stdinfSeg->xSeg,
1517
                true,
1518
                "Nome da Seguradora"
1519
            );
1520
            $this->dom->addChild(
1521
                $infSeg,
1522
                "CNPJ",
1523
                $stdinfSeg->CNPJ,
1524
                false,
1525
                "Número do CNPJ da seguradora"
1526
            );
1527
            $this->dom->appChild($seg, $infSeg, 'Falta tag "seg"');
1528
        }
1529
        $this->dom->addChild(
1530
            $seg,
1531
            "nApol",
1532
            $std->nApol,
1533
            false,
1534
            "Número da Apólice"
1535
        );
1536
        if ($std->nAver != null) {
1537
            foreach ($std->nAver as $nAver) {
1538
                $this->dom->addChild(
1539
                    $seg,
1540
                    "nAver",
1541
                    $nAver,
1542
                    true,
1543
                    "Número da Averbação"
1544
                );
1545
            }
1546
        }
1547
        $this->seg[] = $seg;
1548
        return $seg;
1549
    }
1550
1551
    /**
1552
     * tagprodPred
1553
     * tag MDFe/infMDFe/prodPred
1554
     *
1555
     * @param  stdClass $std
1556
     * @return DOMElement
1557
     */
1558
    public function tagprodPred($std)
1559
    {
1560
        $possible = [
1561
            'tpCarga',
1562
            'xProd',
1563
            'cEAN',
1564
            'NCM',
1565
            'infLotacao'
1566
        ];
1567
        $std = $this->equilizeParameters($std, $possible);
1568
        $this->prodPred = $this->dom->createElement("prodPred");
1569
        $this->dom->addChild(
1570
            $this->prodPred,
1571
            "tpCarga",
1572
            $std->tpCarga,
1573
            true,
1574
            "Tipo da Carga. 01-Granel sólido; 02-Granel líquido; 03-Frigorificada; 04-Conteinerizada; 05-Carga Geral; 06-Neogranel; 07-Perigosa (granel sólido); 08-Perigosa (granel líquido); 09-Perigosa (carga frigorificada); 10-Perigosa (conteinerizada); 11-Perigosa (carga geral)."
1575
        );
1576
        $this->dom->addChild(
1577
            $this->prodPred,
1578
            "xProd",
1579
            $std->xProd,
1580
            true,
1581
            "Descrição do produto predominante"
1582
        );
1583
        $this->dom->addChild(
1584
            $this->prodPred,
1585
            "cEAN",
1586
            $std->cEAN,
1587
            false,
1588
            "GTIN (Global Trade Item Number) do produto, antigo código EAN ou código de barras"
1589
        );
1590
        $this->dom->addChild(
1591
            $this->prodPred,
1592
            "NCM",
1593
            $std->NCM,
1594
            false,
1595
            "Código NCM"
1596
        );
1597
        if (!empty($std->infLotacao)) {
1598
            $this->dom->appChild($this->prodPred, $this->taginfLotacao($std->infLotacao), 'Falta tag "infLotacao"');
1599
        }
1600
        return $this->prodPred;
1601
    }
1602
1603
    /**
1604
     *
1605
     */
1606
    private function taginfLotacao(stdClass $std)
1607
    {
1608
        $possible = [
1609
            'infLocalCarrega',
1610
            'infLocalDescarrega'
1611
        ];
1612
        $std = $this->equilizeParameters($std, $possible);
1613
        $this->infLotacao = $this->dom->createElement("infLotacao");
1614
        if (!empty($std->infLocalCarrega)) {
1615
            $this->dom->appChild($this->infLotacao, $this->tagLocalCarrega($std->infLocalCarrega), 'Falta tag "infLocalCarrega"');
1616
        }
1617
        if (!empty($std->infLocalDescarrega)) {
1618
            $this->dom->appChild($this->infLotacao, $this->tagLocalDescarrega($std->infLocalDescarrega), 'Falta tag "infLocalDescarrega"');
1619
        }
1620
        return $this->infLotacao;
1621
    }
1622
1623
    /**
1624
     * Informações da localização do carregamento do MDF-e de carga lotação
1625
     *
1626
     */
1627
    private function tagLocalCarrega(stdClass $std)
1628
    {
1629
        $possible = [
1630
            'CEP',
1631
            'latitude',
1632
            'longitude'
1633
        ];
1634
        $std = $this->equilizeParameters($std, $possible);
1635
        $tagLocalCarrega = $this->dom->createElement("infLocalCarrega");
1636
        if (!empty($std->CEP)) {
1637
            $this->dom->addChild(
1638
                $tagLocalCarrega,
1639
                "CEP",
1640
                $std->CEP,
1641
                true,
1642
                "CEP onde foi carregado o MDF-e"
1643
            );
1644
        } else {
1645
            $this->dom->addChild(
1646
                $tagLocalCarrega,
1647
                "latitude",
1648
                $std->latitude,
1649
                true,
1650
                "Latitude do ponto geográfico onde foi carregado o MDF-e"
1651
            );
1652
            $this->dom->addChild(
1653
                $tagLocalCarrega,
1654
                "longitude",
1655
                $std->longitude,
1656
                true,
1657
                "Longitude do ponto geográfico onde foi carregado o MDF-e"
1658
            );
1659
        }
1660
        return $tagLocalCarrega;
1661
    }
1662
1663
    /**
1664
     * Informações da localização do descarregamento do MDF-e de carga lotação
1665
     */
1666
    private function tagLocalDescarrega(stdClass $std)
1667
    {
1668
        $possible = [
1669
            'CEP',
1670
            'latitude',
1671
            'longitude'
1672
        ];
1673
        $std = $this->equilizeParameters($std, $possible);
1674
        $tagLocalDescarrega = $this->dom->createElement("infLocalDescarrega");
1675
        if (!empty($std->CEP)) {
1676
            $this->dom->addChild(
1677
                $tagLocalDescarrega,
1678
                "CEP",
1679
                $std->CEP,
1680
                true,
1681
                "CEP onde foi descarregado o MDF-e"
1682
            );
1683
        } else {
1684
            $this->dom->addChild(
1685
                $tagLocalDescarrega,
1686
                "latitude",
1687
                $std->latitude,
1688
                true,
1689
                "Latitude do ponto geográfico onde foi descarregado o MDF-e"
1690
            );
1691
            $this->dom->addChild(
1692
                $tagLocalDescarrega,
1693
                "longitude",
1694
                $std->longitude,
1695
                true,
1696
                "Longitude do ponto geográfico onde foi descarregado o MDF-e"
1697
            );
1698
        }
1699
        return $tagLocalDescarrega;
1700
    }
1701
1702
    /**
1703
     * tagTot
1704
     * tag MDFe/infMDFe/tot
1705
     *
1706
     * @param  stdClass $std
1707
     * @return DOMElement
1708
     */
1709
    public function tagtot(stdClass $std)
1710
    {
1711
        $possible = [
1712
            'qCTe',
1713
            'qNFe',
1714
            'qMDFe',
1715
            'vCarga',
1716
            'cUnid',
1717
            'qCarga'
1718
        ];
1719
        $std = $this->equilizeParameters($std, $possible);
1720
        if (!isset($std->qCTe)) {
1721
            $std->qCTe = 0;
1722
            foreach ($this->infCTe as $infCTe) {
0 ignored issues
show
Bug introduced by
The expression $this->infCTe 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...
1723
                $std->qCTe += count($infCTe);
1724
            }
1725
            if ($std->qCTe == 0) {
1726
                $std->qCTe = '';
1727
            }
1728
        }
1729
        if (!isset($std->qNFe)) {
1730
            $std->qNFe = 0;
1731
            foreach ($this->infNFe as $infNFe) {
0 ignored issues
show
Bug introduced by
The expression $this->infNFe 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...
1732
                $std->qNFe += count($infNFe);
1733
            }
1734
            if ($std->qNFe == 0) {
1735
                $std->qNFe = '';
1736
            }
1737
        }
1738
        if (!isset($std->qMDFe)) {
1739
            $std->qMDFe = 0;
1740
            foreach ($this->infMDFeTransp as $infMDFeTransp) {
0 ignored issues
show
Bug introduced by
The expression $this->infMDFeTransp 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...
1741
                $std->qMDFe += count($infMDFeTransp);
1742
            }
1743
            if ($std->qMDFe == 0) {
1744
                $std->qMDFe = '';
1745
            }
1746
        }
1747
        $tot = $this->dom->createElement("tot");
1748
        $this->dom->addChild(
1749
            $tot,
1750
            "qCTe",
1751
            $std->qCTe,
1752
            false,
1753
            "Quantidade total de CT-e relacionados no Manifesto"
1754
        );
1755
        $this->dom->addChild(
1756
            $tot,
1757
            "qNFe",
1758
            $std->qNFe,
1759
            false,
1760
            "Quantidade total de NF-e relacionados no Manifesto"
1761
        );
1762
        $this->dom->addChild(
1763
            $tot,
1764
            "qMDFe",
1765
            $std->qMDFe,
1766
            false,
1767
            "Quantidade total de MDF-e relacionados no Manifesto"
1768
        );
1769
        $this->dom->addChild(
1770
            $tot,
1771
            "vCarga",
1772
            $std->vCarga,
1773
            true,
1774
            "Valor total da mercadoria/carga transportada"
1775
        );
1776
        $this->dom->addChild(
1777
            $tot,
1778
            "cUnid",
1779
            $std->cUnid,
1780
            true,
1781
            "Código da unidade de medida do Peso Bruto da Carga / Mercadoria Transportada"
1782
        );
1783
        $this->dom->addChild(
1784
            $tot,
1785
            "qCarga",
1786
            $std->qCarga,
1787
            true,
1788
            "Peso Bruto Total da Carga / Mercadoria Transportada"
1789
        );
1790
        $this->tot = $tot;
1791
        return $tot;
1792
    }
1793
1794
    /**
1795
     * tagLacres
1796
     * tag MDFe/infMDFe/lacres
1797
     *
1798
     * @param  stdClass $std
1799
     * @return DOMElement
1800
     */
1801
    public function taglacres(stdClass $std)
1802
    {
1803
        $possible = [
1804
            'nLacre'
1805
        ];
1806
        $std = $this->equilizeParameters($std, $possible);
1807
        $lacres = $this->dom->createElement("lacres");
1808
        $this->dom->addChild(
1809
            $lacres,
1810
            "nLacre",
1811
            $std->nLacre,
1812
            false,
1813
            "Número do lacre"
1814
        );
1815
        $this->lacres[] = $lacres; //array de DOMNode
1816
        return $this->lacres;
1817
    }
1818
1819
    /**
1820
     * taginfAdic
1821
     * Grupo de Informações Adicionais Z01 pai A01
1822
     * tag MDFe/infMDFe/infAdic (opcional)
1823
     *
1824
     * @param  stdClass $std
1825
     * @return DOMElement
1826
     */
1827
    public function taginfAdic(stdClass $std)
1828
    {
1829
        $possible = [
1830
            'infAdFisco',
1831
            'infCpl'
1832
        ];
1833
        $std = $this->equilizeParameters($std, $possible);
1834
        $infAdic = $this->dom->createElement("infAdic");
1835
        $this->dom->addChild(
1836
            $infAdic,
1837
            "infAdFisco",
1838
            $std->infAdFisco,
1839
            false,
1840
            "Informações Adicionais de Interesse do Fisco"
1841
        );
1842
        $this->dom->addChild(
1843
            $infAdic,
1844
            "infCpl",
1845
            $std->infCpl,
1846
            false,
1847
            "Informações Complementares de interesse do Contribuinte"
1848
        );
1849
        $this->infAdic = $infAdic;
1850
        return $infAdic;
1851
    }
1852
1853
    /**
1854
     * tagautXML
1855
     * tag MDFe/infMDFe/autXML
1856
     *
1857
     * Autorizados para download do XML do MDF-e
1858
     *
1859
     * @param  stdClass $std
1860
     * @return DOMElement
1861
     */
1862
    public function tagautXML(stdClass $std)
1863
    {
1864
        $possible = [
1865
            'CNPJ',
1866
            'CPF'
1867
        ];
1868
        $std = $this->equilizeParameters($std, $possible);
1869
        $autXML = $this->dom->createElement("autXML");
1870
        $this->dom->addChild(
1871
            $autXML,
1872
            "CNPJ",
1873
            $std->CNPJ,
1874
            false,
1875
            "CNPJ do autorizado"
1876
        );
1877
        $this->dom->addChild(
1878
            $autXML,
1879
            "CPF",
1880
            $std->CPF,
1881
            false,
1882
            "CPF do autorizado"
1883
        );
1884
        $this->autXML[] = $autXML;
1885
        return $this->autXML;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->autXML; of type string|DOMNode adds the type string to the return on line 1885 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagautXML of type DOMElement.
Loading history...
1886
    }
1887
1888
    /**
1889
     * buildInfModal
1890
     * tag MDFe/infMDFe/infModal
1891
     *
1892
     * @return DOMElement
1893
     */
1894
    private function buildInfModal()
1895
    {
1896
        $infModal = $this->dom->createElement("infModal");
1897
        $infModal->setAttribute("versaoModal", $this->versao);
1898
        $this->infModal = $infModal;
1899
        $modal = $this->ide->getElementsByTagName('modal')->item(0)->nodeValue;
1900
        /*
1901
         1 - Rodoviário;
1902
         2 - Aéreo;
1903
         3 - Aquaviário;
1904
         4 - Ferroviário;
1905
         */
1906
        if ($modal == '1') {
1907
            $this->tagrodo();
1908
        } elseif ($modal == '4') {
1909
            $this->tagferrov();
1910
        }
1911
        return $infModal;
1912
    }
1913
1914
    private function buildIde()
1915
    {
1916
        $this->dom->appChild($this->infMDFe, $this->ide, 'Falta tag "ide"');
1917
        foreach ($this->infPercurso as $percurso) {
0 ignored issues
show
Bug introduced by
The expression $this->infPercurso 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...
1918
            $node = $this->ide->getElementsByTagName('infPercurso')->item(0);
1919
            if (empty($node)) {
1920
                $node = $this->ide->getElementsByTagName('UFFim')->item(0);
1921
            } else {
1922
                if ($this->ide->getElementsByTagName('infPercurso')->length > 1) {
1923
                    $node = $this->ide->getElementsByTagName('infPercurso')->item($this->ide->getElementsByTagName('infPercurso')->length - 1);
1924
                }
1925
            }
1926
            $this->dom->insertAfter($percurso, $node);
1927
        }
1928
        $UFFim = $this->ide->getElementsByTagName('UFFim')->item(0);
1929
        foreach ($this->infMunCarrega as $munCarrega) {
0 ignored issues
show
Bug introduced by
The expression $this->infMunCarrega 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...
1930
            $this->dom->insertAfter($munCarrega, $UFFim);
1931
        }
1932
    }
1933
1934
    /**
1935
     * tagAereo
1936
     * tag MDFe/infMDFe/infModal/aereo
1937
     *
1938
     * @return DOMElement
1939
     */
1940
1941
    public function tagaereo(stdClass $std)
1942
    {
1943
        $possible = [
1944
            'nac',
1945
            'matr',
1946
            'nVoo',
1947
            'cAerEmb',
1948
            'cAerDes',
1949
            'dVoo'
1950
        ];
1951
        $std = $this->equilizeParameters($std, $possible);
1952
        $aereo = $this->dom->createElement("aereo");
1953
        $identificador = '[1] <aereo> - ';
1954
        $this->dom->addChild(
1955
            $aereo,
1956
            "nac",
1957
            $std->nac,
1958
            true,
1959
            $identificador . "Marca da Nacionalidade da aeronave"
1960
        );
1961
        $this->dom->addChild(
1962
            $aereo,
1963
            "matr",
1964
            $std->matr,
1965
            true,
1966
            $identificador . "Marca de Matrícula da aeronave"
1967
        );
1968
        $this->dom->addChild(
1969
            $aereo,
1970
            "nVoo",
1971
            $std->nVoo,
1972
            true,
1973
            $identificador . "Número do Vôo"
1974
        );
1975
        $this->dom->addChild(
1976
            $aereo,
1977
            "cAerEmb",
1978
            $std->cAerEmb,
1979
            true,
1980
            $identificador . "Aeródromo de Embarque - Código IATA"
1981
        );
1982
        $this->dom->addChild(
1983
            $aereo,
1984
            "cAerDes",
1985
            $std->cAerDes,
1986
            true,
1987
            $identificador . "Aeródromo de Destino - Código IATA"
1988
        );
1989
        $this->dom->addChild(
1990
            $aereo,
1991
            "dVoo",
1992
            $std->dVoo,
1993
            true,
1994
            $identificador . "Data do Vôo"
1995
        );
1996
        $this->aereo = $aereo;
1997
        return $aereo;
1998
    }
1999
2000
2001
    /**
2002
     * tagtrem
2003
     * tag MDFe/infMDFe/infModal/ferrov/trem
2004
     *
2005
     * @return DOMElement
2006
     */
2007
2008
    public function tagtrem(stdClass $std)
2009
    {
2010
        $possible = [
2011
            'xPref',
2012
            'dhTrem',
2013
            'xOri',
2014
            'xDest',
2015
            'qVag'
2016
        ];
2017
        $std = $this->equilizeParameters($std, $possible);
2018
        $trem = $this->dom->createElement("trem");
2019
        $identificador = '[1] <trem> - ';
2020
        $this->dom->addChild(
2021
            $trem,
2022
            "xPref",
2023
            $std->xPref,
2024
            true,
2025
            $identificador . "Prefixo do Trem"
2026
        );
2027
        $this->dom->addChild(
2028
            $trem,
2029
            "dhTrem",
2030
            $std->dhTrem,
2031
            false,
2032
            $identificador . "Data e hora de liberação do trem na origem"
2033
        );
2034
        $this->dom->addChild(
2035
            $trem,
2036
            "xOri",
2037
            $std->xOri,
2038
            true,
2039
            $identificador . "Origem do Trem"
2040
        );
2041
        $this->dom->addChild(
2042
            $trem,
2043
            "xDest",
2044
            $std->xDest,
2045
            true,
2046
            $identificador . "Destino do Trem"
2047
        );
2048
        $this->dom->addChild(
2049
            $trem,
2050
            "qVag",
2051
            $std->qVag,
2052
            true,
2053
            $identificador . "Quantidade de vagões carregados"
2054
        );
2055
        $this->trem = $trem;
2056
        return $trem;
2057
    }
2058
2059
    /**
2060
     * tagVag
2061
     * tag MDFe/infMDFe/infModal/ferrov/trem/vag
2062
     *
2063
     * @param string $serie
2064
     * @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...
2065
     * @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...
2066
     * @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...
2067
     *
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...
2068
     * @return DOMElement
2069
     */
2070
2071
    public function tagVag(stdClass $std)
2072
    {
2073
        $possible = [
2074
            'pesoBC',
2075
            'pesoR',
2076
            'tpVag',
2077
            'serie',
2078
            'nVag',
2079
            'nSeq',
2080
            'TU'
2081
        ];
2082
        $identificador = '[1] <vag> - ';
2083
        $std = $this->equilizeParameters($std, $possible);
2084
        $vag = $this->dom->createElement("vag");
2085
        $this->dom->addChild(
2086
            $vag,
2087
            "pesoBC",
2088
            $std->pesoBC,
2089
            true,
2090
            $identificador . "Peso Base de Cálculo de Frete em Toneladas"
2091
        );
2092
        $this->dom->addChild(
2093
            $vag,
2094
            "pesoR",
2095
            $std->pesoR,
2096
            true,
2097
            $identificador . "Peso Real em Toneladas"
2098
        );
2099
        $this->dom->addChild(
2100
            $vag,
2101
            "tpVag",
2102
            $std->tpVag,
2103
            false,
2104
            $identificador . "Tipo de Vagão"
2105
        );
2106
        $this->dom->addChild(
2107
            $vag,
2108
            "serie",
2109
            $std->serie,
2110
            true,
2111
            $identificador . "Serie de Identificação do vagão"
2112
        );
2113
        $this->dom->addChild(
2114
            $vag,
2115
            "nVag",
2116
            $std->nVag,
2117
            true,
2118
            $identificador . "Número de Identificação do vagão"
2119
        );
2120
        $this->dom->addChild(
2121
            $vag,
2122
            "nSeq",
2123
            $std->nSeq,
2124
            false,
2125
            $identificador . "Sequência do vagão na composição"
2126
        );
2127
        $this->dom->addChild(
2128
            $vag,
2129
            "TU",
2130
            $std->TU,
2131
            true,
2132
            $identificador . "Tonelada Útil"
2133
        );
2134
        $this->vag[] = $vag;
2135
        return $vag;
2136
    }
2137
2138
    /**
2139
     * tagaquav
2140
     * tag MDFe/infMDFe/infModal/aquav
2141
     *
2142
     * @param stdClass $std
2143
     * @return DOMElement
2144
     */
2145
2146
    public function tagaquav(stdClass $std)
2147
    {
2148
        $possible = [
2149
            'irin',
2150
            'tpEmb',
2151
            'cEmbar',
2152
            'xEmbar',
2153
            'nViag',
2154
            'cPrtEmb',
2155
            'cPrtDest',
2156
            'prtTrans',
2157
            'tpNav',
2158
            'infTermCarreg',
2159
            'infTermDescarreg',
2160
            'infEmbComb',
2161
            'infUnidCargaVazia',
2162
            'infUnidTranspVazia'
2163
        ];
2164
        $identificador = '[1] <aquav> - ';
2165
        $std = $this->equilizeParameters($std, $possible);
2166
        $aquav = $this->dom->createElement("aquav");
2167
        $this->dom->addChild(
2168
            $aquav,
2169
            "irin",
2170
            $std->irin,
2171
            true,
2172
            $identificador . "Irin do navio sempre deverá ser informado"
2173
        );
2174
        $this->dom->addChild(
2175
            $aquav,
2176
            "tpEmb",
2177
            $std->tpEmb,
2178
            true,
2179
            $identificador . "Código do tipo de embarcação"
2180
        );
2181
        $this->dom->addChild(
2182
            $aquav,
2183
            "cEmbar",
2184
            $std->cEmbar,
2185
            true,
2186
            $identificador . "Código da embarcação"
2187
        );
2188
        $this->dom->addChild(
2189
            $aquav,
2190
            "xEmbar",
2191
            $std->xEmbar,
2192
            true,
2193
            $identificador . "Nome da embarcação"
2194
        );
2195
        $this->dom->addChild(
2196
            $aquav,
2197
            "nViag",
2198
            $std->nViag,
2199
            true,
2200
            $identificador . "Número da Viagem"
2201
        );
2202
        $this->dom->addChild(
2203
            $aquav,
2204
            "cPrtEmb",
2205
            $std->cPrtEmb,
2206
            true,
2207
            $identificador . "Código do Porto de Embarque"
2208
        );
2209
        $this->dom->addChild(
2210
            $aquav,
2211
            "cPrtDest",
2212
            $std->cPrtDest,
2213
            true,
2214
            $identificador . "Código do Porto de Destino"
2215
        );
2216
        $this->dom->addChild(
2217
            $aquav,
2218
            "prtTrans",
2219
            $std->prtTrans,
2220
            false,
2221
            $identificador . "Porto de Transbordo"
2222
        );
2223
        $this->dom->addChild(
2224
            $aquav,
2225
            "tpNav",
2226
            $std->tpNav,
2227
            false,
2228
            $identificador . "Tipo de Navegação"
2229
        );
2230
        if ($std->infTermCarreg) {
2231
            foreach ($std->infTermCarreg as $value) {
2232
                $this->dom->appChild($aquav, $this->taginfTermCarreg($value), 'Falta tag "infTermCarreg"');
2233
            }
2234
        }
2235
        if ($std->infTermDescarreg) {
2236
            foreach ($std->infTermDescarreg as $value) {
2237
                $this->dom->appChild($aquav, $this->taginfTermDescarreg($value), 'Falta tag "infTermDescarreg"');
2238
            }
2239
        }
2240
        if ($std->infEmbComb) {
2241
            foreach ($std->infEmbComb as $value) {
2242
                $this->dom->appChild($aquav, $this->taginfEmbComb($value), 'Falta tag "infEmbComb"');
2243
            }
2244
        }
2245
        if ($std->infUnidCargaVazia) {
2246
            foreach ($std->infUnidCargaVazia as $value) {
2247
                $this->dom->appChild($aquav, $this->taginfUnidCargaVazia($value), 'Falta tag "infUnidCargaVazia"');
2248
            }
2249
        }
2250
        if ($std->infUnidTranspVazia) {
2251
            foreach ($std->infUnidTranspVazia as $value) {
2252
                $this->dom->appChild($aquav, $this->taginfUnidTranspVazia($value), 'Falta tag "infUnidTranspVazia"');
2253
            }
2254
        }
2255
        $this->aquav = $aquav;
2256
        return $aquav;
2257
    }
2258
2259
    /**
2260
     * infUnidTranspVazia
2261
     * tag MDFe/infMDFe/infModal/Aqua/infUnidTranspVazia
2262
     *
2263
     * @return DOMElement
2264
     */
2265
    public function taginfUnidTranspVazia(stdClass $std)
2266
    {
2267
        $possible = [
2268
            'idUnidTranspVazia',
2269
            'tpUnidTranspVazia'
2270
        ];
2271
        $identificador = '[1] <infUnidTranspVazia> - ';
2272
        $std = $this->equilizeParameters($std, $possible);
2273
        $infUnidTranspVazia = $this->dom->createElement("infUnidTranspVazia");
2274
        $this->dom->addChild(
2275
            $infUnidTranspVazia,
2276
            "idUnidTranspVazia",
2277
            $std->idUnidTranspVazia,
2278
            true,
2279
            $identificador . "dentificação da unidades de transporte vazia"
2280
        );
2281
        $this->dom->addChild(
2282
            $infUnidTranspVazia,
2283
            "tpUnidTranspVazia",
2284
            $std->tpUnidTranspVazia,
2285
            true,
2286
            $identificador . "Tipo da unidade de transporte vazia"
2287
        );
2288
        return $infUnidTranspVazia;
2289
    }
2290
2291
    /**
2292
     * infUnidCargaVazia
2293
     * tag MDFe/infMDFe/infModal/Aqua/infUnidCargaVazia
2294
     *
2295
     * @return DOMElement
2296
     */
2297
    public function taginfUnidCargaVazia(stdClass $std)
2298
    {
2299
        $possible = [
2300
            'idUnidCargaVazia',
2301
            'tpUnidCargaVazia'
2302
        ];
2303
        $identificador = '[1] <infUnidCargaVazia> - ';
2304
        $std = $this->equilizeParameters($std, $possible);
2305
        $infUnidCargaVazia = $this->dom->createElement("infUnidCargaVazia");
2306
        $this->dom->addChild(
2307
            $infUnidCargaVazia,
2308
            "idUnidCargaVazia",
2309
            $std->idUnidCargaVazia,
2310
            true,
2311
            $identificador . "Identificação da unidades de carga vazia"
2312
        );
2313
        $this->dom->addChild(
2314
            $infUnidCargaVazia,
2315
            "tpUnidCargaVazia",
2316
            $std->tpUnidCargaVazia,
2317
            true,
2318
            $identificador . "Tipo da unidade de carga vazia"
2319
        );
2320
        return $infUnidCargaVazia;
2321
    }
2322
2323
    /**
2324
     * taginfTermDescarreg
2325
     * tag MDFe/infMDFe/infModal/Aqua/infTermDescarreg
2326
     *
2327
     * @return DOMElement
2328
     */
2329
    public function taginfTermDescarreg(stdClass $std)
2330
    {
2331
        $possible = [
2332
            'cTermDescarreg',
2333
            'xTermDescarreg'
2334
        ];
2335
        $identificador = '[1] <infTermDescarreg> - ';
2336
        $std = $this->equilizeParameters($std, $possible);
2337
        $infTermDescarreg = $this->dom->createElement("infTermDescarreg");
2338
        $this->dom->addChild(
2339
            $infTermDescarreg,
2340
            "cTermDescarreg",
2341
            $std->cTermDescarreg,
2342
            true,
2343
            $identificador . "Código do Terminal de Descarregamento"
2344
        );
2345
        $this->dom->addChild(
2346
            $infTermDescarreg,
2347
            "xTermDescarreg",
2348
            $std->xTermDescarreg,
2349
            true,
2350
            $identificador . "Nome do Terminal de Descarregamento"
2351
        );
2352
        return $infTermDescarreg;
2353
    }
2354
2355
    /**
2356
     * tagInfTermCarreg
2357
     * tag MDFe/infMDFe/infModal/aquav/infTermCarreg
2358
     *
2359
     * @return DOMElement
2360
     */
2361
    public function taginfTermCarreg(stdClass $std)
2362
    {
2363
        $possible = [
2364
            'cTermCarreg',
2365
            'xTermCarreg'
2366
        ];
2367
        $identificador = '[1] <infTermCarreg> - ';
2368
        $std = $this->equilizeParameters($std, $possible);
2369
        $infTermCarreg = $this->dom->createElement("infTermCarreg");
2370
2371
        $this->dom->addChild(
2372
            $infTermCarreg,
2373
            "cTermCarreg",
2374
            $std->cTermCarreg,
2375
            true,
2376
            $identificador . "Código do Terminal de Carregamento"
2377
        );
2378
        $this->dom->addChild(
2379
            $infTermCarreg,
2380
            "xTermCarreg",
2381
            $std->xTermCarreg,
2382
            true,
2383
            $identificador . "Nome do Terminal de Carregamento"
2384
        );
2385
        return $infTermCarreg;
2386
    }
2387
2388
    /**
2389
     * tagInfTermCarreg
2390
     * tag MDFe/infMDFe/infModal/aquav/infEmbComb
2391
     *
2392
     * @param stdClass $std
2393
     * @return DOMElement
2394
     */
2395
    public function taginfEmbComb(stdClass $std)
2396
    {
2397
        $possible = [
2398
            'cEmbComb',
2399
            'xBalsa'
2400
        ];
2401
        $identificador = '[1] <infEmbComb> - ';
2402
        $std = $this->equilizeParameters($std, $possible);
2403
        $infEmbComb = $this->dom->createElement("infEmbComb");
2404
2405
        $this->dom->addChild(
2406
            $infEmbComb,
2407
            "cEmbComb",
2408
            $std->cEmbComb,
2409
            true,
2410
            $identificador . "Código da embarcação do comboio"
2411
        );
2412
        $this->dom->addChild(
2413
            $infEmbComb,
2414
            "xBalsa",
2415
            $std->xBalsa,
2416
            true,
2417
            $identificador . "Identificador da Balsa"
2418
        );
2419
        return $infEmbComb;
2420
    }
2421
2422
    /**
2423
     * condutor
2424
     * tag MDFe/infMDFe/infModal/rodo/veicTracao/condutor
2425
     *
2426
     * @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...
2427
     *
2428
     * @return DOMElement
2429
     */
2430
    private function tagcondutor(stdClass $std)
2431
    {
2432
        $possible = [
2433
            'xNome',
2434
            'CPF'
2435
        ];
2436
        $std = $this->equilizeParameters($std, $possible);
2437
        $condutor = $this->dom->createElement("condutor");
2438
        $identificador = '[4] <condutor> - ';
2439
        $this->dom->addChild(
2440
            $condutor,
2441
            "xNome",
2442
            $std->xNome,
2443
            true,
2444
            $identificador . "Nome do Condutor "
2445
        );
2446
        $this->dom->addChild(
2447
            $condutor,
2448
            "CPF",
2449
            $std->CPF,
2450
            true,
2451
            $identificador . "CPF do Condutor "
2452
        );
2453
        return $condutor;
2454
    }
2455
2456
    /**
2457
     * tagVeicTracao
2458
     * tag MDFe/infMDFe/infModal/rodo/veicTracao
2459
     *
2460
     * @param  stdClass $std
2461
     * @return DOMElement
2462
     */
2463
    public function tagveicTracao(stdClass $std)
2464
    {
2465
        $possible = [
2466
            'cInt',
2467
            'placa',
2468
            'RENAVAM',
2469
            'tara',
2470
            'capKG',
2471
            'capM3',
2472
            'prop',
2473
            'tpRod',
2474
            'tpCar',
2475
            'UF',
2476
            'condutor'
2477
        ];
2478
        $std = $this->equilizeParameters($std, $possible);
2479
        $veicTracao = $this->dom->createElement("veicTracao");
2480
        $identificador = '[4] <disp> - ';
2481
        $this->dom->addChild(
2482
            $veicTracao,
2483
            "cInt",
2484
            $std->cInt,
2485
            false,
2486
            $identificador . "Código interno do veículo"
2487
        );
2488
        $this->dom->addChild(
2489
            $veicTracao,
2490
            "placa",
2491
            $std->placa,
2492
            true,
2493
            $identificador . "Placa do veículo"
2494
        );
2495
        $this->dom->addChild(
2496
            $veicTracao,
2497
            "RENAVAM",
2498
            $std->RENAVAM,
2499
            false,
2500
            $identificador . "RENAVAM"
2501
        );
2502
        $this->dom->addChild(
2503
            $veicTracao,
2504
            "tara",
2505
            $std->tara,
2506
            true,
2507
            $identificador . "Tara em KG"
2508
        );
2509
        $this->dom->addChild(
2510
            $veicTracao,
2511
            "capKG",
2512
            $std->capKG,
2513
            false,
2514
            $identificador . "Capacidade em KG"
2515
        );
2516
        $this->dom->addChild(
2517
            $veicTracao,
2518
            "capM3",
2519
            $std->capM3,
2520
            false,
2521
            $identificador . "Capacidade em M3"
2522
        );
2523
        if ($std->prop != null) {
2524
            $possible = [
2525
                'CPF',
2526
                'CNPJ',
2527
                'RNTRC',
2528
                'xNome',
2529
                'IE',
2530
                'UF',
2531
                'tpProp'
2532
            ];
2533
            $identificadorProp = '[4] <prop> - ';
2534
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2535
            $prop = $this->dom->createElement("prop");
2536
            if ($stdprop->CPF) {
2537
                $this->dom->addChild(
2538
                    $prop,
2539
                    "CPF",
2540
                    $stdprop->CPF,
2541
                    true,
2542
                    $identificadorProp . "Número do CPF"
2543
                );
2544
            } else {
2545
                $this->dom->addChild(
2546
                    $prop,
2547
                    "CNPJ",
2548
                    $stdprop->CNPJ,
2549
                    true,
2550
                    $identificadorProp . "Número do CNPJ"
2551
                );
2552
            }
2553
            $this->dom->addChild(
2554
                $prop,
2555
                "RNTRC",
2556
                $stdprop->RNTRC,
2557
                true,
2558
                $identificadorProp . "RNTRC"
2559
            );
2560
            $this->dom->addChild(
2561
                $prop,
2562
                "xNome",
2563
                $stdprop->xNome,
2564
                true,
2565
                $identificadorProp . "Razão Social"
2566
            );
2567
            $this->dom->addChild(
2568
                $prop,
2569
                "IE",
2570
                $stdprop->IE,
2571
                true,
2572
                $identificadorProp . "Inscrição Estadual",
2573
                true
2574
            );
2575
            $this->dom->addChild(
2576
                $prop,
2577
                "UF",
2578
                $stdprop->UF,
2579
                true,
2580
                $identificadorProp . "Unidade da Federação"
2581
            );
2582
            $this->dom->addChild(
2583
                $prop,
2584
                "tpProp",
2585
                $stdprop->tpProp,
2586
                true,
2587
                $identificadorProp . "Tipo Proprietário"
2588
            );
2589
            $this->dom->appChild($veicTracao, $prop, 'Falta tag "veicTracao"');
2590
        }
2591
        if ($std->condutor) {
2592
            foreach ($std->condutor as $value) {
2593
                $this->dom->appChild($veicTracao, $this->tagcondutor($value), 'Falta tag "condutor"');
2594
            }
2595
        }
2596
        $this->dom->addChild(
2597
            $veicTracao,
2598
            "tpRod",
2599
            $std->tpRod,
2600
            true,
2601
            $identificador . "Tipo de rodado"
2602
        );
2603
        $this->dom->addChild(
2604
            $veicTracao,
2605
            "tpCar",
2606
            $std->tpCar,
2607
            true,
2608
            $identificador . "Tipo de carroceria"
2609
        );
2610
        $this->dom->addChild(
2611
            $veicTracao,
2612
            "UF",
2613
            $std->UF,
2614
            true,
2615
            $identificador . "UF de licenciamento do veículo"
2616
        );
2617
        $this->veicTracao = $veicTracao;
2618
        return $veicTracao;
2619
    }
2620
2621
    /**
2622
     * tagVeicReboque
2623
     * tag MDFe/infMDFe/infModal/rodo/VeicReboque
2624
     *
2625
     * @param  stdClass $std
2626
     * @return DOMElement
2627
     */
2628
    public function tagveicReboque(stdClass $std)
2629
    {
2630
        $possible = [
2631
            'cInt',
2632
            'placa',
2633
            'RENAVAM',
2634
            'tara',
2635
            'capKG',
2636
            'capM3',
2637
            'prop',
2638
            'tpCar',
2639
            'UF'
2640
        ];
2641
        $std = $this->equilizeParameters($std, $possible);
2642
        $veicReboque = $this->dom->createElement("veicReboque");
2643
        $identificador = '[4] <veicReboque> - ';
2644
        $this->dom->addChild(
2645
            $veicReboque,
2646
            "cInt",
2647
            $std->cInt,
2648
            false,
2649
            $identificador . "Código interno do veículo"
2650
        );
2651
        $this->dom->addChild(
2652
            $veicReboque,
2653
            "placa",
2654
            $std->placa,
2655
            true,
2656
            $identificador . "Placa do veículo"
2657
        );
2658
        $this->dom->addChild(
2659
            $veicReboque,
2660
            "RENAVAM",
2661
            $std->RENAVAM,
2662
            false,
2663
            $identificador . "RENAVAM"
2664
        );
2665
        $this->dom->addChild(
2666
            $veicReboque,
2667
            "tara",
2668
            $std->tara,
2669
            true,
2670
            $identificador . "Tara em KG"
2671
        );
2672
        $this->dom->addChild(
2673
            $veicReboque,
2674
            "capKG",
2675
            $std->capKG,
2676
            false,
2677
            $identificador . "Capacidade em KG"
2678
        );
2679
        $this->dom->addChild(
2680
            $veicReboque,
2681
            "capM3",
2682
            $std->capM3,
2683
            false,
2684
            $identificador . "Capacidade em M3"
2685
        );
2686
        if ($std->prop != null) {
2687
            $identificadorprop = '[4] <prop> - ';
2688
            $possible = [
2689
                'CPF',
2690
                'CNPJ',
2691
                'RNTRC',
2692
                'xNome',
2693
                'IE',
2694
                'UF',
2695
                'tpProp'
2696
            ];
2697
            $stdprop = $this->equilizeParameters($std->prop, $possible);
2698
            $prop = $this->dom->createElement("prop");
2699
            if ($stdprop->CPF) {
2700
                $this->dom->addChild(
2701
                    $prop,
2702
                    "CPF",
2703
                    $stdprop->CPF,
2704
                    true,
2705
                    $identificadorprop . "Número do CPF"
2706
                );
2707
            } else {
2708
                $this->dom->addChild(
2709
                    $prop,
2710
                    "CNPJ",
2711
                    $stdprop->CNPJ,
2712
                    true,
2713
                    $identificadorprop . "Número do CNPJ"
2714
                );
2715
            }
2716
            $this->dom->addChild(
2717
                $prop,
2718
                "RNTRC",
2719
                $stdprop->RNTRC,
2720
                true,
2721
                $identificadorprop . "RNTRC"
2722
            );
2723
            $this->dom->addChild(
2724
                $prop,
2725
                "xNome",
2726
                $stdprop->xNome,
2727
                true,
2728
                $identificadorprop . "Razão Social"
2729
            );
2730
            $this->dom->addChild(
2731
                $prop,
2732
                "IE",
2733
                $stdprop->IE,
2734
                true,
2735
                $identificadorprop . "Inscrição Estadual"
2736
            );
2737
            $this->dom->addChild(
2738
                $prop,
2739
                "UF",
2740
                $stdprop->UF,
2741
                true,
2742
                $identificadorprop . "Unidade da Federação"
2743
            );
2744
            $this->dom->addChild(
2745
                $prop,
2746
                "tpProp",
2747
                $stdprop->tpProp,
2748
                true,
2749
                $identificadorprop . "Tipo Proprietário"
2750
            );
2751
            $this->dom->appChild($veicReboque, $prop, 'Falta tag "veicReboque"');
2752
        }
2753
        $this->dom->addChild(
2754
            $veicReboque,
2755
            "tpCar",
2756
            $std->tpCar,
2757
            true,
2758
            $identificador . "Tipo de carroceria"
2759
        );
2760
        $this->dom->addChild(
2761
            $veicReboque,
2762
            "UF",
2763
            $std->UF,
2764
            true,
2765
            $identificador . "UF de licenciamento do veículo"
2766
        );
2767
        $this->veicReboque[] = $veicReboque;
2768
        return $veicReboque;
2769
    }
2770
2771
    /**
2772
     * tagcodAgPorto
2773
     * tag MDFe/infMDFe/infModal/rodo/codAgPorto
2774
     *
2775
     * @param  stdClass $std
2776
     * @return DOMElement
2777
     */
2778
    public function tagcodAgPorto(stdClass $std)
2779
    {
2780
        $possible = [
2781
            'codAgPorto'
2782
        ];
2783
        $std = $this->equilizeParameters($std, $possible);
2784
        $this->dom->addChild(
2785
            $this->rodo,
2786
            "codAgPorto",
2787
            $std->codAgPorto,
2788
            false,
2789
            "Código de Agendamento no porto"
2790
        );
2791
        return $this->rodo;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->rodo; of type string|DOMNode adds the type string to the return on line 2791 which is incompatible with the return type documented by NFePHP\MDFe\Make::tagcodAgPorto of type DOMElement.
Loading history...
2792
    }
2793
2794
    /**
2795
     * taglacRodo
2796
     * tag MDFe/infMDFe/infModal/rodo/lacRodo
2797
     *
2798
     * @param  stdClass $std
2799
     * @return DOMElement
2800
     */
2801
    public function taglacRodo(stdClass $std)
2802
    {
2803
        $possible = [
2804
            'nLacre'
2805
        ];
2806
        $std = $this->equilizeParameters($std, $possible);
2807
        $lacRodo = $this->dom->createElement("lacRodo");
2808
        $this->dom->addChild(
2809
            $lacRodo,
2810
            "nLacre",
2811
            $std->nLacre,
2812
            true,
2813
            "Número do Lacre"
2814
        );
2815
        $this->lacRodo[] = $lacRodo;
2816
        return $lacRodo;
2817
    }
2818
2819
    /**
2820
     * Informações do Responsável técnico ZD01 pai A01
2821
     * tag NFe/infNFe/infRespTec (opcional)
2822
     * @param stdClass $std
2823
     * @return DOMElement
2824
     * @throws RuntimeException
2825
     */
2826
    public function taginfRespTec(stdClass $std)
2827
    {
2828
        $possible = [
2829
            'CNPJ',
2830
            'xContato',
2831
            'email',
2832
            'fone',
2833
            'CSRT',
2834
            'idCSRT'
2835
        ];
2836
2837
        $std = $this->equilizeParameters($std, $possible);
2838
        $infRespTec = $this->dom->createElement("infRespTec");
2839
        $this->dom->addChild(
2840
            $infRespTec,
2841
            "CNPJ",
2842
            $std->CNPJ,
2843
            true,
2844
            "Informar o CNPJ da pessoa jurídica responsável pelo sistema "
2845
            . "utilizado na emissão do documento fiscal eletrônico"
2846
        );
2847
        $this->dom->addChild(
2848
            $infRespTec,
2849
            "xContato",
2850
            $std->xContato,
2851
            true,
2852
            "Informar o nome da pessoa a ser contatada na empresa desenvolvedora "
2853
            . "do sistema utilizado na emissão do documento fiscal eletrônico"
2854
        );
2855
        $this->dom->addChild(
2856
            $infRespTec,
2857
            "email",
2858
            $std->email,
2859
            true,
2860
            "Informar o e-mail da pessoa a ser contatada na empresa "
2861
            . "desenvolvedora do sistema."
2862
        );
2863
        $this->dom->addChild(
2864
            $infRespTec,
2865
            "fone",
2866
            $std->fone,
2867
            true,
2868
            "Informar o telefone da pessoa a ser contatada na empresa "
2869
            . "desenvolvedora do sistema."
2870
        );
2871
        if (!empty($std->CSRT) && !empty($std->idCSRT)) {
2872
            $this->csrt = $std->CSRT;
0 ignored issues
show
Bug introduced by
The property csrt 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...
2873
            $this->dom->addChild(
2874
                $infRespTec,
2875
                "idCSRT",
2876
                $std->idCSRT,
2877
                true,
2878
                "Identificador do CSRT utilizado para montar o hash do CSRT"
2879
            );
2880
            $this->dom->addChild(
2881
                $infRespTec,
2882
                "hashCSRT",
2883
                $std->CSRT,
2884
                true,
2885
                "hash do CSRT"
2886
            );
2887
        }
2888
        $this->infRespTec = $infRespTec;
0 ignored issues
show
Bug introduced by
The property infRespTec 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...
2889
        return $infRespTec;
2890
    }
2891
2892
    /**
2893
     * Metodo responsavel para montagem da tag ingPag - Informações do Pagamento do Frete
2894
     *
2895
     * @param stdClass $std
2896
     * @return DOMElement
2897
     * @throws RuntimeException
2898
     */
2899
    public function taginfPag(stdClass $std)
2900
    {
2901
        $possible = [
2902
            'xNome',
2903
            'CPF',
2904
            'CNPJ',
2905
            'idEstrangeiro',
2906
            'Comp',
2907
            'vContrato',
2908
            'indPag',
2909
            'infPrazo',
2910
            'infBanc'
2911
        ];
2912
        $std = $this->equilizeParameters($std, $possible);
2913
        $infPag = $this->dom->createElement("infPag");
2914
        $identificador = '[4] <infPag> - ';
2915
        $this->dom->addChild(
2916
            $infPag,
2917
            "xNome",
2918
            $std->xNome,
2919
            true,
2920
            $identificador . "Nome do responsável pelo pgto"
2921
        );
2922
        if (!empty($std->CPF)) {
2923
            $this->dom->addChild(
2924
                $infPag,
2925
                "CPF",
2926
                $std->CPF,
2927
                true,
2928
                $identificador . "Número do CPF do responsável pelo pgto"
2929
            );
2930
        } else if (!empty($std->CNPJ)) {
2931
            $this->dom->addChild(
2932
                $infPag,
2933
                "CNPJ",
2934
                $std->CNPJ,
2935
                true,
2936
                $identificador . "Número do CNPJ do responsável pelo pgto"
2937
            );
2938
        } else {
2939
            $this->dom->addChild(
2940
                $infPag,
2941
                "idEstrangeiro",
2942
                $std->idEstrangeiro,
2943
                true,
2944
                $identificador . "Identificador do responsável pelo pgto em caso de ser estrangeiro"
2945
            );
2946
        }
2947
        foreach ($std->Comp as $value) {
2948
            $this->dom->appChild($infPag, $this->CompPag($value), 'Falta tag "Comp"');
2949
        }
2950
        $this->dom->addChild(
2951
            $infPag,
2952
            "vContrato",
2953
            $std->vContrato,
2954
            true,
2955
            $identificador . "Valor total do contrato"
2956
        );
2957
        $this->dom->addChild(
2958
            $infPag,
2959
            "indPag",
2960
            $std->indPag,
2961
            true,
2962
            $identificador . "Indicador da Forma de Pagamento"
2963
        );
2964
        if ($std->indPag == 1) {
2965
            foreach ($std->infPrazo as $value) {
2966
                $this->dom->appChild($infPag, $this->infPrazo($value), 'Falta tag "infPrazo"');
2967
            }
2968
        }
2969
        $this->dom->appChild($infPag, $this->infBanc($std->infBanc), 'Falta tag "infBanc"');
2970
        $this->infPag[] = $infPag;
2971
        return $infPag;
2972
    }
2973
2974
    /**
2975
     * Componentes do Pagamento do Frete
2976
     * @param stdClass
2977
     *
2978
     */
2979
    private function CompPag(stdClass $std)
2980
    {
2981
        $possible = [
2982
            'tpComp',
2983
            'vComp',
2984
            'xComp'
2985
        ];
2986
        $stdComp = $this->equilizeParameters($std, $possible);
2987
        $comp = $this->dom->createElement("Comp");
2988
        $identificador = '[4] <Comp> - ';
2989
        $this->dom->addChild(
2990
            $comp,
2991
            "tpComp",
2992
            $stdComp->tpComp,
2993
            true,
2994
            $identificador . "Tipo do Componente"
2995
        );
2996
        $this->dom->addChild(
2997
            $comp,
2998
            "vComp",
2999
            $stdComp->vComp,
3000
            true,
3001
            $identificador . "Valor do Componente"
3002
        );
3003
        $this->dom->addChild(
3004
            $comp,
3005
            "xComp",
3006
            $stdComp->xComp,
3007
            false,
3008
            $identificador . "Descrição do componente do tipo Outros"
3009
        );
3010
        return $comp;
3011
    }
3012
3013
    /***
3014
     * Informações do pagamento a prazo. Obs: Informar somente se indPag for à Prazo.
3015
     *
3016
     */
3017
    private function infPrazo(stdClass $std)
3018
    {
3019
        $possible = [
3020
            'nParcela',
3021
            'dVenc',
3022
            'vParcela'
3023
        ];
3024
        $stdPraz = $this->equilizeParameters($std, $possible);
3025
        $prazo = $this->dom->createElement("infPrazo");
3026
        $identificador = '[4] <infPrazo> - ';
3027
        $this->dom->addChild(
3028
            $prazo,
3029
            "nParcela",
3030
            $stdPraz->nParcela,
3031
            false,
3032
            $identificador . "Número da parcela"
3033
        );
3034
        $this->dom->addChild(
3035
            $prazo,
3036
            "dVenc",
3037
            $stdPraz->dVenc,
3038
            false,
3039
            $identificador . "Data de vencimento da Parcela (AAAA-MMDD)"
3040
        );
3041
        $this->dom->addChild(
3042
            $prazo,
3043
            "vParcela",
3044
            $stdPraz->vParcela,
3045
            true,
3046
            $identificador . "Valor da Parcela"
3047
        );
3048
        return $prazo;
3049
    }
3050
3051
    /**
3052
     * Informações bancárias.
3053
     *
3054
     */
3055
    private function infBanc(stdClass $std)
3056
    {
3057
        $possible = [
3058
            'codBanco',
3059
            'codAgencia',
3060
            'CNPJIPEF'
3061
        ];
3062
        $stdBanco = $this->equilizeParameters($std, $possible);
3063
        $banco = $this->dom->createElement("infBanc");
3064
        $identificador = '[4] <infBanc> - ';
3065
        if (!empty($stdBanco->codBanco)) {
3066
            $this->dom->addChild(
3067
                $banco,
3068
                "codBanco",
3069
                $stdBanco->codBanco,
3070
                true,
3071
                $identificador . "Número do banco"
3072
            );
3073
            $this->dom->addChild(
3074
                $banco,
3075
                "codAgencia",
3076
                $stdBanco->codAgencia,
3077
                true,
3078
                $identificador . "Número da Agência"
3079
            );
3080
        } else {
3081
            $this->dom->addChild(
3082
                $banco,
3083
                "CNPJIPEF",
3084
                $stdBanco->CNPJIPEF,
3085
                true,
3086
                $identificador . "Número do CNPJ da Instituição de pagamento Eletrônico do Frete"
3087
            );
3088
        }
3089
        return $banco;
3090
    }
3091
3092
    /**
3093
     * buildMDFe
3094
     * Tag raiz da MDFe
3095
     * tag MDFe DOMNode
3096
     * Função chamada pelo método [ monta ]
3097
     *
3098
     * @return DOMElement
3099
     */
3100
    protected function buildMDFe()
3101
    {
3102
        if (empty($this->MDFe)) {
3103
            $this->MDFe = $this->dom->createElement("MDFe");
3104
            $this->MDFe->setAttribute("xmlns", "http://www.portalfiscal.inf.br/mdfe");
3105
        }
3106
        return $this->MDFe;
3107
    }
3108
3109
    /**
3110
     * checkMDFKey
3111
     * Remonta a chave do MDFe de 44 digitos com base em seus dados
3112
     * Isso é útil no caso da chave informada estar errada
3113
     * se a chave estiver errada a mesma é substituida
3114
     *
3115
     * @param object $dom
3116
     */
3117
    private function checkMDFKey($dom)
3118
    {
3119
        $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
3120
        $ide = $dom->getElementsByTagName("ide")->item(0);
3121
        $emit = $dom->getElementsByTagName("emit")->item(0);
3122
        $cUF = $ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3123
        $dhEmi = $ide->getElementsByTagName('dhEmi')->item(0)->nodeValue;
3124
        if (!empty($emit->getElementsByTagName('CNPJ')->item(0)->nodeValue)) {
3125
            $doc = $emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3126
        } else {
3127
            $doc = $emit->getElementsByTagName('CPF')->item(0)->nodeValue;
3128
        }
3129
        $mod = $ide->getElementsByTagName('mod')->item(0)->nodeValue;
3130
        $serie = $ide->getElementsByTagName('serie')->item(0)->nodeValue;
3131
        $nMDF = $ide->getElementsByTagName('nMDF')->item(0)->nodeValue;
3132
        $tpEmis = $ide->getElementsByTagName('tpEmis')->item(0)->nodeValue;
3133
        $cNF = $ide->getElementsByTagName('cMDF')->item(0)->nodeValue;
3134
        $chave = str_replace('MDFe', '', $infMDFe->getAttribute("Id"));
3135
        $dt = new \DateTime($dhEmi);
3136
        $chaveMontada = Keys::build(
3137
            $cUF,
3138
            $dt->format('y'),
3139
            $dt->format('m'),
3140
            $doc,
3141
            $mod,
3142
            $serie,
3143
            $nMDF,
3144
            $tpEmis,
3145
            $cNF
3146
        );
3147
3148
        //caso a chave contida na NFe esteja errada
3149
        //substituir a chave
3150
        if ($chaveMontada != $chave) {
3151
            $ide->getElementsByTagName('cDV')->item(0)->nodeValue = substr($chaveMontada, -1);
3152
            $infMDFe = $dom->getElementsByTagName("infMDFe")->item(0);
3153
            $infMDFe->setAttribute("Id", "MDFe" . $chaveMontada);
3154
            $infMDFe->setAttribute("versao", $this->versao);
3155
            $this->chMDFe = $chaveMontada;
3156
        }
3157
    }
3158
3159
    /**
3160
     * Retorna os erros detectados
3161
     * @return array
3162
     */
3163
    public function getErrors()
3164
    {
3165
        return $this->errors;
3166
    }
3167
3168
    /**
3169
     * Includes missing or unsupported properties in stdClass
3170
     * Replace all unsuported chars
3171
     *
3172
     * @param  stdClass $std
3173
     * @param  array $possible
3174
     * @return stdClass
3175
     */
3176
    private function equilizeParameters(stdClass $std, $possible)
3177
    {
3178
        return Strings::equilizeParameters($std, $possible, $this->replaceAccentedChars);
0 ignored issues
show
Bug introduced by
The method equilizeParameters() does not seem to exist on object<NFePHP\Common\Strings>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3179
    }
3180
}