Passed
Push — master ( f31a42...920d28 )
by Roberto
03:52
created

EvtAqProd::toNode()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 80

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 80
ccs 0
cts 76
cp 0
rs 8.4362
c 0
b 0
f 0
cc 4
nc 3
nop 0
crap 20

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
 * Read for 2.4.2 layout
8
 *
9
 * @category  library
10
 * @package   NFePHP\eSocial
11
 * @copyright NFePHP Copyright (c) 2017
12
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
13
 * @license   https://opensource.org/licenses/MIT MIT
14
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
15
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
16
 * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository
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
    /**
28
     * @var int
29
     */
30
    public $sequencial;
31
32
    /**
33
     * @var string
34
     */
35
    protected $evtName = 'evtAqProd';
36
37
    /**
38
     * @var string
39
     */
40
    protected $evtAlias = 'S-1250';
41
42
    /**
43
     * Parameters patterns
44
     *
45
     * @var array
46
     */
47
    protected $parameters = [];
48
49
    /**
50
     * Constructor
51
     *
52
     * @param string $config
53
     * @param stdClass $std
54
     * @param Certificate $certificate | null
55
     * @param string $date
56
     */
57
    public function __construct(
58
        $config,
59
        stdClass $std,
60
        Certificate $certificate = null,
61
        $date = ''
62
    ) {
63
64
        parent::__construct($config, $std, $certificate, $date);
65
    }
66
67
    /**
68
     * Node constructor
69
     */
70
    protected function toNode()
71
    {
72
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
73
        //o idEvento pode variar de evento para evento
74
        //então cada factory individualmente terá de construir o seu
75
        $ideEvento = $this->dom->createElement("ideEvento");
76
        $this->dom->addChild(
77
            $ideEvento,
78
            "indRetif",
79
            $this->std->indretif,
80
            true
81
        );
82
        $this->dom->addChild(
83
            $ideEvento,
84
            "nrRecibo",
85
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
86
            false
87
        );
88
        $this->dom->addChild(
89
            $ideEvento,
90
            "indApuracao",
91
            $this->std->indapuracao,
92
            true
93
        );
94
        $this->dom->addChild(
95
            $ideEvento,
96
            "perApur",
97
            $this->std->perapur,
98
            true
99
        );
100
        $this->dom->addChild(
101
            $ideEvento,
102
            "tpAmb",
103
            $this->tpAmb,
104
            true
105
        );
106
        $this->dom->addChild(
107
            $ideEvento,
108
            "procEmi",
109
            $this->procEmi,
110
            true
111
        );
112
        $this->dom->addChild(
113
            $ideEvento,
114
            "verProc",
115
            $this->verProc,
116
            true
117
        );
118
        $this->node->insertBefore($ideEvento, $ideEmpregador);
119
120
        $infoAquisProd = $this->dom->createElement("infoAquisProd");
121
        $ideEstabAdquir = $this->dom->createElement("ideEstabAdquir");
122
        $this->dom->addChild(
123
            $ideEstabAdquir,
124
            "tpInscAdq",
125
            $this->std->ideestabadquir->tpinscadq,
126
            true
127
        );
128
        $this->dom->addChild(
129
            $ideEstabAdquir,
130
            "nrInscAdq",
131
            $this->std->ideestabadquir->nrinscadq,
132
            true
133
        );
134
        if (isset($this->std->ideestabadquir->tpaquis)) {
135
            if ($this->layoutStr !== 'v02_05_00') {
136
                $this->tpAquis($ideEstabAdquir, $this->std->ideestabadquir->tpaquis);
137
            } else {
138
                $this->tpAquisV020500(
139
                    $ideEstabAdquir,
140
                    $this->std->ideestabadquir->tpaquis
141
                );
142
            }
143
        }
144
        $infoAquisProd->appendChild($ideEstabAdquir);
145
        $this->node->appendChild($infoAquisProd);
146
        $this->eSocial->appendChild($this->node);
147
        //$this->xml = $this->dom->saveXML($this->eSocial);
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...
148
        $this->sign();
149
    }
150
    
151
    /**
152
     * Estrutura do tpAquin v2.4.2
153
     * @param DOMElement $ideEstabAdquir
154
     * @param stdClass $tpaquis
155
     */
156
    protected function tpAquis(&$ideEstabAdquir, $tpaquis)
