Completed
Pull Request — master (#126)
by
unknown
07:30
created

EvtInsApo   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 358
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 30
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 358
ccs 0
cts 257
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
F toNode() 0 315 29
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtInsApo Event S-2241 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 EvtInsApo extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtInsApo';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-2241';
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
        $evtInsApo = $this->dom->createElement("evtInsApo");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtInsApo->appendChild($att);
82
83
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
84
85
        $ideEvento = $this->dom->createElement("ideEvento");
86
        $this->dom->addChild(
87
            $ideEvento,
88
            "indRetif",
89
            $this->std->indretif,
90
            true
91
        );
92
        $this->dom->addChild(
93
            $ideEvento,
94
            "tpAmb",
95
            $this->tpAmb,
96
            true
97
        );
98
        $this->dom->addChild(
99
            $ideEvento,
100
            "procEmi",
101
            $this->procEmi,
102
            true
103
        );
104
        $this->dom->addChild(
105
            $ideEvento,
106
            "verProc",
107
            $this->verProc,
108
            true
109
        );
110
        $this->node->insertBefore($ideEvento, $ideEmpregador);
111
112
        $ideVinculo = $this->dom->createElement("ideVinculo");
113
114
        $this->dom->addChild(
115
            $ideVinculo,
116
            "cpfTrab",
117
            $this->std->idevinculo->cpftrab,
118
            true
119
        );
120
        $this->dom->addChild(
121
            $ideVinculo,
122
            "nisTrab",
123
            $this->std->idevinculo->nistrab,
124
            true
125
        );
126
        $this->dom->addChild(
127
            $ideVinculo,
128
            "matricula",
129
            $this->std->idevinculo->matricula,
130
            true
131
        );
132
133
        $this->node->appendChild($ideVinculo);
134
135
        if (isset($this->std->insalperic)) {
136
            $insalPeric = $this->dom->createElement("insalPeric");
137
138
            if (isset($this->std->insalperic->iniinsalperic)) {
139
                $iniInsalPeric = $this->dom->createElement("iniInsalPeric");
140
141
                $this->dom->addChild(
142
                    $iniInsalPeric,
143
                    "dtIniCondicao",
144
                    $this->std->insalperic->iniinsalperic->dtinicondicao,
145
                    true
146
                );
147
148
                if (isset($this->std->insalperic->iniinsalperic->infoamb)) {
149
                    foreach ($this->std->insalperic->iniinsalperic->infoamb as $amb) {
150
                        $infoAmb = $this->dom->createElement("infoAmb");
151
152
                        $this->dom->addChild(
153
                            $infoAmb,
154
                            "codAmb",
155
                            $amb->codamb,
156
                            true
157
                        );
158
159
                        if (isset($amb->fatrisco)) {
160
                            foreach ($amb->fatrisco as $risco) {
161
                                $fatRisco = $this->dom->createElement("fatRisco");
162
163
                                $this->dom->addChild(
164
                                    $fatRisco,
165
                                    "codFatRis",
166
                                    $risco->codfatris,
167
                                    true
168
                                );
169
170
                                $infoAmb->appendChild($fatRisco);
171
                            }
172
                        }
173
174
                        $iniInsalPeric->appendChild($infoAmb);
175
                    }
176
                }
177
178
                $insalPeric->appendChild($iniInsalPeric);
179
            }
180
181
            if (isset($this->std->insalperic->altinsalperic)) {
182
                $altInsalPeric = $this->dom->createElement("altInsalPeric");
183
184
                $this->dom->addChild(
185
                    $altInsalPeric,
186
                    "dtAltCondicao",
187
                    $this->std->insalperic->altinsalperic->dtaltcondicao,
188
                    true
189
                );
190
191
                if (isset($this->std->insalperic->altinsalperic->infoamb)) {
192
                    foreach ($this->std->insalperic->altinsalperic->infoamb as $amb) {
193
                        $infoAmb = $this->dom->createElement("infoamb");
194
195
                        $this->dom->addChild(
196
                            $infoAmb,
197
                            "codAmb",
198
                            $amb->codamb,
199
                            true
200
                        );
201
202
                        if (isset($amb->fatrisco)) {
203
                            foreach ($amb->fatrisco as $risco) {
204
                                $fatRisco = $this->dom->createElement("fatRisco");
205
206
                                $this->dom->addChild(
207
                                    $fatRisco,
208
                                    "codFatRis",
209
                                    $risco->codfatris,
210
                                    true
211
                                );
212
213
                                $infoAmb->appendChild($fatRisco);
214
                            }
215
                        }
216
217
                        $altInsalPeric->appendChild($infoAmb);
218
                    }
219
                }
220
221
                $insalPeric->appendChild($altInsalPeric);
222
            }
223
224
            if (isset($this->std->insalperic->fiminsalperic)) {
225
                $fimInsalPeric = $this->dom->createElement("fimInsalPeric");
226
227
                $this->dom->addChild(
228
                    $fimInsalPeric,
229
                    "dtFimCondicao",
230
                    $this->std->insalperic->fiminsalperic->dtfimcondicao,
231
                    true
232
                );
233
234
                if (isset($this->std->insalperic->fiminsalperic->infoamb)) {
235
                    foreach ($this->std->insalperic->fiminsalperic->infoamb as $amb) {
236
                        $infoAmb = $this->dom->createElement("infoAmb");
237
238
                        $this->dom->addChild(
239
                            $infoAmb,
240
                            "codAmb",
241
                            $amb->codamb,
242
                            true
243
                        );
244
245
246
                        $fimInsalPeric->appendChild($infoAmb);
247
                    }
248
                }
249
250
                $insalPeric->appendChild($fimInsalPeric);
251
            }
252
253
254
            $this->node->appendChild($insalPeric);
255
        }
256
257
        if (isset($this->std->aposentesp)) {
258
            $aposentEsp = $this->dom->createElement("aposentEsp");
259
260
            if (isset($this->std->aposentesp->iniaposentesp)) {
261
                $iniAposentEsp = $this->dom->createElement("iniAposentEsp");
262
263
                $this->dom->addChild(
264
                    $iniAposentEsp,
265
                    "dtIniCondicao",
266
                    $this->std->aposentesp->iniaposentesp->dtinicondicao,
267
                    true
268
                );
269
270
                if (isset($this->std->aposentesp->iniaposentesp->infoamb)) {
271
                    foreach ($this->std->aposentesp->iniaposentesp->infoamb as $amb) {
272
                        $infoAmb = $this->dom->createElement("infoAmb");
273
274
                        $this->dom->addChild(
275
                            $infoAmb,
276
                            "codAmb",
277
                            $amb->codamb,
278
                            true
279
                        );
280
281
                        if (isset($amb->fatrisco)) {
282
                            foreach ($amb->fatrisco as $risco) {
283
                                $fatRisco = $this->dom->createElement("fatRisco");
284
285
                                $this->dom->addChild(
286
                                    $fatRisco,
287
                                    "codFatRis",
288
                                    $risco->codfatris,
289
                                    true
290
                                );
291
292
                                $infoAmb->appendChild($fatRisco);
293
                            }
294
                        }
295
296
                        $iniAposentEsp->appendChild($infoAmb);
297
                    }
298
                }
299
300
                $aposentEsp->appendChild($iniAposentEsp);
301
            }
302
303
            if (isset($this->std->aposentesp->altaposentesp)) {
304
                $altAposentEsp = $this->dom->createElement("altAposentEsp");
305
306
                $this->dom->addChild(
307
                    $altAposentEsp,
308
                    "dtAltCondicao",
309
                    $this->std->aposentesp->altaposentesp->dtaltcondicao,
310
                    true
311
                );
312
313
                if (isset($this->std->aposentesp->altaposentesp->infoamb)) {
314
                    foreach ($this->std->aposentesp->altaposentesp->infoamb as $amb) {
315
                        $infoAmb = $this->dom->createElement("infoamb");
316
317
                        $this->dom->addChild(
318
                            $infoAmb,
319
                            "codAmb",
320
                            $amb->codamb,
321
                            true
322
                        );
323
324
                        if (isset($amb->fatrisco)) {
325
                            foreach ($amb->fatrisco as $risco) {
326
                                $fatRisco = $this->dom->createElement("fatRisco");
327
328
                                $this->dom->addChild(
329
                                    $fatRisco,
330
                                    "codFatRis",
331
                                    $risco->codfatris,
332
                                    true
333
                                );
334
335
                                $infoAmb->appendChild($fatRisco);
336
                            }
337
                        }
338
339
                        $altAposentEsp->appendChild($infoAmb);
340
                    }
341
                }
342
343
                $aposentEsp->appendChild($altAposentEsp);
344
            }
345
346
            if (isset($this->std->aposentesp->fimaposentesp)) {
347
                $fimAposentEsp = $this->dom->createElement("fimAposentEsp");
348
349
                $this->dom->addChild(
350
                    $fimAposentEsp,
351
                    "dtFimCondicao",
352
                    $this->std->aposentesp->fimaposentesp->dtfimcondicao,
353
                    true
354
                );
355
356
                if (isset($this->std->aposentesp->fimaposentesp->infoamb)) {
357
                    foreach ($this->std->aposentesp->fimaposentesp->infoamb as $amb) {
358
                        $infoAmb = $this->dom->createElement("infoAmb");
359
360
                        $this->dom->addChild(
361
                            $infoAmb,
362
                            "codAmb",
363
                            $amb->codamb,
364
                            true
365
                        );
366
367
368
                        $fimAposentEsp->appendChild($infoAmb);
369
                    }
370
                }
371
372
                $aposentEsp->appendChild($fimAposentEsp);
373
            }
374
375
            $this->node->appendChild($aposentEsp);
376
        }
377
378
        $this->eSocial->appendChild($this->node);
379
        $this->sign();
380
    }
381
}
382