Completed
Push — master ( d0bdbe...8f6d6b )
by Roberto
04:06 queued 02:01
created

EvtServPrest::toNode()   D

Complexity

Conditions 21
Paths 12

Size

Total Lines 281
Code Lines 226

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 462

Importance

Changes 0
Metric Value
dl 0
loc 281
ccs 0
cts 274
cp 0
rs 4.6955
c 0
b 0
f 0
cc 21
eloc 226
nc 12
nop 0
crap 462

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 EvtServPrest Event R-2020 constructor
7
 *
8
 * @category  API
9
 * @package   NFePHP\EFDReinf
10
 * @copyright NFePHP Copyright (c) 2017
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 EvtServPrest 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 = 'evtPrestadorServicos';
41
        $params->evtTag = 'evtServPrest';
42
        $params->evtAlias = 'R-2020';
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
            "indRetif",
58
            $this->std->indretif,
59
            true
60
        );
61
        $this->dom->addChild(
62
            $ideEvento,
63
            "nrRecibo",
64
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
65
            true
66
        );
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "perApur",
70
            $this->std->perapur,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "tpAmb",
76
            $this->tpAmb,
77
            true
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "procEmi",
82
            $this->procEmi,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "verProc",
88
            $this->verProc,
89
            true
90
        );
91
        $this->node->insertBefore($ideEvento, $ideContri);
92
        
93
        $info = $this->dom->createElement("infoServPrest");
94
        $ideEstabPrest = $this->dom->createElement("ideEstabPrest");
95
        $this->dom->addChild(
96
            $ideEstabPrest,
97
            "tpInscEstabPrest",
98
            $this->std->tpinscestabprest,
99
            true
100
        );        
101
        $this->dom->addChild(
102
            $ideEstabPrest,
103
            "nrInscEstabPrest",
104
            $this->std->nrinscestabprest,
105
            true
106
        );
107
        $ideTomador = $this->dom->createElement("ideTomador"); 
108
        $this->dom->addChild(
109
            $ideTomador,
110
            "tpInscTomador",
111
            $this->std->tpinsctomador,
112
            true
113
        );
114
        $this->dom->addChild(
115
            $ideTomador,
116
            "nrInscTomador",
117
            $this->std->nrinsctomador,
118
            true
119
        );
120
        $this->dom->addChild(
121
            $ideTomador,
122
            "indObra",
123
            $this->std->indobra,
124
            true
125
        );
126
        $this->dom->addChild(
127
            $ideTomador,
128
            "vlrTotalBruto",
129
            number_format($this->std->vlrtotalbruto, 2 , ',', ''),
130
            true
131
        );
132
        $this->dom->addChild(
133
            $ideTomador,
134
            "vlrTotalBaseRet",
135
            number_format($this->std->vlrtotalbaseret, 2 , ',', ''),
136
            true
137
        );
138
        $this->dom->addChild(
139
            $ideTomador,
140
            "vlrTotalRetPrinc",
141
            number_format($this->std->vlrtotalretprinc, 2 , ',', ''),
142
            true
143
        );
144
        $this->dom->addChild(
145
            $ideTomador,
146
            "vlrTotalRetAdic",
147
            !empty($this->std->vlrtotalretadic) ? number_format($this->std->vlrtotalretadic, 2 , ',', '') : null,
148
            false
149
        );
150
        $this->dom->addChild(
151
            $ideTomador,
152
            "vlrTotalNRetPrinc",
153
            !empty($this->std->vlrtotalnretprinc) ? number_format($this->std->vlrtotalnretprinc, 2 , ',', '') : null,
154
            false
155
        );
156
        $this->dom->addChild(
157
            $ideTomador,
158
            "vlrTotalNRetAdic",
159
            !empty($this->std->vlrtotalnretadic) ? number_format($this->std->vlrtotalnretadic, 2 , ',', '') : null,
160
            false
161
        );
162
        