157
    {
158
        foreach ($tpaquis as $tp) {
0 ignored issues
show
Bug introduced by
The expression $tpaquis of type object<stdClass> is not traversable.
Loading history...
159
            $tpAquis = $this->dom->createElement("tpAquis");
160
161
            $this->dom->addChild(
162
                $tpAquis,
163
                "indAquis",
164
                $tp->indaquis,
165
                true
166
            );
167
168
            $this->dom->addChild(
169
                $tpAquis,
170
                "vlrTotAquis",
171
                $tp->vlrtotaquis,
172
                true
173
            );
174
            foreach ($tp->ideprodutor as $ideprod) {
175
                $ideProdutor = $this->dom->createElement("ideProdutor");
176
                $this->dom->addChild(
177
                    $ideProdutor,
178
                    "tpInscProd",
179
                    $ideprod->tpinscprod,
180
                    true
181
                );
182
                $this->dom->addChild(
183
                    $ideProdutor,
184
                    "nrInscProd",
185
                    $ideprod->nrinscprod,
186
                    true
187
                );
188
                $this->dom->addChild(
189
                    $ideProdutor,
190
                    "vlrBruto",
191
                    $ideprod->vlrbruto,
192
                    true
193
                );
194
                $this->dom->addChild(
195
                    $ideProdutor,
196
                    "vrCPDescPR",
197
                    $ideprod->vrcpdescpr,
198
                    true
199
                );
200
                $this->dom->addChild(
201
                    $ideProdutor,
202
                    "vrRatDescPR",
203
                    $ideprod->vrratdescpr,
204
                    true
205
                );
206
                $this->dom->addChild(
207
                    $ideProdutor,
208
                    "vrSenarDesc",
209
                    $ideprod->vrsenardesc,
210
                    true
211
                );
212
                if (isset($ideprod->nfs)) {
213
                    foreach ($ideprod->nfs as $prodnfs) {
214
                        $nfs = $this->dom->createElement("nfs");
215
                        $this->dom->addChild(
216
                            $nfs,
217
                            "serie",
218
                            !empty($prodnfs->serie) ? $prodnfs->serie : null,
219
                            false
220
                        );
221
                        $this->dom->addChild(
222
                            $nfs,
223
                            "nrDocto",
224
                            $prodnfs->nrdocto,
225
                            true
226
                        );
227
                        $this->dom->addChild(
228
                            $nfs,
229
                            "dtEmisNF",
230
                            $prodnfs->dtemisnf,
231
                            true
232
                        );
233
                        $this->dom->addChild(
234
                            $nfs,
235
                            "vlrBruto",
236
                            $prodnfs->vlrbruto,
237
                            true
238
                        );
239
                        $this->dom->addChild(
240
                            $nfs,
241
                            "vrCPDescPR",
242
                            $prodnfs->vrcpdescpr,
243
                            true
244
                        );
245
                        $this->dom->addChild(
246
                            $nfs,
247
                            "vrRatDescPR",
248
                            $prodnfs->vrratdescpr,
249
                            true
250
                        );
251
                        $this->dom->addChild(
252
                            $nfs,
253
                            "vrSenarDesc",
254
                            $prodnfs->vrsenardesc,
255
                            true
256
                        );
257
                        $ideProdutor->appendChild($nfs);
258
                    }
259
                }
260
                if (isset($ideprod->infoprocjud)) {
261
                    foreach ($ideprod->infoprocjud as $prodprocjud) {
262
                        $infoProcJud = $this->dom->createElement("infoProcJud");
263
                        $this->dom->addChild(
264
                            $infoProcJud,
265
                            "nrProcJud",
266
                            $prodprocjud->nrprocjud,
267
                            true
268
                        );
269
                        $this->dom->addChild(
270
                            $infoProcJud,
271
                            "codSusp",
272
                            $prodprocjud->codsusp,
273
                            true
274
                        );
275
                        $this->dom->addChild(
276
                            $infoProcJud,
277
                            "vrCPNRet",
278
                            $prodprocjud->vrcpnret,
279
                            true
280
                        );
281
                        $this->dom->addChild(
282
                            $infoProcJud,
283
                            "vrRatNRet",
284
                            $prodprocjud->vrratnret,
285
                            true
286
                        );
287
                        $this->dom->addChild(
288
                            $infoProcJud,
289
                            "vrSenarNRet",
290
                            $prodprocjud->vrsenarnret,
291
                            true
292
                        );
293
                        $ideProdutor->appendChild($infoProcJud);
294
                    }
295
                }
296
                $tpAquis->appendChild($ideProdutor);
297
            }
298
            $ideEstabAdquir->appendChild($tpAquis);
299
        }
300
    }
301
    
302
    /**
303
     * Grandes altereções de estrutura na tag tpAquis
304
     * @param DOMElement $ideEstabAdquir
305
     * @param stdClass $tpaquis
306
     */
307
    protected function tpAquisV020500(&$ideEstabAdquir, $tpaquis)
