Test Failed
Pull Request — master (#107)
by
unknown
05:40
created

EvtAfastTemp::toNode()   D

Complexity

Conditions 15
Paths 32

Size

Total Lines 266
Code Lines 181

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 266
ccs 0
cts 50
cp 0
rs 4.9121
c 1
b 0
f 0
cc 15
eloc 181
nc 32
nop 0
crap 240

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\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtAfastTemp Event S-2230 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 EvtAfastTemp extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtAfastTemp';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'S-2230';
39
    /**
40
     * Parameters patterns
41
     *
42
     * @var array
43
     */
44
    protected $parameters = [];
45
46
    /**
47
     * Constructor
48
     *
49
     * @param string      $config
50
     * @param stdClass    $std
51
     * @param Certificate $certificate
52
     */
53
    public function __construct(
54
        $config,
55
        stdClass $std,
56
        Certificate $certificate
57
    ) {
58
        parent::__construct($config, $std, $certificate);
59
    }
60
61
    /**
62
     * Node constructor
63
     */
64
    protected function toNode()
65
    {
66
        $evtid = FactoryId::build(
67
            $this->tpInsc,
68
            $this->nrInsc,
69
            $this->date,
70
            $this->sequencial
71
        );
72
73
        $evtAfastTemp = $this->dom->createElement("evtAfastTemp");
74
75
        $att = $this->dom->createAttribute('Id');
76
77
        $att->value = $evtid;
78
79
        $evtAfastTemp->appendChild($att);
80
81
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
82
83
        $ideEvento = $this->dom->createElement("ideEvento");
84
        $this->dom->addChild(
85
            $ideEvento,
86
            "indRetif",
87
            $this->std->indretif,
88
            true
89
        );
90
        $this->dom->addChild(
91
            $ideEvento,
92
            "tpAmb",
93
            $this->tpAmb,
94
            true
95
        );
96
        $this->dom->addChild(
97
            $ideEvento,
98
            "procEmi",
99
            $this->procEmi,
100
            true
101
        );
102
        $this->dom->addChild(
103
            $ideEvento,
104
            "verProc",
105
            $this->verProc,
106
            true
107
        );
108
        $evtAfastTemp->appendChild($ideEvento);
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
        $this->dom->addChild(
133
            $ideVinculo,
134
            "codCateg",
135
            !empty($this->std->idevinculo->codcateg) ? $this->std->idevinculo->codcateg : null,
136
            false
137
        );
138
        $this->node->appendChild($ideVinculo);
139
140
        $infoAfastamento = $this->dom->createElement("infoAfastamento");
141
142
        $iniAfastamento = $this->dom->createElement("iniAfastamento");
143
144
        $this->dom->addChild(
145
            $iniAfastamento,
146
            "dtIniAfast",
147
            $this->std->iniafastamento->dtiniafast,
148
            true
149
        );
150
151
        $this->dom->addChild(
152
            $iniAfastamento,
153
            "codMotAfast",
154
            $this->std->iniafastamento->codmotafast,
155
            true
156
        );
157
158
        $this->dom->addChild(
159
            $iniAfastamento,
160
            "infoMesmoMtv",
161
            !empty($this->std->iniafastamento->infomesmomtv) ? $this->std->iniafastamento->infomesmomtv : null,
162
            false
163
        );
164
165
        $this->dom->addChild(
166
            $iniAfastamento,
167
            "tpAcidTransito",
168
            !empty($this->std->iniafastamento->tpacidtransito) ? $this->std->iniafastamento->tpacidtransito : null,
169
            false
170
        );
171
172
        $this->dom->addChild(
173
            $iniAfastamento,
174
            "observacao",
175
            !empty($this->std->iniafastamento->observacao) ? $this->std->iniafastamento->observacao : null,
176
            false
177
        );
178
179
        if (isset($this->std->iniafastamento->infoatestado)) {
180
            foreach ($this->std->iniafastamento->infoatestado as $info) {
181
                $infoAtestado = $this->dom->createElement("infoAtestado");
182
183
                $this->dom->addChild(
184
                    $infoAtestado,
185
                    "codCID",
186
                    !empty($info->codcid) ? $info->codcid : null,
187
                    false
188
                );
189
190
                $this->dom->addChild(
191
                    $infoAtestado,
192
                    "qtdDiasAfast",
193
                    $info->qtddiasafast,
194
                    true
195
                );
196
197
                if (isset($info->emitente)) {
198
                    $emitente = $this->dom->createElement("emitente");
199
200
                    $this->dom->addChild(
201
                        $emitente,
202
                        "nmEmit",
203
                        $info->emitente->nmemit,
204
                        true
205
                    );
206
207
                    $this->dom->addChild(
208
                        $emitente,
209
                        "ideOC",
210
                        $info->emitente->ideoc,
211
                        true
212
                    );
213
214
                    $this->dom->addChild(
215
                        $emitente,
216
                        "nrOc",
217
                        $info->emitente->nroc,
218
                        true
219
                    );
220
221
                    $this->dom->addChild(
222
                        $emitente,
223
                        "ufOC",
224
                        !empty($info->emitente->ufoc) ? $info->emitente->ufoc : null,
225
                        false
226
                    );
227
228
                    $infoAtestado->appendChild($emitente);
229
                }
230
231
                $iniAfastamento->appendChild($infoAtestado);
232
            }
233
        }
234
235
        if (!empty($this->std->infocessao)) {
236
            $infoCessao = $this->dom->createElement("infoCessao");
237
238
            $this->dom->addChild(
239
                $infoCessao,
240
                "cnpjCess",
241
                $this->std->infocessao->cnpjcess,
242
                true
243
            );
244
245
            $this->dom->addChild(
246
                $infoCessao,
247
                "infOnus",
248
                $this->std->infocessao->infonus,
249
                true
250
            );
251
252
            $iniAfastamento->appendChild($infoCessao);
253
        }
254
255
        if (!empty($this->std->infomandsind)) {
256
            $infoMandSind = $this->dom->createElement("infoMandSind");
257
258
            $this->dom->addChild(
259
                $infoMandSind,
260
                "cnpjSind",
261
                $this->std->infomandsind->cnpjsind,
262
                true
263
            );
264
265
            $this->dom->addChild(
266
                $infoMandSind,
267
                "infOnusRemun",
268
                $this->std->infomandsind->infonusremun,
269
                true
270
            );
271
272
            $iniAfastamento->appendChild($infoMandSind);
273
        }
274
275
        $infoAfastamento->appendChild($iniAfastamento);
276
277
        if (!empty($this->std->inforetif)) {
278
            $infoRetif = $this->dom->createElement("infoRetif");
279
280
            $this->dom->addChild(
281
                $infoRetif,
282
                "origRetif",
283
                $this->std->inforetif->origretif,
284
                true
285
            );
286
287
            $this->dom->addChild(
288
                $infoRetif,
289
                "tpProc",
290
                $this->std->inforetif->tpproc,
291
                true
292
            );
293
294
            $this->dom->addChild(
295
                $infoRetif,
296
                "nrProc",
297
                !empty($this->std->inforetif->nrproc) ? $this->std->inforetif->nrproc : null,
298
                false
299
            );
300
301
            $infoAfastamento->appendChild($infoRetif);
302
        }
303
304
        if (!empty($this->std->fimafastamento)) {
305
            $fimAfastamento = $this->dom->createElement("fimAfastamento");
306
307
            $this->dom->addChild(
308
                $fimAfastamento,
309
                "dtTermAfast",
310
                $this->std->fimafastamento->dttermafast,
311
                true
312
            );
313
314
            $this->dom->addChild(
315
                $fimAfastamento,
316
                "codMotAfast",
317
                $this->std->fimafastamento->codmotafast,
318
                true
319
            );
320
321
322
            $infoAfastamento->appendChild($fimAfastamento);
323
        }
324
325
        $this->node->appendChild($infoAfastamento);
326
327
        $this->eSocial->appendChild($this->node);
328
        $this->sign();
329
    }
330
}
331