EvtCadPatrocinado   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 273
Duplicated Lines 35.16 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 26
lcom 1
cbo 1
dl 96
loc 273
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
F toNode() 96 250 25

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 EvtCadPatrocinado 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 = 'evtCadPatrocinado';
28
        $params->evtTag = 'evtCadPatrocinado';
29
        $params->evtAlias = 'F-2020';
30
        parent::__construct($config, $std, $params, $certificate, $data);
31
    }
32
33
    protected function toNode()
34
    {
35
        $ideDeclarante = $this->node->getElementsByTagName('ideDeclarante')->item(0);
36
        $this->dom->addChild(
37
            $ideDeclarante,
38
            "GIIN",
39
            !empty($this->std->giin) ? $this->std->giin : null,
40
            false
41
        );
42
        $this->dom->addChild(
43
            $ideDeclarante,
44
            "CategoriaPatrocinador",
45
            !empty($this->std->categoriapatrocinador) ? $this->std->categoriapatrocinador : null,
46
            false
47
        );
48
        //o idEvento pode variar de evento para evento
49
        //então cada factory individualmente terá de construir o seu
50
        $ideEvento = $this->dom->createElement("ideEvento");
51
        $this->dom->addChild(
52
            $ideEvento,
53
            "indRetificacao",
54
            $this->std->indretificacao,
55
            true
56
        );
57
        $this->dom->addChild(
58
            $ideEvento,
59
            "nrRecibo",
60
            isset($this->std->nrrecibo) ? $this->std->nrrecibo : null,
61
            false
62
        );
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "tpAmb",
66
            (string) $this->tpAmb,
67
            true
68
        );
69
        $this->dom->addChild(
70
            $ideEvento,
71
            "aplicEmi",
72
            '1',
73
            true
74
        );
75
        $this->dom->addChild(
76
            $ideEvento,
77
            "verAplic",
78
            $this->verAplic,
79
            true
80
        );
81
        $this->node->insertBefore($ideEvento, $ideDeclarante);
82
        
83
        $ip = $this->std->infopatrocinado;
84
        $infoPatrocinado = $this->dom->createElement("infoPatrocinado");
85
        $this->dom->addChild(
86
            $infoPatrocinado,
87
            "GIIN",
88
            !empty($ip->giin) ? $ip->giin : null,
89
            false
90
        );
91
        $this->dom->addChild(
92
            $infoPatrocinado,
93
            "CNPJ",
94
            $ip->cnpj,
95
            true
96
        );
97 View Code Duplication
        if (!empty($ip->nif)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
            foreach ($ip->nif as $n) {
99
                $NIF = $this->dom->createElement("NIF");
100
                $this->dom->addChild(
101
                    $NIF,
102
                    "NumeroNIF",
103
                    $n->numeronif,
104
                    true
105
                );
106
                $this->dom->addChild(
107
                    $NIF,
108
                    "PaisEmissao",
109
                    $n->paisemissao,
110
                    true
111
                );
112
                $this->dom->addChild(
113
                    $NIF,
114
                    "tpNIF",
115
                    !empty($n->tpnif) ? $n->tpnif : null,
116
                    false
117
                );
118
119
120
                $infoPatrocinado->appendChild($NIF);
121
            }
122
        }
123
        $this->dom->addChild(
124
            $infoPatrocinado,
125
            "nomePatrocinado",
126
            $ip->nomepatrocinado,
127
            true
128
        );
129
        $this->dom->addChild(
130
            $infoPatrocinado,
131
            "tpNome",
132
            !empty($ip->tpnome) ? $ip->tpnome : null,
133
            false
134
        );
135
        
136
        $end = $ip->endereco;
137
        $endereco = $this->dom->createElement("endereco");
138
        $this->dom->addChild(
139
            $endereco,
140
            "enderecoLivre",
141
            $end->enderecolivre,
142
            true
143
        );
144
        $this->dom->addChild(
145
            $endereco,
146
            "CEP",
147
            $end->cep,
148
            true
149
        );
150
        $this->dom->addChild(
151
            $endereco,
152
            "municipio",
153
            $end->municipio,
154
            true
155
        );
156
        $this->dom->addChild(
157
            $endereco,
158
            "pais",
159
            $end->pais,
160
            true
161
        );