308
    {
309
        foreach ($tpaquis as $tp) {
0 ignored issues
show
Bug introduced by
The expression $tpaquis of type object<stdClass> is not traversable.
Loading history...
310
            $tpAquis = $this->dom->createElement("tpAquis");
311
            $tpAquis->setAttribute('indAquis', $tp->indaquis);
312
            $tpAquis->setAttribute(
313
                'vlrTotAquis',
314
                number_format($tp->vlrtotaquis, 2, '.', '')
315
            );
316
            foreach ($tp->ideprodutor as $ideprod) {
317
                $ideProdutor = $this->dom->createElement("ideProdutor");
318
                $ideProdutor->setAttribute('tpInscProd', $ideprod->tpinscprod);
319
                $ideProdutor->setAttribute('nrInscProd', $ideprod->nrinscprod);
320
                $ideProdutor->setAttribute(
321
                    'vlrBruto',
322
                    number_format($ideprod->vlrbruto, 2, '.', '')
323
                );
324
                $ideProdutor->setAttribute(
325
                    'vrCPDescPR',
326
                    number_format($ideprod->vrcpdescpr, 2, '.', '')
327
                );
328
                $ideProdutor->setAttribute(
329
                    'vrRatDescPR',
330
                    number_format($ideprod->vrratdescpr, 2, '.', '')
331
                );
332
                $ideProdutor->setAttribute(
333
                    'vrSenarDesc',
334
                    number_format($ideprod->vrsenardesc, 2, '.', '')
335
                );
336
                $ideProdutor->setAttribute('indOpcCP', $ideprod->indopccp);
337
338
                foreach ($ideprod->nfs as $prodnfs) {
339
                    $nfs = $this->dom->createElement("nfs");
340
                    !empty($prodnfs->serie) ? $nfs->setAttribute('serie', $prodnfs->serie) : null;
341
                    $nfs->setAttribute('nrDocto', $prodnfs->nrdocto);
342
                    $nfs->setAttribute('dtEmisNF', $prodnfs->dtemisnf);
343
                    $nfs->setAttribute(
344
                        'vlrBruto',
345
                        number_format($prodnfs->vlrbruto, 2, '.', '')
346
                    );
347
                    $nfs->setAttribute(
348
                        'vrCPDescPR',
349
                        number_format($prodnfs->vrcpdescpr, 2, '.', '')
350
                    );
351
                    $nfs->setAttribute(
352
                        'vrRatDescPR',
353
                        number_format($prodnfs->vrratdescpr, 2, '.', '')
354
                    );
355
                    $nfs->setAttribute(
356
                        'vrSenarDesc',
357
                        number_format($prodnfs->vrsenardesc, 2, '.', '')
358
                    );
359
                    $ideProdutor->appendChild($nfs);
360
                }
361
                foreach ($ideprod->infoprocjud as $prodprocjud) {
362
                    $infoProcJud = $this->dom->createElement("infoProcJud");
363
                    $infoProcJud->setAttribute('nrProcJud', $prodprocjud->nrprocjud);
364
                    $infoProcJud->setAttribute('codSusp', $prodprocjud->codsusp);
365
                    $infoProcJud->setAttribute(
366
                        'vrCPNRet',
367
                        number_format($prodprocjud->vrcpnret, 2, '.', '')
368
                    );
369
                    $infoProcJud->setAttribute(
370
                        'vrRatNRet',
371
                        number_format($prodprocjud->vrratnret, 2, '.', '')
372
                    );
373
                    $infoProcJud->setAttribute(
374
                        'vrSenarNRet',
375
                        number_format($prodprocjud->vrsenarnret, 2, '.', '')
376
                    );
377
                    $ideProdutor->appendChild($infoProcJud);
378
                }
379
                $tpAquis->appendChild($ideProdutor);
380
                if (!empty($tp->infoprocj)) {
381
                    foreach ($tp->infoprocj as $procjud) {
382
                        $procJ = $this->dom->createElement("infoProcJ");
383
                        $procJ->setAttribute('nrProcJud', $procjud->nrprocjud);
384
                        $procJ->setAttribute('codSusp', $procjud->codsusp);
385
                        $procJ->setAttribute(
386
                            'vrCPNRet',
387
                            number_format($procjud->vrcpnret, 2, '.', '')
388
                        );
389
                        $procJ->setAttribute(
390
                            'vrRatNRet',
391
                            number_format($procjud->vrratnret, 2, '.', '')
392
                        );
393
                        $procJ->setAttribute(
394
                            'vrSenarNRet',
395
                            number_format($procjud->vrsenarnret, 2, '.', '')
396
                        );
397
                        $tpAquis->appendChild($procJ);
398
                    }
399
                }
400
            }
401
            $ideEstabAdquir->appendChild($tpAquis);
402
        }
403
    }
404
}
405