163
        foreach ($this->std->nfs as $n) {
164
            $nfs = $this->dom->createElement("nfs");
165
            $this->dom->addChild(
166
                $nfs,
167
                "serie",
168
                $n->serie,
169
                true
170
            );            
171
            $this->dom->addChild(
172
                $nfs,
173
                "numDocto",
174
                $n->numdocto,
175
                true
176
            );            
177
            $this->dom->addChild(
178
                $nfs,
179
                "dtEmissaoNF",
180
                $n->dtemissaonf,
181
                true
182
            );
183
            $this->dom->addChild(
184
                $nfs,
185
                "vlrBruto",
186
                number_format($n->vlrbruto, 2 , ',', ''),
187
                true
188
            );
189
            $this->dom->addChild(
190
                $nfs,
191
                "obs",
192
                !empty($n->obs) ? $n->obs : null,
193
                false
194
            );
195
            
196
            foreach ($n->infotpserv as $its) {
197
                $infoTpServ = $this->dom->createElement("infoTpServ");
198
                $this->dom->addChild(
199
                    $infoTpServ,
200
                    "tpServico",
201
                    $its->tpservico,
202
                    true
203
                );
204
                $this->dom->addChild(
205
                    $infoTpServ,
206
                    "vlrBaseRet",
207
                    number_format($its->vlrbaseret, 2, ',', ''),
208
                    true
209
                );
210
                $this->dom->addChild(
211
                    $infoTpServ,
212
                    "vlrRetencao",
213
                    number_format($its->vlrretencao, 2, ',', ''),
214
                    true
215
                );
216
                $this->dom->addChild(
217
                    $infoTpServ,
218
                    "vlrRetSub",
219
                    !empty($its->vlrretsub) ? number_format($its->vlrretsub, 2, ',', '') : null,
220
                    false
221
                );
222
                $this->dom->addChild(
223
                    $infoTpServ,
224
                    "vlrNRetPrinc",
225
                    !empty($its->vlrnretprinc) ? number_format($its->vlrnretprinc, 2, ',', '') : null,
226
                    false
227
                );
228
                $this->dom->addChild(
229
                    $infoTpServ,
230
                    "vlrServicos15",
231
                    !empty($its->vlrservicos15) ? number_format($its->vlrservicos15, 2, ',', '') : null,
232
                    false
233
                );
234
                $this->dom->addChild(
235
                    $infoTpServ,
236
                    "vlrServicos20",
237
                    !empty($its->vlrservicos20) ? number_format($its->vlrservicos20, 2, ',', '') : null,
238
                    false
239
                );
240
                $this->dom->addChild(
241
                    $infoTpServ,
242
                    "vlrServicos25",
243
                    !empty($its->vlrservicos25) ? number_format($its->vlrservicos25, 2, ',', '') : null,
244
                    false
245
                );
246
                $this->dom->addChild(
247
                    $infoTpServ,
248
                    "vlrAdicional",
249
                    !empty($its->vlradicional) ? number_format($its->vlradicional, 2, ',', '') : null,
250
                    false
251
                );
252
                $this->dom->addChild(
253
                    $infoTpServ,
254
                    "vlrNRetAdic",
255
                    !empty($its->vlrnretadic) ? number_format($its->vlrnretadic, 2, ',', '') : null,
256
                    false
257
                );
258
259
                $nfs->appendChild($infoTpServ);
260
            }
261
            $ideTomador->appendChild($nfs);  
262
        }
263
        if (!empty($this->std->infoprocretpr)) {
264
            foreach ($this->std->infoprocretpr as $irp) {
265
                $infoProcRetPr = $this->dom->createElement("infoProcRetPr");
266
                $this->dom->addChild(
267
                    $infoProcRetPr,
268
                    "tpProcRetPrinc",
269
                    $irp->tpprocretprinc,
270
                    true
271
                );
272
                $this->dom->addChild(
273
                    $infoProcRetPr,
274
                    "nrProcRetPrinc",
275
                    $irp->nrprocretprinc,
276
                    true
277
                );
278
                $this->dom->addChild(
279
                    $infoProcRetPr,
280
                    "codSuspPrinc",
281
                    !empty($irp->codsuspprinc) ? $irp->codsuspprinc : null,
282
                    false
283
                );
284
                $this->dom->addChild(
285
                    $infoProcRetPr,
286
                    "valorPrinc",
287
                    number_format($irp->valorprinc, 2, ',', ''),
288
                    true
289
                );
290
                $ideTomador->appendChild($infoProcRetPr);
291
            }
292
        }
293
        if (!empty($this->std->infoprocretad)) {
294
            foreach ($this->std->infoprocretad as $rad) {
295
                $infoProcRetAd = $this->dom->createElement("infoProcRetAd");
296
                $this->dom->addChild(
297
                    $infoProcRetAd,
298
                    "tpProcRetAdic",
299
                    $rad->tpprocretadic,
300
                    true
301
                );
302
                $this->dom->addChild(
303
                    $infoProcRetAd,
304
                    "nrProcRetAdic",
305
                    $rad->nrprocretadic,
306
                    true
307
                );
308
                $this->dom->addChild(
309
                    $infoProcRetAd,
310
                    "codSuspAdic",
311
                    !empty($rad->codsuspadic) ? $rad->codsuspadic : null,
312
                    false
313
                );
314
                $this->dom->addChild(
315
                    $infoProcRetAd,
316
                    "valorAdic",
317
                    number_format($rad->valoradic, 2, ',', ''),
318
                    true
319
                );
320
                $ideTomador->appendChild($infoProcRetAd);
321
            }
322
        }
323
        $ideEstabPrest->appendChild($ideTomador);
324
        $info->appendChild($ideEstabPrest);
325
        $this->node->appendChild($info);
326
        $this->reinf->appendChild($this->node);
327
        //$this->xml = $this->dom->saveXML($this->reinf);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
328
        $this->sign($this->evtTag);
329
    }
330
}
331