EvtCadIntermediario::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.8666
cc 1
nc 1
nop 4
1
<?php
2
3
namespace NFePHP\eFinanc\Factories;
4
5
use NFePHP\eFinanc\Common\Factory;
6
use NFePHP\eFinanc\Common\FactoryInterface;
7
use NFePHP\eFinanc\Common\FactoryId;
8
use NFePHP\Common\Certificate;
9
use stdClass;
10
11
class EvtCadIntermediario extends Factory implements FactoryInterface
12
{
13
    /**
14
     * Constructor
15
     * @param string $config
16
     * @param stdClass $std
17
     * @param Certificate $certificate
18
     * @param string $data
19
     */
20
    public function __construct(
21
        $config,
22
        stdClass $std,
23
        Certificate $certificate = null,
24
        $data = ''
25
    ) {
26
        $params = new \stdClass();
27
        $params->evtName = 'evtCadIntermediario';
28
        $params->evtTag = 'evtCadIntermediario';
29
        $params->evtAlias = 'F-2010';
30
        parent::__construct($config, $std, $params, $certificate, $data);
31
    }
32
33
    protected function toNode()
34
    {
35
        $ideDeclarante = $this->node->getElementsByTagName('ideDeclarante')->item(0);
36
        //o idEvento pode variar de evento para evento
37
        //então cada factory individualmente terá de construir o seu
38
        $ideEvento = $this->dom->createElement("ideEvento");
39
        $this->dom->addChild(
40
            $ideEvento,
41
            "indRetificacao",
42
            $this->std->indretificacao,
43
            true
44
        );
45
        $this->dom->addChild(
46
            $ideEvento,
47
            "nrRecibo",
48
            isset($this->std->nrrecibo) ? $this->std->nrrecibo : null,
49
            false
50
        );
51
        $this->dom->addChild(
52
            $ideEvento,
53
            "tpAmb",
54
            (string) $this->tpAmb,
55
            true
56
        );
57
        $this->dom->addChild(
58
            $ideEvento,
59
            "aplicEmi",
60
            '1',
61
            true
62
        );
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "verAplic",
66
            $this->verAplic,
67
            true
68
        );
69
        $this->node->insertBefore($ideEvento, $ideDeclarante);
70
        
71
        $infoIntermediario = $this->dom->createElement("infoIntermediario");
72
        $this->dom->addChild(
73
            $infoIntermediario,
74
            "GIIN",
75
            !empty($this->std->giin) ? $this->std->giin : null,
76
            false
77
        );
78
        $this->dom->addChild(
79
            $infoIntermediario,
80
            "tpNI",
81
            !empty($this->std->tpni) ? $this->std->tpni : null,
82
            false
83
        );
84
        $this->dom->addChild(
85
            $infoIntermediario,
86
            "NIIntermediario",
87
            !empty($this->std->niintermediario) ? $this->std->niintermediario : null,
88
            false
89
        );
90
        $this->dom->addChild(
91
            $infoIntermediario,
92
            "nomeIntermediario",
93
            $this->std->nomeintermediario,
94
            true
95
        );
96
        $endereco = $this->dom->createElement("endereco");
97
        $this->dom->addChild(
98
            $endereco,
99
            "enderecoLivre",
100
            $this->std->endereco->enderecolivre,
101
            true
102
        );
103
        $this->dom->addChild(
104
            $endereco,
105
            "municipio",
106
            $this->std->endereco->municipio,
107
            true
108
        );
109
        $this->dom->addChild(
110
            $endereco,
111
            "pais",
112
            $this->std->endereco->pais,
113
            true
114
        );
115
        $infoIntermediario->appendChild($endereco);
116
        $this->dom->addChild(
117
            $infoIntermediario,
118
            "paisResidencia",
119
            $this->std->paisresidencia,
120
            true
121
        );
122
        $this->node->appendChild($infoIntermediario);
123
        
124
        
125
        //finalização do xml
126
        $this->eFinanceira->appendChild($this->node);
127
        //$this->xml = $this->dom->saveXML($this->eFinanceira);
128
        $this->sign($this->evtTag);
129
    }
130
}
131