Completed
Pull Request — master (#227)
by Roberto
03:27
created

EvtBasesFGTS::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 2
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtBasesFGTS Event S-5003 constructor
7
 * Read for 2.5.0 layout
8
 *
9
 * @category  library
10
 * @package   NFePHP\eSocial
11
 * @copyright NFePHP Copyright (c) 2017-2019
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
19
use NFePHP\Common\Certificate;
20
use NFePHP\eSocial\Common\Factory;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtBasesFGTS extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
    /**
31
     * @var string
32
     */
33
    protected $evtName = 'evtBasesFGTS';
34
    /**
35
     * @var string
36
     */
37
    protected $evtAlias = 'S-5003';
38
    /**
39
     * Parameters patterns
40
     *
41
     * @var array
42
     */
43
    protected $parameters = [];
44
45
    /**
46
     * Constructor
47
     *
48
     * @param string $config
49
     * @param stdClass $std
50
     * @param Certificate $certificate | null
51
     * @param string $date
52
     */
53
    public function __construct(
54
        $config,
55
        stdClass $std,
56
        Certificate $certificate = null,
57
        $date = ''
58
    ) {
59
        parent::__construct($config, $std, $certificate, $date);
60
    }
61
62
    /**
63
     * Node constructor
64
     */
65
    protected function toNode()
66
    {
67
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
68
        //o idEvento pode variar de evento para evento
69
        //então cada factory individualmente terá de construir o seu
70
        $ideEvento = $this->dom->createElement("ideEvento");
71
        $this->dom->addChild(
72
            $ideEvento,
73
            "nrRecArqBase",
74
            !empty($this->std->nrrecarqbase) ? $this->std->nrrecarqbase : null,
75
            false
76
        );
77
        $this->dom->addChild(
78
            $ideEvento,
79
            "perApur",
80
            $this->std->perapur,
81
            true
82
        );
83
        $this->node->insertBefore($ideEvento, $ideEmpregador);
84
        
85
        $ide = $this->dom->createElement("ideTrabalhador");
86
        $this->dom->addChild(
87
            $ide,
88
            "cpfTrab",
89
            $this->std->cpftrab,
90
            true
91
        );
92
        $this->dom->addChild(
93
            $ide,
94
            "nisTrab",
95
            !empty($this->std->nistrab) ? $this->std->nistrab : null,
96
            false
97
        );
98
        $this->node->appendChild($ide);
99
        
100
        if (!empty($this->std->infofgts)) {
101
            $info = $this->std->infofgts;
102
            $infoFGTS = $this->dom->createElement("infoFGTS");
103
            $this->dom->addChild(
104
                $infoFGTS,
105
                "dtVenc",
106
                !empty($info->dtvenc) ? $info->dtvenc : null,
107
                false
108
            );
109
            foreach ($info->ideestablot as $isl) {
110
                $ideEstabLot = $this->dom->createElement("ideEstabLot");
111
                $this->dom->addChild(
112
                    $ideEstabLot,
113
                    "tpInsc",
114
                    $isl->tpinsc,
115
                    true
116
                );
117
                $this->dom->addChild(
118
                    $ideEstabLot,
119
                    "nrInsc",
120
                    $isl->nrinsc,
121
                    true
122
                );
123
                $this->dom->addChild(
124
                    $ideEstabLot,
125
                    "codLotacao",
126
                    $isl->codlotacao,
127
                    true
128
                );
129
                foreach ($isl->infotrabfgts as $itf) {
130
                    $infoTrabFGTS = $this->dom->createElement("infoTrabFGTS");
131
                    $this->dom->addChild(
132
                        $infoTrabFGTS,
133
                        "matricula",
134
                        !empty($itf->matricula) ? $itf->matricula : null,
135
                        false
136
                    );
137
                    $this->dom->addChild(
138
                        $infoTrabFGTS,
139
                        "codCateg",
140
                        $itf->codcateg,
141
                        true
142
                    );
143
                    $this->dom->addChild(
144
                        $infoTrabFGTS,
145
                        "dtAdm",
146
                        !empty($itf->dtadm) ? $itf->dtadm : null,
147
                        false
148
                    );
149
                    $this->dom->addChild(
150
                        $infoTrabFGTS,
151
                        "dtDeslig",
152
                        !empty($itf->dtdeslig) ? $itf->dtdeslig : null,
153
                        false
154
                    );
155
                    $this->dom->addChild(
156
                        $infoTrabFGTS,
157
                        "dtInicio",
158
                        !empty($itf->dtinicio) ? $itf->dtinicio : null,
159
                        false
160
                    );
161
                    $this->dom->addChild(
162
                        $infoTrabFGTS,
163
                        "mtvDeslig",
164
                        !empty($itf->mtvdeslig) ? $itf->mtvdeslig : null,
165
                        false
166
                    );
167
                    $this->dom->addChild(
168
                        $infoTrabFGTS,
169
                        "dtTerm",
170
                        !empty($itf->dtterm) ? $itf->dtterm : null,
171
                        false
172
                    );
173
                    $this->dom->addChild(
174
                        $infoTrabFGTS,
175
                        "mtvDesligTSV",
176
                        !empty($itf->mtvdesligtsv) ? $itf->mtvdesligtsv : null,
177
                        false
178
                    );
179
                    
180
                    if (!empty($itf->infobasefgts)) {
181
                        $ibf = $itf->infobasefgts;
182
                        $infoBaseFGTS = $this->dom->createElement("infoBaseFGTS");
183
                        if ($ibf->baseperapur) {
184
                            foreach ($ibf->baseperapur as $bpa) {
185
                                $basePerApur = $this->dom->createElement("basePerApur");
186
                                $this->dom->addChild(
187
                                    $basePerApur,
188
                                    "tpValor",
189
                                    $bpa->tpvalor,
190
                                    true
191
                                );
192
                                $this->dom->addChild(
193
                                    $basePerApur,
194
                                    "remFGTS",
195
                                    number_format($bpa->remfgts, 2, ".", ""),
196
                                    true
197
                                );
198
                                $infoBaseFGTS->appendChild($basePerApur);
199
                            }
200
                        }
201
                        
202
                        if ($ibf->infobaseperante) {
203
                            foreach ($ibf->infobaseperante as $ibpae) {
204
                                $infoBasePerAntE = $this->dom->createElement("infoBasePerAntE");
205
                                $this->dom->addChild(
206
                                    $infoBasePerAntE,
207
                                    "perRef",
208
                                    $ibpae->perref,
209
                                    true
210
                                );
211
                                foreach ($ibpae->baseperante as $bpae) {
212
                                    $basePerAntE = $this->dom->createElement("basePerAntE");
213
                                    $this->dom->addChild(
214
                                        $basePerAntE,
215
                                        "tpValorE",
216
                                        $bpae->tpvalore,
217
                                        true
218
                                    );
219
                                    $this->dom->addChild(
220
                                        $basePerAntE,
221
                                        "remFGTSE",
222
                                        number_format($bpae->remfgtse, 2, ".", ""),
223
                                        true
224
                                    );
225
                                    $infoBasePerAntE->appendChild($basePerAntE);
226
                                }
227
                                $infoBaseFGTS->appendChild($infoBasePerAntE);
228
                            }
229
                        }
230
                        $infoTrabFGTS->appendChild($infoBaseFGTS);
231
                    }
232
                    $ideEstabLot->appendChild($infoTrabFGTS);
233
                }
234
                $infoFGTS->appendChild($ideEstabLot);
235
            }
236
            
237
            if (!empty($info->infodpsfgts)) {
238
                $idps = $info->infodpsfgts;
239
                $infoDpsFGTS = $this->dom->createElement("infoDpsFGTS");
240
                foreach ($idps->infotrabdps as $itdps) {
241
                    $infoTrabDps = $this->dom->createElement("infoTrabDps");
242
                    $this->dom->addChild(
243
                        $infoTrabDps,
244
                        "matricula",
245
                        !empty($itdps->matricula) ? $itdps->matricula : null,
246
                        false
247
                    );
248
                    $this->dom->addChild(
249
                        $infoTrabDps,
250
                        "codCateg",
251
                        $itdps->codcateg,
252
                        true
253
                    );
254
                    
255
                    if (!empty($itdps->dpsperapur)) {
256
                        foreach ($itdps->dpsperapur as $dpsapp) {
257
                            $dpsPerApur = $this->dom->createElement("dpsPerApur");
258
                            $this->dom->addChild(
259
                                $dpsPerApur,
260
                                "tpDps",
261
                                $dpsapp->tpdps,
262
                                true
263
                            );
264
                            $this->dom->addChild(
265
                                $dpsPerApur,
266
                                "dpsFGTS",
267
                                number_format($dpsapp->dpsfgts, 2, ".", ""),
268
                                true
269
                            );
270
                            $infoTrabDps->appendChild($dpsPerApur);
271
                        }
272
                    }
273
                    
274
                    if (!empty($itdps->infodpsperante)) {
275
                        foreach ($itdps->infodpsperante as $ipae) {
276
                            $infoDpsPerAntE = $this->dom->createElement("infoDpsPerAntE");
277
                            $this->dom->addChild(
278
                                $infoDpsPerAntE,
279
                                "perRef",
280
                                $ipae->perref,
281
                                true
282
                            );
283
                            foreach ($ipae->dpsperante as $dpspae) {
284
                                $dpsPerAntE = $this->dom->createElement("dpsPerAntE");
285
                                $this->dom->addChild(
286
                                    $dpsPerAntE,
287
                                    "tpDpsE",
288
                                    $dpspae->tpdpse,
289
                                    true
290
                                );
291
                                $this->dom->addChild(
292
                                    $dpsPerAntE,
293
                                    "dpsFGTSE",
294
                                    number_format($dpspae->dpsfgtse, 2, ".", ""),
295
                                    true
296
                                );
297
                                $infoDpsPerAntE->appendChild($dpsPerAntE);
298
                            }
299
                            $infoTrabDps->appendChild($infoDpsPerAntE);
300
                        }
301
                    }
302
                    $infoDpsFGTS->appendChild($infoTrabDps);
303
                }
304
                $infoFGTS->appendChild($infoDpsFGTS);
305
            }
306
            $this->node->appendChild($infoFGTS);
307
        }
308
        $this->eSocial->appendChild($this->node);
309
        //$this->xml = $this->dom->saveXML($this->node);
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...
310
        $this->sign();
311
    }
312
}
313