Passed
Pull Request — master (#128)
by
unknown
02:06
created

Make::infPrazo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 1

Importance

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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