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

EvtAssocDespRec::toNode()   C

Complexity

Conditions 8
Paths 5

Size

Total Lines 166
Code Lines 131

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 166
ccs 0
cts 159
cp 0
rs 5.2676
c 0
b 0
f 0
cc 8
eloc 131
nc 5
nop 0
crap 72

How to fix   Long Method   

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 EvtAssocDespRec Event R-2030 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 EvtAssocDespRec extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var string
28
     * NOTA: indica o XSD e o namespace do XML
29
     */
30
    protected $evtName = 'evtRecursoRecebidoAssociacao';
31
    /**
32
     * @var string
33
     */
34
    protected $evtTag = 'evtAssocDespRec';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'R-2030';
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
        //remove ideContri
63
        $this->node->removeChild($ideContri);
64
        //o idEvento pode variar de evento para evento
65
        //então cada factory individualmente terá de construir o seu
66
        $ideEvento = $this->dom->createElement("ideEvento");
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "indRetif",
70
            $this->std->indretif,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "nrRecibo",
76
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
77
            true
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "perApur",
82
            $this->std->perapur,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "tpAmb",
88
            $this->tpAmb,
89
            true
90
        );
91
        $this->dom->addChild(
92
            $ideEvento,
93
            "procEmi",
94
            $this->procEmi,
95
            true
96
        );
97
        $this->dom->addChild(
98
            $ideEvento,
99
            "verProc",
100
            $this->verProc,
101
            true
102
        );
103
        $this->node->appendChild($ideEvento);
104
        
105
        //cria novo ideContri
106
        $ideContri = $this->dom->createElement("ideContri");
107
        $this->dom->addChild(
108
            $ideContri,
109
            "tpInsc",
110
            $this->tpInsc,
111
            true
112
        );
113
        $this->dom->addChild(
114
            $ideContri,
115
            "nrInsc",
116
            $this->nrInsc,
117
            true
118
        );
119
        $ideEstab = $this->dom->createElement("ideEstab");
120
        $this->dom->addChild(
121
            $ideEstab,
122
            "tpInscEstab",
123
            $this->std->tpinscestab,
124
            true
125
        );        
126
        $this->dom->addChild(
127
            $ideEstab,
128
            "nrInscEstab",
129
            $this->std->nrinscestab,
130
            true
131
        );
132
        foreach ($this->std->recursosrec as $r) {
133
            $recursosRec = $this->dom->createElement("recursosRec");
134
            $this->dom->addChild(
135
                $recursosRec,
136
                "cnpjOrigRecurso",
137
                $r->cnpjorigrecurso,
138
                true
139
            );
140
            $this->dom->addChild(
141
                $recursosRec,
142
                "vlrTotalRec",
143
                $r->vlrtotalrec,
144
                true
145
            );
146
            $this->dom->addChild(
147
                $recursosRec,
148
                "vlrTotalRet",
149
                $r->vlrtotalret,
150
                true
151
            );
152
            $this->dom->addChild(
153
                $recursosRec,
154
                "vlrTotalNRet",
155
                !empty($r->vlrtotalnret) ? $r->vlrtotalnret : null,
156
                false
157
            );
158
            foreach ($r->inforecurso as $i) {
159
                $infoRecurso = $this->dom->createElement("infoRecurso"); 
160
                $this->dom->addChild(
161
                    $infoRecurso,
162
                    "tpRepasse",
163
                    $i->tprepasse,
164
                    true
165
                );
166
                $this->dom->addChild(
167
                    $infoRecurso,
168
                    "descRecurso",
169
                    $i->descrecurso,
170
                    true
171
                );
172
                $this->dom->addChild(
173
                    $infoRecurso,
174
                    "vlrBruto",
175
                    $i->vlrbruto,
176
                    true
177
                );
178
                $this->dom->addChild(
179
                    $infoRecurso,
180
                    "vlrRetApur",
181
                    $i->vlrretapur,
182
                    true
183
                );
184
                $recursosRec->appendChild($infoRecurso); 
185
            }
186
            if (!empty($r->infoproc)) {
187
                foreach ($r->infoproc as $i) {
188
                    $infoProc = $this->dom->createElement("infoProc");
189
                    $this->dom->addChild(
190
                        $infoProc,
191
                        "tpProc",
192
                        $i->tpproc,
193
                        true
194
                    );
195
                    $this->dom->addChild(
196
                        $infoProc,
197
                        "nrProc",
198
                        $i->nrproc,
199
                        true
200
                    );
201
                    $this->dom->addChild(
202
                        $infoProc,
203
                        "codSusp",
204
                        !empty($i->codsusp) ? $i->codsusp : null,
205
                        true
206
                    );
207
                    $this->dom->addChild(
208
                        $infoProc,
209
                        "vlrNRet",
210
                        $i->vlrnret,
211
                        true
212
                    );
213
                    $recursosRec->appendChild($infoProc);
214
                }
215
            }
216
            $ideEstab->appendChild($recursosRec);
217
        }
218
219
        $ideContri->appendChild($ideEstab);
220
        $this->node->appendChild($ideContri);
221
        $this->reinf->appendChild($this->node);
222
        //$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...
223
        $this->sign();
224
    }
225
}
226