162
        $infoPatrocinado->appendChild($endereco);
163
        $this->dom->addChild(
164
            $infoPatrocinado,
165
            "tpEndereco",
166
            !empty($ip->tpendereco) ? $ip->tpendereco : null,
167
            false
168
        );
169
        
170
        if (!empty($ip->enderecooutros)) {
171
            foreach ($ip->enderecooutros as $eo) {
172
                $EnderecoOutros = $this->dom->createElement("EnderecoOutros");
173
                $this->dom->addChild(
174
                    $EnderecoOutros,
175
                    "tpEndereco",
176
                    !empty($eo->tpendereco) ? $eo->tpendereco : null,
177
                    false
178
                );
179
                $this->dom->addChild(
180
                    $EnderecoOutros,
181
                    "EnderecoLivre",
182
                    !empty($eo->enderecolivre) ? $eo->enderecolivre : null,
183
                    false
184
                );
185 View Code Duplication
                if (!empty($eo->enderecoestrutura) && empty($eo->enderecolivre)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
                    $ee = $eo->enderecoestrutura;
187
                    $EnderecoEstrutura = $this->dom->createElement("EnderecoEstrutura");
188
                    $this->dom->addChild(
189
                        $EnderecoEstrutura,
190
                        "EnderecoLivre",
191
                        isset($ee->enderecolivre) ? $ee->enderecolivre : null,
192
                        false
193
                    );
194
                    if (!empty($ee->endereco)) {
195
                        $end = $ee->endereco;
196
                        $Endereco = $this->dom->createElement("Endereco");
197
                        $this->dom->addChild(
198
                            $Endereco,
199
                            "Logradouro",
200
                            isset($end->logradouro) ? $end->logradouro : null,
201
                            false
202
                        );
203
                        $this->dom->addChild(
204
                            $Endereco,
205
                            "Numero",
206
                            isset($end->numero) ? $end->numero : null,
207
                            false
208
                        );
209
                        $this->dom->addChild(
210
                            $Endereco,
211
                            "Complemento",
212
                            isset($end->complemento) ? $end->complemento : null,
213
                            false
214
                        );
215
                        $this->dom->addChild(
216
                            $Endereco,
217
                            "Andar",
218
                            isset($end->andar) ? $end->andar : null,
219
                            false
220
                        );
221
                        $this->dom->addChild(
222
                            $Endereco,
223
                            "Bairro",
224
                            isset($end->bairro) ? $end->bairro : null,
225
                            false
226
                        );
227
                        $this->dom->addChild(
228
                            $Endereco,
229
                            "CaixaPostal",
230
                            isset($end->caixapostal) ? $end->caixapostal : null,
231
                            false
232
                        );
233
                        $EnderecoEstrutura->appendChild($Endereco);
234
                    }
235
                    $this->dom->addChild(
236
                        $EnderecoEstrutura,
237
                        "CEP",
238
                        $ee->cep,
239
                        true
240
                    );
241
                    $this->dom->addChild(
242
                        $EnderecoEstrutura,
243
                        "Municipio",
244
                        $ee->municipio,
245
                        true
246
                    );
247
                    $this->dom->addChild(
248
                        $EnderecoEstrutura,
249
                        "UF",
250
                        $ee->uf,
251
                        true
252
                    );
253
                    $EnderecoOutros->appendChild($EnderecoEstrutura);
254
                }
255
                $this->dom->addChild(
256
                    $EnderecoOutros,
257
                    "Pais",
258
                    $eo->pais,
259
                    true
260
                );
261
                $infoPatrocinado->appendChild($EnderecoOutros);
262
            }
263
        }
264
        foreach ($ip->paisresid as $pr) {
265
            $paisResid = $this->dom->createElement("paisResid");
266
            $this->dom->addChild(
267
                $paisResid,
268
                "Pais",
269
                $pr->pais,
270
                true
271
            );
272
            $infoPatrocinado->appendChild($paisResid);
273
        }
274
        
275
        $this->node->appendChild($infoPatrocinado);
276
        
277
        
278
        //finalização do xml
279
        $this->eFinanceira->appendChild($this->node);
280
        //$this->xml = $this->dom->saveXML($this->eFinanceira);
281
        $this->sign($this->evtTag);
282
    }
283
}
284