Passed
Push — master ( 2b0481...2e1257 )
by
unknown
01:01 queued 11s
created

Make::infPrazo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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