Passed
Push — master ( 73f724...5a2e05 )
by Roberto
05:00 queued 02:47
created

EvtInfoContri::toNode()   F

Complexity

Conditions 20
Paths 126

Size

Total Lines 213

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 420

Importance

Changes 0
Metric Value
dl 0
loc 213
ccs 0
cts 207
cp 0
rs 3.16
c 0
b 0
f 0
cc 20
nc 126
nop 0
crap 420

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\EFDReinf\Factories;
4
5
/**
6
 * Class EFD-Reinf EvtInfoContri Event R-1000 constructor
7
 *
8
 * @category  Library
9
 * @package   NFePHP\EFDReinf
10
 * @copyright NFePHP Copyright (c) 2017 - 2021
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-efdreinf for the canonical source repository
16
 */
17
18
use NFePHP\EFDReinf\Common\Factory;
19
use NFePHP\EFDReinf\Common\FactoryInterface;
20
use NFePHP\EFDReinf\Common\FactoryId;
21
use NFePHP\Common\Certificate;
22
use stdClass;
23
24
class EvtInfoContri extends Factory implements FactoryInterface
25
{
26
    /**
27
     * Constructor
28
     * @param string $config
29
     * @param stdClass $std
30
     * @param Certificate $certificate
31
     * @param string $data
32
     */
33
    public function __construct(
34
        $config,
35
        stdClass $std,
36
        Certificate $certificate = null,
37
        $data = ''
38
    ) {
39
        $params = new \stdClass();
40
        $params->evtName = 'evtInfoContribuinte';
41
        $params->evtTag = 'evtInfoContri';
42
        $params->evtAlias = 'R-1000';
43
        parent::__construct($config, $std, $params, $certificate, $data);
44
    }
45
46
    /**
47
     * Node constructor
48
     */
49
    protected function toNode()
50
    {
51
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
52
        //o idEvento pode variar de evento para evento
53
        //então cada factory individualmente terá de construir o seu
54
        $ideEvento = $this->dom->createElement("ideEvento");
55
        $this->dom->addChild(
56
            $ideEvento,
57
            "tpAmb",
58
            $this->tpAmb,
59
            true
60
        );
61
        $this->dom->addChild(
62
            $ideEvento,
63
            "procEmi",
64
            $this->procEmi,
65
            true
66
        );
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "verProc",
70
            $this->verProc,
71
            true
72
        );
73
        $this->node->insertBefore($ideEvento, $ideContri);
74
        //tag deste evento em particular
75
        $infoContri = $this->dom->createElement("infoContri");
76
        //se aplica a todos os modos
77
        $idePeriodo = $this->dom->createElement("idePeriodo");
78
        $this->dom->addChild(
79
            $idePeriodo,
80
            "iniValid",
81
            $this->std->inivalid,
82
            true
83
        );
84
        if ($this->std->modo == 'INC') {
85
            $this->std->fimvalid = null;
86
        }
87
        $this->dom->addChild(
88
            $idePeriodo,
89
            "fimValid",
90
            !empty($this->std->fimvalid) ? $this->std->fimvalid : null,
91
            false
92
        );
93
        $infocadastro = null;
94
        if (!empty($this->std->infocadastro)) {
95
            $cad = $this->std->infocadastro;
96
            $infocadastro = $this->dom->createElement("infoCadastro");
97
            $this->dom->addChild(
98
                $infocadastro,
99
                "classTrib",
100
                $cad->classtrib,
101
                true
102
            );
103
            $this->dom->addChild(
104
                $infocadastro,
105
                "indEscrituracao",
106
                $cad->indescrituracao,
107
                true
108
            );
109
            $this->dom->addChild(
110
                $infocadastro,
111
                "indDesoneracao",
112
                $cad->inddesoneracao,
113
                true
114
            );
115
            $this->dom->addChild(
116
                $infocadastro,
117
                "indAcordoIsenMulta",
118
                $cad->indacordoisenmulta,
119
                true
120
            );
121
            $indsitpj = null;
122
            if (isset($cad->indsitpj)) {
123
                $indsitpj = $cad->indsitpj;
124
            }
125
            $this->dom->addChild(
126
                $infocadastro,
127
                "indSitPJ",
128
                $indsitpj,
129
                false
130
            );
131
            $contato = $this->dom->createElement("contato");
132
            $this->dom->addChild(
133
                $contato,
134
                "nmCtt",
135
                $cad->contato->nmctt,
136
                true
137
            );
138
            $this->dom->addChild(
139
                $contato,
140
                "cpfCtt",
141
                $cad->contato->cpfctt,
142
                true
143
            );
144
            $this->dom->addChild(
145
                $contato,
146
                "foneFixo",
147
                !empty($cad->contato->fonefixo)
148
                    ? $cad->contato->fonefixo
149
                    : null,
150
                false
151
            );
152
            $this->dom->addChild(
153
                $contato,
154
                "foneCel",
155
                !empty($cad->contato->fonecel)
156
                    ? $cad->contato->fonecel
157
                    : null,
158
                false
159
            );
160
            $this->dom->addChild(
161
                $contato,
162
                "email",
163
                !empty($cad->contato->email)
164
                    ? $cad->contato->email
165
                    : null,
166
                false
167
            );
168
            $infocadastro->appendChild($contato);
169
            if (!empty($cad->softhouse)) {
170
                foreach ($cad->softhouse as $soft) {
171
                    $softhouse = $this->dom->createElement("softHouse");
172
                    $this->dom->addChild(
173
                        $softhouse,
174
                        "cnpjSoftHouse",
175
                        $soft->cnpjsofthouse,
176
                        true
177
                    );
178
                    $this->dom->addChild(
179
                        $softhouse,
180
                        "nmRazao",
181
                        $soft->nmrazao,
182
                        true
183
                    );
184
                    $this->dom->addChild(
185
                        $softhouse,
186
                        "nmCont",
187
                        $soft->nmcont,
188
                        true
189
                    );
190
                    $this->dom->addChild(
191
                        $softhouse,
192
                        "telefone",
193
                        !empty($soft->telefone) ? $soft->telefone : null,
194
                        false
195
                    );
196
                    $this->dom->addChild(
197
                        $softhouse,
198
                        "email",
199
                        !empty($soft->email) ? $soft->email : null,
200
                        false
201
                    );
202
                    $infocadastro->appendChild($softhouse);
203
                }
204
            }
205
            if (!empty($cad->infoefr)) {
206
                $infoEFR = $this->dom->createElement("infoEFR");
207
                $this->dom->addChild(
208
                    $infoEFR,
209
                    "ideEFR",
210
                    $cad->infoefr->ideefr,
211
                    true
212
                );
213
                $this->dom->addChild(
214
                    $infoEFR,
215
                    "cnpjEFR",
216
                    !empty($cad->infoefr->cnpjefr) ? $cad->infoefr->cnpjefr : null,
217
                    false
218
                );
219
                $infocadastro->appendChild($infoEFR);
220
            }
221
        }
222
        if ($this->std->modo == 'INC') {
223
            $modo = $this->dom->createElement("inclusao");
224
            $modo->appendChild($idePeriodo);
225
            if (!empty($infocadastro)) {
226
                $modo->appendChild($infocadastro);
227
            }
228
        } elseif ($this->std->modo == 'ALT') {
229
            $modo = $this->dom->createElement("alteracao");
230
            $modo->appendChild($idePeriodo);
231
            if (!empty($infocadastro)) {
232
                $modo->appendChild($infocadastro);
233
            }
234
            if (!empty($this->std->novavalidade)) {
235
                $new = $this->std->novavalidade;
236
                $nval = $this->dom->createElement("novaValidade");
237
                $this->dom->addChild(
238
                    $nval,
239
                    "iniValid",
240
                    $new->inivalid,
241
                    true
242
                );
243
                $this->dom->addChild(
244
                    $nval,
245
                    "fimValid",
246
                    !empty($new->fimvalid) ? $new->fimvalid : null,
247
                    false
248
                );
249
                $modo->appendChild($nval);
250
            }
251
        } else {
252
            $modo = $this->dom->createElement("exclusao");
253
            $modo->appendChild($idePeriodo);
254
        }
255
        //finalização do xml
256
        $infoContri->appendChild($modo);
257
        $this->node->appendChild($infoContri);
258
        $this->reinf->appendChild($this->node);
259
        //$this->xml = $this->dom->saveXML($this->reinf);
260
        $this->sign($this->evtTag);
261
    }
262
}
263