Passed
Push — master ( feaf84...03ed34 )
by Roberto
06:49 queued 18s
created

EvtMonit::toNode()   C

Complexity

Conditions 11
Paths 4

Size

Total Lines 193
Code Lines 157

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 193
ccs 0
cts 188
cp 0
rs 5.2653
c 1
b 0
f 0
cc 11
eloc 157
nc 4
nop 0
crap 132

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 EvtMonit Event S-2220 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
19
use NFePHP\Common\Certificate;
20
use NFePHP\eSocial\Common\Factory;
21
use NFePHP\eSocial\Common\FactoryId;
22
use NFePHP\eSocial\Common\FactoryInterface;
23
use stdClass;
24
25
class EvtMonit extends Factory implements FactoryInterface
26
{
27
    /**
28
     * @var int
29
     */
30
    public $sequencial;
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtMonit';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'S-2220';
39
40
    /**
41
     * Constructor
42
     * @param string $config
43
     * @param stdClass $std
44
     * @param Certificate $certificate
45
     */
46
    public function __construct(
47
        $config,
48
        stdClass $std,
49
        Certificate $certificate
50
    ) {
51
        parent::__construct($config, $std, $certificate);
52
    }
53
54
    /**
55
     * Node constructor
56
     */
57
    protected function toNode()
58
    {
59
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
60
        //o idEvento pode variar de evento para evento
61
        //então cada factory individualmente terá de construir o seu
62
        $ideEvento = $this->dom->createElement("ideEvento");
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "indRetif",
66
            $this->std->indretif,
67
            true
68
        );
69
        $this->dom->addChild(
70
            $ideEvento,
71
            "tpAmb",
72
            $this->tpAmb,
73
            true
74
        );
75
        $this->dom->addChild(
76
            $ideEvento,
77
            "procEmi",
78
            $this->procEmi,
79
            true
80
        );
81
        $this->dom->addChild(
82
            $ideEvento,
83
            "verProc",
84
            $this->verProc,
85
            true
86
        );
87
        $this->node->insertBefore($ideEvento, $ideEmpregador);
88
        $ideVinculo = $this->dom->createElement("ideVinculo");
89
        $this->dom->addChild(
90
            $ideVinculo,
91
            "cpfTrab",
92
            $this->std->idevinculo->cpftrab,
93
            true
94
        );
95
        $this->dom->addChild(
96
            $ideVinculo,
97
            "nisTrab",
98
            $this->std->idevinculo->nistrab,
99
            true
100
        );
101
        $this->dom->addChild(
102
            $ideVinculo,
103
            "matricula",
104
            $this->std->idevinculo->matricula,
105
            true
106
        );
107
        $this->node->appendChild($ideVinculo);
108
        $aso = $this->dom->createElement("aso");
109
        $this->dom->addChild(
110
            $aso,
111
            "dtAso",
112
            $this->std->aso->dtaso,
113
            true
114
        );
115
        $this->dom->addChild(
116
            $aso,
117
            "tpAso",
118
            $this->std->aso->tpaso,
119
            true
120
        );
121
        $this->dom->addChild(
122
            $aso,
123
            "resAso",
124
            $this->std->aso->resaso,
125
            true
126
        );
127
        if (isset($this->std->exame)) {
128
            foreach ($this->std->exame as $exam) {
129
                $exame = $this->dom->createElement("exame");
130
                $this->dom->addChild(
131
                    $exame,
132
                    "dtExm",
133
                    $exam->dtexm,
134
                    true
135
                );
136
                $this->dom->addChild(
137
                    $exame,
138
                    "procRealizado",
139
                    ! empty($exam->procrealizado) ? $exam->procrealizado : null,
140
                    false
141
                );
142
                $this->dom->addChild(
143
                    $exame,
144
                    "obsProc",
145
                    ! empty($exam->obsproc) ? $exam->obsproc : null,
146
                    false
147
                );
148
                $this->dom->addChild(
149
                    $exame,
150
                    "interprExm",
151
                    $exam->interprexm,
152
                    true
153
                );
154
                $this->dom->addChild(
155
                    $exame,
156
                    "ordExame",
157
                    $exam->ordexame,
158
                    true
159
                );
160
                $this->dom->addChild(
161
                    $exame,
162
                    "dtIniMonit",
163
                    $exam->dtinimonit,
164
                    true
165
                );
166
                $this->dom->addChild(
167
                    $exame,
168
                    "dtFimMonit",
169
                    ! empty($exam->dtfimmonit) ? $exam->dtfimmonit : null,
170
                    false
171
                );
172
                $this->dom->addChild(
173
                    $exame,
174
                    "indResult",
175
                    ! empty($exam->indresult) ? $exam->indresult : null,
176
                    false
177
                );
178
                $aso->appendChild($exame);
179
            }
180
        }
181
        $respMonit = $this->dom->createElement("respMonit");
182
        $this->dom->addChild(
183
            $respMonit,
184
            "nisResp",
185
            $this->std->respmonit->nisresp,
186
            true
187
        );
188
        $this->dom->addChild(
189
            $respMonit,
190
            "nrConsClasse",
191
            $this->std->respmonit->nrconsclasse,
192
            true
193
        );
194
        $this->dom->addChild(
195
            $respMonit,
196
            "ufConsClasse",
197
            ! empty($this->std->respmonit->ufconsclasse) ? $this->std->respmonit->ufconsclasse : null,
198
            false
199
        );
200
        isset($exame) ? $exame->appendChild($respMonit) : null;
201
        $ideServSaude = $this->dom->createElement("ideServSaude");
202
        $this->dom->addChild(
203
            $ideServSaude,
204
            "codCNES",
205
            ! empty($this->std->ideservsaude->codcnes) ? $this->std->ideservsaude->codcnes : null,
206
            false
207
        );
208
        $this->dom->addChild(
209
            $ideServSaude,
210
            "frmCtt",
211
            $this->std->ideservsaude->frmctt,
212
            true
213
        );
214
        $this->dom->addChild(
215
            $ideServSaude,
216
            "email",
217
            ! empty($this->std->ideservsaude->email) ? $this->std->ideservsaude->email : null,
218
            false
219
        );
220
        $aso->appendChild($ideServSaude);
221
        $medico = $this->dom->createElement("medico");
222
        $this->dom->addChild(
223
            $medico,
224
            "nmMed",
225
            $this->std->medico->nmmed,
226
            true
227
        );
228
        $ideServSaude->appendChild($medico);
229
        $crm = $this->dom->createElement("crm");
230
        $this->dom->addChild(
231
            $crm,
232
            "nrCRM",
233
            $this->std->medico->nrcrm,
234
            true
235
        );
236
        $this->dom->addChild(
237
            $crm,
238
            "ufCRM",
239
            $this->std->medico->ufcrm,
240
            true
241
        );
242
        $medico->appendChild($crm);
243
        $this->node->appendChild($aso);
244
245
        //finalização do xml
246
        $this->eSocial->appendChild($this->node);
247
        $this->sign();
248
        //$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...
249
    }
250
}
251