Passed
Push — master ( e850ef...69529f )
by Roberto
02:10
created

EvtComProd::toNode()   C

Complexity

Conditions 12
Paths 4

Size

Total Lines 164
Code Lines 132

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 164
ccs 0
cts 160
cp 0
rs 5.034
c 0
b 0
f 0
cc 12
eloc 132
nc 4
nop 0
crap 156

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 EvtComProd Event R-2050 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 EvtComProd extends Factory implements FactoryInterface
25
{
26
    /**
27
     * Constructor
28
     * @param string $config
29
     * @param stdClass $std
30
     * @param Certificate $certificate
31
     * @param string date
32
     */
33
    public function __construct(
34
        $config,
35
        stdClass $std,
36
        Certificate $certificate = null,
37
        $date = ''
38
    ) {
39
        $params = new \stdClass();
40
        $params->evtName = 'evtInfoProdRural';
41
        $params->evtTag = 'evtComProd';
42
        $params->evtAlias = 'R-2050';
43
        parent::__construct($config, $std, $params, $certificate, $date);
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("infoComProd");
94
        $ideEstab = $this->dom->createElement("ideEstab");
95
        $this->dom->addChild(
96
            $ideEstab,
97
            "tpInscEstab",
98
            $this->std->tpinscestab,
99
            true
100
        );
101
        $this->dom->addChild(
102
            $ideEstab,
103
            "nrInscEstab",
104
            $this->std->nrinscestab,
105
            true
106
        );
107
        $this->dom->addChild(
108
            $ideEstab,
109
            "vlrRecBrutaTotal",
110
            number_format($this->std->vlrrecbrutatotal, 2, ',', ''),
111
            true
112
        );
113
        $this->dom->addChild(
114
            $ideEstab,
115
            "vlrCPApur",
116
            number_format($this->std->vlrcpapur, 2, ',', ''),
117
            true
118
        );
119
        $this->dom->addChild(
120
            $ideEstab,
121
            "vlrRatApur",
122
            number_format($this->std->vlrratapur, 2, ',', ''),
123
            true
124
        );
125
        $this->dom->addChild(
126
            $ideEstab,
127
            "vlrSenarApur",
128
            number_format($this->std->vlrsenarapur, 2, ',', ''),
129
            true
130
        );
131
        $this->dom->addChild(
132
            $ideEstab,
133
            "vlrCPSuspTotal",
134
            !empty($this->std->vlrcpsusptotal) ? number_format($this->std->vlrcpsusptotal, 2, ',', '') : null,
135
            false
136
        );
137
        $this->dom->addChild(
138
            $ideEstab,
139
            "vlrRatSuspTotal",
140
            !empty($this->std->vlrratsusptotal) ? number_format($this->std->vlrratsusptotal, 2, ',', '') : null,
141
            false
142
        );
143
        $this->dom->addChild(
144
            $ideEstab,
145
            "vlrSenarSuspTotal",
146
            !empty($this->std->vlrsenarsusptotal) ? number_format($this->std->vlrsenarsusptotal, 2, ',', '') : null,
147
            false
148
        );
149
        foreach ($this->std->tipocom as $tp) {
150
            $tipoCom = $this->dom->createElement("tipoCom");
151
            $this->dom->addChild(
152
                $tipoCom,
153
                "indCom",
154
                $tp->indcom,
155
                true
156
            );
157
            $this->dom->addChild(
158
                $tipoCom,
159
                "vlrRecBruta",
160
                number_format($tp->vlrrecbruta, 2, ',', ''),
161
                true
162
            );
163
            $ideEstab->appendChild($tipoCom);
164
        }
165
        if (!empty($this->std->infoproc)) {
166
            foreach($this->std->infoproc as $ip) {
167
                $infoProc = $this->dom->createElement("infoProc");
168
                $this->dom->addChild(
169
                    $infoProc,
170
                    "tpProc",
171
                    $ip->tpproc,
172
                    true
173
                );
174
                $this->dom->addChild(
175
                    $infoProc,
176
                    "nrProc",
177
                    $ip->nrproc,
178
                    true
179
                );
180
                $this->dom->addChild(
181
                    $infoProc,
182
                    "codSusp",
183
                    !empty($ip->codsusp) ? $ip->codsusp : null,
184
                    false
185
                );
186
                $this->dom->addChild(
187
                    $infoProc,
188
                    "vlrCPSusp",
189
                    !empty($ip->vlrcpsusp) ? number_format($ip->vlrcpsusp, 2, ',', '') : null,
190
                    false
191
                );
192
                $this->dom->addChild(
193
                    $infoProc,
194
                    "vlrRatSusp",
195
                    !empty($ip->vlrratsusp) ? number_format($ip->vlrratsusp, 2, ',', '') : null,
196
                    false
197
                );
198
                $this->dom->addChild(
199
                    $infoProc,
200
                    "vlrSenarSusp",
201
                    !empty($ip->vlrsenarsusp) ? number_format($ip->vlrsenarsusp, 2, ',', '') : null,
202
                    false
203
                );
204
                $ideEstab->appendChild($infoProc);
205
            }
206
        }
207
        $info->appendChild($ideEstab);
208
        $this->node->appendChild($info);
209
        $this->reinf->appendChild($this->node);
210
        //$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...
211
        $this->sign($this->evtTag);
212
    }
213
}
214