Passed
Push — master ( 60293e...5490e2 )
by Roberto
03:17
created

EvtMonit::v020500()   B

Complexity

Conditions 7
Paths 2

Size

Total Lines 123

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 123
ccs 0
cts 120
cp 0
rs 7.0666
c 0
b 0
f 0
cc 7
nc 2
nop 0
crap 56

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
namespace NFePHP\eSocial\Factories;
3
4
/**
5
 * Class eSocial EvtMonit Event S-2220 constructor
6
 * Read for 2.4.2 layout
7
 *
8
 * @category  library
9
 * @package   NFePHP\eSocial
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
use NFePHP\Common\Certificate;
18
use NFePHP\eSocial\Common\Factory;
19
use NFePHP\eSocial\Common\FactoryId;
20
use NFePHP\eSocial\Common\FactoryInterface;
21
use stdClass;
22
23
class EvtMonit extends Factory implements FactoryInterface
24
{
25
    /**
26
     * @var int
27
     */
28
    public $sequencial;
29
    /**
30
     * @var string
31
     */
32
    protected $evtName = 'evtMonit';
33
    /**
34
     * @var string
35
     */
36
    protected $evtAlias = 'S-2220';
37
    /**
38
     * Constructor
39
     *
40
     * @param string $config
41
     * @param stdClass $std
42
     * @param Certificate $certificate | null
43
     * @param string $date
44
     */
45
    public function __construct(
46
        $config,
47
        stdClass $std,
48
        Certificate $certificate = null,
49
        $date = ''
50
    ) {
51
        parent::__construct($config, $std, $certificate, $date);
52
    }
53
    /**
54
     * Node constructor
55
     */
56
    protected function toNode()
57
    {
58
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
59
        //o idEvento pode variar de evento para evento
60
        //então cada factory individualmente terá de construir o seu
61
        $ideEvento = $this->dom->createElement("ideEvento");
62
        $this->dom->addChild(
63
            $ideEvento,
64
            "indRetif",
65
            $this->std->indretif,
66
            true
67
        );
68
        $this->dom->addChild(
69
            $ideEvento,
70
            "tpAmb",
71
            $this->tpAmb,
72
            true
73
        );
74
        $this->dom->addChild(
75
            $ideEvento,
76
            "procEmi",
77
            $this->procEmi,
78
            true
79
        );
80
        $this->dom->addChild(
81
            $ideEvento,
82
            "verProc",
83
            $this->verProc,
84
            true
85
        );
86
        $this->node->insertBefore($ideEvento, $ideEmpregador);
87
        $ideVinculo = $this->dom->createElement("ideVinculo");
88
        $this->dom->addChild(
89
            $ideVinculo,
90
            "cpfTrab",
91
            $this->std->idevinculo->cpftrab,
92
            true
93
        );
94
        $this->dom->addChild(
95
            $ideVinculo,
96
            "nisTrab",
97
            $this->std->idevinculo->nistrab,
98
            true
99
        );
100
        $this->dom->addChild(
101
            $ideVinculo,
102
            "matricula",
103
            $this->std->idevinculo->matricula,
104
            true
105
        );
106
        $this->node->appendChild($ideVinculo);
107
        
108
        if ($this->layoutStr !== 'v02_05_00') {
109
            $aso = $this->dom->createElement("aso");
110
            $this->dom->addChild(
111
                $aso,
112
                "dtAso",
113
                $this->std->aso->dtaso,
114
                true
115
            );
116
            $this->dom->addChild(
117
                $aso,
118
                "tpAso",
119
                $this->std->aso->tpaso,
120
                true
121
            );
122
            $this->dom->addChild(
123
                $aso,
124
                "resAso",
125
                $this->std->aso->resaso,
126
                true
127
            );
128
            if (isset($this->std->aso->exame)) {
129
                foreach ($this->std->aso->exame as $exa) {
130
                    $exame = $this->dom->createElement("exame");
131
                    $this->dom->addChild(
132
                        $exame,
133
                        "dtExm",
134
                        $exa->dtexm,
135
                        true
136
                    );
137
                    $this->dom->addChild(
138
                        $exame,
139
                        "procRealizado",
140
                        !empty($exa->procrealizado) ? $exa->procrealizado : null,
141
                        false
142
                    );
143
                    $this->dom->addChild(
144
                        $exame,
145
                        "obsProc",
146
                        !empty($exa->obsproc) ? $exa->obsproc : null,
147
                        false
148
                    );
149
                    $this->dom->addChild(
150
                        $exame,
151
                        "interprExm",
152
                        $exa->interprexm,
153
                        true
154
                    );
155
                    $this->dom->addChild(
156
                        $exame,
157
                        "ordExame",
158
                        $exa->ordexame,
159
                        true
160
                    );
161
                    $this->dom->addChild(
162
                        $exame,
163
                        "dtIniMonit",
164
                        $exa->dtinimonit,
165
                        true
166
                    );
167
                    $this->dom->addChild(
168
                        $exame,
169
                        "dtFimMonit",
170
                        !empty($exa->dtfimmonit) ? $exa->dtfimmonit : null,
171
                        false
172
                    );
173
                    $this->dom->addChild(
174
                        $exame,
175
                        "indResult",
176
                        !empty($exa->indresult) ? $exa->indresult : null,
177
                        false
178
                    );
179
                    $respMonit = $this->dom->createElement("respMonit");
180
                    $resm = $exa->respmonit;
181
                    $this->dom->addChild(
182
                        $respMonit,
183
                        "nisResp",
184
                        $resm->nisresp,
185
                        true
186
                    );
187
                    $this->dom->addChild(
188
                        $respMonit,
189
                        "nrConsClasse",
190
                        $resm->nrconsclasse,
191
                        true
192
                    );
193
                    $this->dom->addChild(
194
                        $respMonit,
195
                        "ufConsClasse",
196
                        !empty($resm->ufconsclasse) ? $resm->ufconsclasse : null,
197
                        false
198
                    );
199
                    $exame->appendChild($respMonit);
200
                    $aso->appendChild($exame);
201
                }
202
            }
203
            $ideServSaude = $this->dom->createElement("ideServSaude");
204
            $sers = $this->std->aso->ideservsaude;
205
            $this->dom->addChild(
206
                $ideServSaude,
207
                "codCNES",
208
                !empty($sers->codcnes) ? $sers->codcnes : null,
209
                false
210
            );
211
            $this->dom->addChild(
212
                $ideServSaude,
213
                "frmCtt",
214
                $sers->frmctt,
215
                true
216
            );
217
            $this->dom->addChild(
218
                $ideServSaude,
219
                "email",
220
                !empty($sers->email) ? $sers->email : null,
221
                false
222
            );
223
            $medico = $this->dom->createElement("medico");
224
            $med = $sers->medico;
225
            $this->dom->addChild(
226
                $medico,
227
                "nmMed",
228
                $med->nmmed,
229
                true
230
            );
231
            $crm = $this->dom->createElement("crm");
232
            $this->dom->addChild(
233
                $crm,
234
                "nrCRM",
235
                $med->nrcrm,
236
                true
237
            );
238
            $this->dom->addChild(
239
                $crm,
240
                "ufCRM",
241
                $med->ufcrm,
242
                true
243
            );
244
            $medico->appendChild($crm);
245
            $ideServSaude->appendChild($medico);
246
            $aso->appendChild($ideServSaude);
247
            $this->node->appendChild($aso);
248
        } else {
249
            $this->v020500();
250
        }
251
        //finalização do xml
252
        $this->eSocial->appendChild($this->node);
253
        //$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...
254
        $this->sign();
255
    }
