Passed
Push — master ( b85394...28dc46 )
by Roberto
02:23
created

EvtTotal::toNode()   D

Complexity

Conditions 24
Paths 64

Size

Total Lines 310
Code Lines 250

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 600

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 310
ccs 0
cts 305
cp 0
rs 4.5989
c 1
b 0
f 0
cc 24
eloc 250
nc 64
nop 0
crap 600

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 EvtTotal Event R-5001 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 EvtTotal extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var string
28
     * NOTA: refere-se ao nome do XSD
29
     */
30
    protected $evtName = 'evtTotal';
31
    /**
32
     * @var string
33
     */
34
    protected $evtTag = 'evtTotal';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'R-5001';
39
40
    /**
41
     * Constructor
42
     * @param string $config
43
     * @param stdClass $std
44
     * @param Certificate $certificate
45
     * @param string date
46
     */
47
    public function __construct(
48
        $config,
49
        stdClass $std,
50
        Certificate $certificate = null,
51
        $date = ''
52
    ) {
53
        parent::__construct($config, $std, $certificate, $date);
54
    }
55
    
56
    /**
57
     * Node constructor
58
     */
59
    protected function toNode()
60
    {
61
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
62
        //o idEvento pode variar de evento para evento
63
        //então cada factory individualmente terá de construir o seu
64
        $ideEvento = $this->dom->createElement("ideEvento");
65
        $this->dom->addChild(
66
            $ideEvento,
67
            "perApur",
68
            $this->std->perapur,
69
            true
70
        );
71
        $this->node->insertBefore($ideEvento, $ideContri);
72
        //tag deste evento em particular
73
        $ideRecRetorno = $this->dom->createElement("ideRecRetorno");
74
        $ideStatus = $this->dom->createElement("ideStatus");
75
        $this->dom->addChild(
76
            $ideStatus,
77
            "cdRetorno",
78
            $this->std->cdretorno,
79
            true
80
        );
81
        $this->dom->addChild(
82
            $ideStatus,
83
            "descRetorno",
84
            $this->std->descretorno,
85
            true
86
        );
87
        if (!empty($this->std->regocorrs)) {
88
            foreach ($this->std->regocorrs as $r) {
89
                $regOcorrs = $this->dom->createElement("regOcorrs");
90
                $this->dom->addChild(
91
                    $regOcorrs,
92
                    "tpOcorr",
93
                    $r->tpocorr,
94
                    true
95
                );
96
                $this->dom->addChild(
97
                    $regOcorrs,
98
                    "localErroAviso",
99
                    $r->localerroaviso,
100
                    true
101
                );
102
                $this->dom->addChild(
103
                    $regOcorrs,
104
                    "codResp",
105
                    $r->codresp,
106
                    true
107
                );
108
                $this->dom->addChild(
109
                    $regOcorrs,
110
                    "dscResp",
111
                    $r->dscresp,
112
                    true
113
                );
114
                $ideStatus->appendChild($regOcorrs);
115
            }
116
        }
117
        $ideRecRetorno->appendChild($ideStatus);
118
        $this->node->appendChild($ideRecRetorno);
119
        $infoRecEv = $this->dom->createElement("infoRecEv");
120
        $this->dom->addChild(
121
            $infoRecEv,
122
            "dhProcess",
123
            $this->std->dhprocess,
124
            true
125
        );
126
        $this->dom->addChild(
127
            $infoRecEv,
128
            "tpEv",
129
            $this->std->tpev,
130
            true
131
        );
132
        $this->dom->addChild(
133
            $infoRecEv,
134
            "idEv",
135
            $this->std->idev,
136
            true
137
        );
138
        $this->dom->addChild(
139
            $infoRecEv,
140
            "hash",
141
            $this->std->hash,
142
            true
143
        );
144
        $this->node->appendChild($infoRecEv);
145
        $infoTotal = $this->dom->createElement("infoTotal");
146
        $this->dom->addChild(
147
            $infoTotal,
148
            "nrRecArqBase",
149
            !empty($this->std->nrrecarqbase) ? $this->std->nrrecarqbase : null,
150
            false
151
        );
152
        $this->dom->addChild(
153
            $infoTotal,
154
            "indExistInfo",
155
            $this->std->indexistinfo,
156
            true
157
        );
158
        $this->node->appendChild($infoTotal);
159
        $infoContrib = $this->dom->createElement("infoContrib");
160
        $this->dom->addChild(
161
            $infoContrib,
162
            "indEscrituracao",
163
            $this->std->indescrituracao,
164
            true
165
        );
166
        $this->dom->addChild(
167
            $infoContrib,
168
            "indDesoneracao",
169
            $this->std->inddesoneracao,
170
            true
171
        );
172
        $this->dom->addChild(
173
            $infoContrib,
174
            "indAcordoIsenMulta",
175
            $this->std->indacordoisenmulta,
176
            true
177
        );
178
        if (!empty($this->std->rtom)) {
179
            foreach ($this->std->rtom as $r) {
180
                $rTom = $this->dom->createElement("RTom");
181
                $this->dom->addChild(
182
                    $rTom,
183
                    "cnpjPrestador",
184
                    $r->cnpjprestador,
185
                    true
186
                );
187
                $this->dom->addChild(
188
                    $rTom,
189
                    "vlrTotalBaseRet",
190
                    $r->vlrtotalbaseret,
191
                    true
192
                );
193
                $this->dom->addChild(
194
                    $rTom,
195
                    "vlrTotalRetPrinc",
196
                    $r->vlrtotalretprinc,
197
                    true
198
                );
199
                $this->dom->addChild(
200
                    $rTom,
201
                    "vlrTotalRetAdic",
202
                    !empty($r->vlrtotalretadic) ? $r->vlrtotalretadic : null,
203
                    false
204
                );
205
                $this->dom->addChild(
206
                    $rTom,
207
                    "vlrTotalNRetPrinc",
208
                    !empty($r->vlrtotalnretprinc) ? $r->vlrtotalnretprinc : null,
209
                    false
210
                );
211
                $this->dom->addChild(
212
                    $rTom,
213
                    "vlrTotalNRetAdic",
214
                    !empty($r->vlrtotalnretadic) ? $r->vlrtotalnretadic : null,
215
                    false
216
                );
217
                $infoContrib->appendChild($rTom);
218
            }
219
        }
220
        if (!empty($this->std->rprest)) {
221
            foreach ($this->std->rprest as $r) {
222
                $rPrest = $this->dom->createElement("RPrest");
223
                $this->dom->addChild(
224
                    $rPrest,
225
                    "tpInscTomador",
226
                    $r->tpinsctomador,
227
                    true
228
                );
229
                $this->dom->addChild(
230
                    $rPrest,
231
                    "nrInscTomador",
232
                    $r->nrinsctomador,
233
                    true
234
                );
235
                $this->dom->addChild(
236
                    $rPrest,
237
                    "vlrTotalBaseRet",
238
                    $r->vlrtotalbaseret,
239
                    true
240
                );
241
                $this->dom->addChild(
242
                    $rPrest,
243
                    "vlrTotalRetPrinc",
244
                    $r->vlrtotalretprinc,
245
                    true
246
                );
247
                $this->dom->addChild(
248
                    $rPrest,
249
                    "vlrTotalRetAdic",
250
                    !empty($r->vlrtotalretadic) ? $r->vlrtotalretadic : null,
251
                    false
252
                );
253
                $this->dom->addChild(
254
                    $rPrest,
255
                    "vlrTotalNRetPrinc",
256
                    !empty($r->vlrtotalnretprinc) ? $r->vlrtotalnretprinc : null,
257
                    false
258
                );
259
                $this->dom->addChild(
260
                    $rPrest,
261
                    "vlrTotalNRetAdic",
262
                    !empty($r->vlrtotalnretadic) ? $r->vlrtotalnretadic : null,
263
                    false
264
                );
265
                $infoContrib->appendChild($rPrest);
266
            }
267
        }
268
        if (!empty($this->std->rrecrepad)) {
269
            foreach ($this->std->rrecrepad as $r) {
270
                $rRecRepAD = $this->dom->createElement("RRecRepAD");
271
                $this->dom->addChild(
272
                    $rRecRepAD,
273
                    "cnpjAssocDesp",
274
                    $r->cnpjassocdesp,
275
                    true
276
                );
277
                $this->dom->addChild(
278
                    $rRecRepAD,
279
                    "vlrTotalRep",
280
                    $r->vlrtotalrep,
281
                    true
282
                );
283
                $this->dom->addChild(
284
                    $rRecRepAD,
285
                    "vlrTotalRet",
286
                    $r->vlrtotalret,
287
                    true
288
                );
289
                $this->dom->addChild(
290
                    $rRecRepAD,
291
                    "vlrTotalNRet",
292
                    !empty($r->vlrtotalnret) ? $r->vlrtotalnret : null,
293
                    false
294
                );
295
                $infoContrib->appendChild($rRecRepAD);
296
            }
297
        }
298
        if (!empty($this->std->rcoml)) {
299
            $rComl = $this->dom->createElement("RComl");
300
            $r = $this->std->rcoml;
301
            $this->dom->addChild(
302
                $rComl,
303
                "vlrCPApur",
304
                $r->vlrcpapur,
305
                true
306
            );
307
            $this->dom->addChild(
308
                $rComl,
309
                "vlrRatApur",
310
                $r->vlrratapur,
311
                true
312
            );
313
            $this->dom->addChild(
314
                $rComl,
315
                "vlrSenarApur",
316
                $r->vlrsenarapur,
317
                true
318
            );
319
            $this->dom->addChild(
320
                $rComl,
321
                "vlrCPSusp",
322
                !empty($r->vlrcpsusp) ? $r->vlrcpsusp : null,
323
                false
324
            );
325
            $this->dom->addChild(
326
                $rComl,
327
                "vlrRatSusp",
328
                !empty($r->vlrratsusp) ? $r->vlrratsusp : null,
329
                false
330
            );
331
            $this->dom->addChild(
332
                $rComl,
333
                "vlrSenarSusp",
334
                !empty($r->vlrsenarsusp) ? $r->vlrsenarsusp : null,
335
                false
336
            );
337
            $infoContrib->appendChild($rComl);
338
        }
339
        if (!empty($this->std->rcprb)) {
340
            foreach ($this->std->rcprb as $r) {
341
                $rCPRB = $this->dom->createElement("RCPRB");
342
                $this->dom->addChild(
343
                    $rCPRB,
344
                    "codRec",
345
                    $r->codrec,
346
                    true
347
                );
348
                $this->dom->addChild(
349
                    $rCPRB,
350
                    "vlrCPApurTotal",
351
                    $r->vlrcpapurtotal,
352
                    true
353
                );
354
                $this->dom->addChild(
355
                    $rCPRB,
356
                    "vlrCPRBSusp",
357
                    !empty($r->vlrcprbsusp) ? $r->vlrcprbsusp : null,
358
                    false
359
                );
360
                $infoContrib->appendChild($rCPRB);
361
            }
362
        }
363
        $this->node->appendChild($infoContrib);
364
        
365
        $this->reinf->appendChild($this->node);
366
        $this->xml = $this->dom->saveXML($this->reinf);
367
        //$this->sign();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
368
    }
369
}
370