Completed
Pull Request — master (#108)
by
unknown
02:56
created

EvtAqProd::toNode()   C

Complexity

Conditions 8
Paths 2

Size

Total Lines 255
Code Lines 177

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 255
ccs 0
cts 214
cp 0
rs 5.2676
c 0
b 0
f 0
cc 8
eloc 177
nc 2
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\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtAqProd Event S-1250 constructor
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHPSocial
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-esocial for the canonical source repository
16
 */
17
18
use NFePHP\Common\Certificate;
19
use NFePHP\eSocial\Common\Factory;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtAqProd extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtAqProd';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1250';
40
41
    /**
42
     * Parameters patterns
43
     *
44
     * @var array
45
     */
46
    protected $parameters = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $config
52
     * @param stdClass $std
53
     * @param Certificate $certificate
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate
59
    ) {
60
        parent::__construct($config, $std, $certificate);
61
    }
62
63
    /**
64
     * Node constructor
65
     */
66
    protected function toNode()
67
    {
68
        $evtid = FactoryId::build(
69
            $this->tpInsc,
70
            $this->nrInsc,
71
            $this->date,
72
            $this->sequencial
73
        );
74
75
        $evtAqProd = $this->dom->createElement("evtAqProd");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtAqProd->appendChild($att);
82
83
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
84
85
        $ideEvento = $this->dom->createElement("ideEvento");
86
87
        $this->dom->addChild(
88
            $ideEvento,
89
            "indRetif",
90
            $this->std->indretif,
91
            true
92
        );
93
        $this->dom->addChild(
94
            $ideEvento,
95
            "nrRecibo",
96
            ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
97
            false
98
        );
99
        $this->dom->addChild(
100
            $ideEvento,
101
            "indApuracao",
102
            $this->std->indapuracao,
103
            true
104
        );
105
        $this->dom->addChild(
106
            $ideEvento,
107
            "perApur",
108
            $this->std->perapur,
109
            true
110
        );
111
        $this->dom->addChild(
112
            $ideEvento,
113
            "tpAmb",
114
            $this->tpAmb,
115
            true
116
        );
117
        $this->dom->addChild(
118
            $ideEvento,
119
            "procEmi",
120
            $this->procEmi,
121
            true
122
        );
123
        $this->dom->addChild(
124
            $ideEvento,
125
            "verProc",
126
            $this->verProc,
127
            true
128
        );
129
130
        $this->node->insertBefore($ideEvento, $ideEmpregador);
131
132
        $infoAquisProd  = $this->dom->createElement("infoAquisProd");
133
        $ideEstabAdquir = $this->dom->createElement("ideEstabAdquir");
134
135
        $this->dom->addChild(
136
            $ideEstabAdquir,
137
            "tpInscAdq",
138
            $this->std->ideestabadquir->tpinscadq,
139
            true
140
        );
141
142
        $this->dom->addChild(
143
            $ideEstabAdquir,
144
            "nrInscAdq",
145
            $this->std->ideestabadquir->nrinscadq,
146
            true
147
        );
148
149
        if (isset($this->std->ideestabadquir->tpaquis)) {
150
            foreach ($this->std->ideestabadquir->tpaquis as $tp) {
151
                $tpAquis = $this->dom->createElement("tpAquis");
152
153
                $this->dom->addChild(
154
                    $tpAquis,
155
                    "indAquis",
156
                    $tp->indaquis,
157
                    true
158
                );
159
160
                $this->dom->addChild(
161
                    $tpAquis,
162
                    "vlrTotAquis",
163
                    $tp->vlrtotaquis,
164
                    true
165
                );
166
167
                foreach ($tp->ideprodutor as $ideprod) {
168
                    $ideProdutor = $this->dom->createElement("ideProdutor");
169
170
                    $this->dom->addChild(
171
                        $ideProdutor,
172
                        "tpInscProd",
173
                        $ideprod->tpinscprod,
174
                        true
175
                    );
176
177
                    $this->dom->addChild(
178
                        $ideProdutor,
179
                        "nrInscProd",
180
                        $ideprod->nrinscprod,
181
                        true
182
                    );
183
184
                    $this->dom->addChild(
185
                        $ideProdutor,
186
                        "vlrBruto",
187
                        $ideprod->vlrbruto,
188
                        true
189
                    );
190
191
                    $this->dom->addChild(
192
                        $ideProdutor,
193
                        "vrCPDescPR",
194
                        $ideprod->vrcpdescpr,
195
                        true
196
                    );
197
198
                    $this->dom->addChild(
199
                        $ideProdutor,
200
                        "vrRatDescPR",
201
                        $ideprod->vrratdescpr,
202
                        true
203
                    );
204
205
                    $this->dom->addChild(
206
                        $ideProdutor,
207
                        "vrSenarDesc",
208
                        $ideprod->vrsenardesc,
209
                        true
210
                    );
211
212
                    foreach ($ideprod->nfs as $prodnfs) {
213
                        $nfs = $this->dom->createElement("nfs");
214
215
                        $this->dom->addChild(
216
                            $nfs,
217
                            "serie",
218
                            ! empty($prodnfs->serie) ? $prodnfs->serie : null,
219
                            false
220
                        );
221
222
                        $this->dom->addChild(
223
                            $nfs,
224
                            "nrDocto",
225
                            $prodnfs->nrdocto,
226
                            true
227
                        );
228
229
                        $this->dom->addChild(
230
                            $nfs,
231
                            "dtEmisNF",
232
                            $prodnfs->dtemisnf,
233
                            true
234
                        );
235
236
                        $this->dom->addChild(
237
                            $nfs,
238
                            "vlrBruto",
239
                            $prodnfs->vlrbruto,
240
                            true
241
                        );
242
243
                        $this->dom->addChild(
244
                            $nfs,
245
                            "vrCPDescPR",
246
                            $prodnfs->vrcpdescpr,
247
                            true
248
                        );
249
250
                        $this->dom->addChild(
251
                            $nfs,
252
                            "vrRatDescPR",
253
                            $prodnfs->vrratdescpr,
254
                            true
255
                        );
256
257
                        $this->dom->addChild(
258
                            $nfs,
259
                            "vrSenarDesc",
260
                            $prodnfs->vrsenardesc,
261
                            true
262
                        );
263
264
                        $ideProdutor->appendChild($nfs);
265
                    }
266
267
                    foreach ($ideprod->infoprocjud as $prodprocjud) {
268
                        $infoProcJud = $this->dom->createElement("infoProcJud");
269
270
                        $this->dom->addChild(
271
                            $infoProcJud,
272
                            "nrProcJud",
273
                            $prodprocjud->nrprocjud,
274
                            true
275
                        );
276
277
                        $this->dom->addChild(
278
                            $infoProcJud,
279
                            "codSusp",
280
                            $prodprocjud->codsusp,
281
                            true
282
                        );
283
284
                        $this->dom->addChild(
285
                            $infoProcJud,
286
                            "vrCPNRet",
287
                            $prodprocjud->vrcpnret,
288
                            true
289
                        );
290
291
                        $this->dom->addChild(
292
                            $infoProcJud,
293
                            "vrRatNRet",
294
                            $prodprocjud->vrratnret,
295
                            true
296
                        );
297
298
                        $this->dom->addChild(
299
                            $infoProcJud,
300
                            "vrSenarNRet",
301
                            $prodprocjud->vrsenarnret,
302
                            true
303
                        );
304
305
                        $ideProdutor->appendChild($infoProcJud);
306
                    }
307
308
                    $tpAquis->appendChild($ideProdutor);
309
                }
310
311
                $ideEstabAdquir->appendChild($tpAquis);
312
            }
313
        }
314
315
        $infoAquisProd->appendChild($ideEstabAdquir);
316
        $this->node->appendChild($infoAquisProd);
317
318
        $this->eSocial->appendChild($this->node);
319
        $this->sign();
320
    }
321
}
322