256
    
257
    protected function v020500()
258
    {
259
        $exMedOcup = $this->dom->createElement("exMedOcup");
260
        $this->dom->addChild(
261
            $exMedOcup,
262
            "tpExameOcup",
263
            $this->std->exmedocup->tpexameocup,
264
            true
265
        );
266
        $stdaso = $this->std->exmedocup->aso;
267
        $aso = $this->dom->createElement("aso");
268
        $this->dom->addChild(
269
            $aso,
270
            "dtAso",
271
            $stdaso->dtaso,
272
            true
273
        );
274
        $this->dom->addChild(
275
            $aso,
276
            "resAso",
277
            $stdaso->resaso,
278
            true
279
        );
280
        
281
        foreach ($this->std->exmedocup->aso->exame as $exa) {
282
            $exame = $this->dom->createElement("exame");
283
            $this->dom->addChild(
284
                $exame,
285
                "dtExm",
286
                $exa->dtexm,
287
                true
288
            );
289
            $this->dom->addChild(
290
                $exame,
291
                "procRealizado",
292
                $exa->procrealizado,
293
                true
294
            );
295
            $this->dom->addChild(
296
                $exame,
297
                "obsProc",
298
                !empty($exa->obsproc) ? $exa->obsproc : null,
299
                false
300
            );
301
            $this->dom->addChild(
302
                $exame,
303
                "ordExame",
304
                $exa->ordexame,
305
                true
306
            );
307
            $this->dom->addChild(
308
                $exame,
309
                "indResult",
310
                !empty($exa->indresult) ? $exa->indresult : null,
311
                false
312
            );
313
            $aso->appendChild($exame);
314
        }
315
        
316
        $stdmed = $this->std->exmedocup->aso->medico;
317
        $medico = $this->dom->createElement("medico");
318
        $this->dom->addChild(
319
            $medico,
320
            "cpfMed",
321
            !empty($stdmed->cpfmed) ? $stdmed->cpfmed : null,
322
            false
323
        );
324
        $this->dom->addChild(
325
            $medico,
326
            "nisMed",
327
            !empty($stdmed->nismed) ? $stdmed->nismed : null,
328
            false
329
        );
330
        $this->dom->addChild(
331
            $medico,
332
            "nmMed",
333
            $stdmed->nmmed,
334
            true
335
        );
336
        $this->dom->addChild(
337
            $medico,
338
            "nrCRM",
339
            $stdmed->nrcrm,
340
            true
341
        );
342
        $this->dom->addChild(
343
            $medico,
344
            "ufCRM",
345
            $stdmed->ufcrm,
346
            true
347
        );
348
        $aso->appendChild($medico);
349
        $exMedOcup->appendChild($aso);
350
        
351
        $stdmon = $this->std->exmedocup->respmonit;
352
        $monit = $this->dom->createElement("respMonit");
353
        $this->dom->addChild(
354
            $monit,
355
            "cpfResp",
356
            !empty($stdmon->cpfresp) ? $stdmon->cpfresp : null,
357
            false
358
        );
359
        $this->dom->addChild(
360
            $monit,
361
            "nmResp",
362
            $stdmon->nmresp,
363
            true
364
        );
365
        $this->dom->addChild(
366
            $monit,
367
            "nrCRM",
368
            $stdmon->nrcrm,
369
            true
370
        );
371
        $this->dom->addChild(
372
            $monit,
373
            "ufCRM",
374
            $stdmon->ufcrm,
375
            true
376
        );
377
        $exMedOcup->appendChild($monit);
378
        $this->node->appendChild($exMedOcup);
379
    }
380
}
381