Conditions | 17 |
Paths | 72 |
Total Lines | 340 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
10 | protected function toNode250() |
||
11 | { |
||
12 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
|
|||
13 | //o idEvento pode variar de evento para evento |
||
14 | //então cada factory individualmente terá de construir o seu |
||
15 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
16 | $this->dom->addChild( |
||
17 | $ideEvento, |
||
18 | "indRetif", |
||
19 | $this->std->indretif, |
||
20 | true |
||
21 | ); |
||
22 | $this->dom->addChild( |
||
23 | $ideEvento, |
||
24 | "nrRecibo", |
||
25 | !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null, |
||
26 | false |
||
27 | ); |
||
28 | $this->dom->addChild( |
||
29 | $ideEvento, |
||
30 | "tpAmb", |
||
31 | $this->tpAmb, |
||
32 | true |
||
33 | ); |
||
34 | $this->dom->addChild( |
||
35 | $ideEvento, |
||
36 | "procEmi", |
||
37 | $this->procEmi, |
||
38 | true |
||
39 | ); |
||
40 | $this->dom->addChild( |
||
41 | $ideEvento, |
||
42 | "verProc", |
||
43 | $this->verProc, |
||
44 | true |
||
45 | ); |
||
46 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
47 | |||
48 | $ideBenef = $this->dom->createElement("ideBenef"); |
||
49 | $iben = $this->std->idebenef; |
||
50 | $this->dom->addChild( |
||
51 | $ideBenef, |
||
52 | "cpfBenef", |
||
53 | $iben->cpfbenef, |
||
54 | true |
||
55 | ); |
||
56 | $this->dom->addChild( |
||
57 | $ideBenef, |
||
58 | "nmBenefic", |
||
59 | $iben->nmbenefic, |
||
60 | true |
||
61 | ); |
||
62 | $this->node->appendChild($ideBenef); |
||
63 | |||
64 | $dadosBenef = $this->dom->createElement("dadosBenef"); |
||
65 | |||
66 | $dadosNasc = $this->dom->createElement("dadosNasc"); |
||
67 | $diben = $this->std->idebenef->dadosbenef->dadosnasc; |
||
68 | $this->dom->addChild( |
||
69 | $dadosNasc, |
||
70 | "dtNascto", |
||
71 | $diben->dtnascto, |
||
72 | true |
||
73 | ); |
||
74 | $this->dom->addChild( |
||
75 | $dadosNasc, |
||
76 | "codMunic", |
||
77 | !empty($diben->codmunic) ? $diben->codmunic : null, |
||
78 | false |
||
79 | ); |
||
80 | $this->dom->addChild( |
||
81 | $dadosNasc, |
||
82 | "uf", |
||
83 | !empty($diben->uf) ? $diben->uf : null, |
||
84 | false |
||
85 | ); |
||
86 | $this->dom->addChild( |
||
87 | $dadosNasc, |
||
88 | "paisNascto", |
||
89 | $diben->paisnascto, |
||
90 | true |
||
91 | ); |
||
92 | $this->dom->addChild( |
||
93 | $dadosNasc, |
||
94 | "paisNac", |
||
95 | $diben->paisnac, |
||
96 | true |
||
97 | ); |
||
98 | $this->dom->addChild( |
||
99 | $dadosNasc, |
||
100 | "nmMae", |
||
101 | !empty($diben->nmmae) ? $diben->nmmae : null, |
||
102 | false |
||
103 | ); |
||
104 | $this->dom->addChild( |
||
105 | $dadosNasc, |
||
106 | "nmPai", |
||
107 | !empty($diben->nmpai) ? |
||
108 | $diben->nmpai : null, |
||
109 | false |
||
110 | ); |
||
111 | $dadosBenef->appendChild($dadosNasc); |
||
112 | $endereco = $this->dom->createElement("endereco"); |
||
113 | if (isset($this->std->idebenef->dadosbenef->endereco->brasil)) { |
||
114 | $br = $this->std->idebenef->dadosbenef->endereco->brasil; |
||
115 | $brasil = $this->dom->createElement("brasil"); |
||
116 | $this->dom->addChild( |
||
117 | $brasil, |
||
118 | "tpLograd", |
||
119 | $br->tplograd, |
||
120 | true |
||
121 | ); |
||
122 | $this->dom->addChild( |
||
123 | $brasil, |
||
124 | "dscLograd", |
||
125 | $br->dsclograd, |
||
126 | true |
||
127 | ); |
||
128 | $this->dom->addChild( |
||
129 | $brasil, |
||
130 | "nrLograd", |
||
131 | $br->nrlograd, |
||
132 | true |
||
133 | ); |
||
134 | $this->dom->addChild( |
||
135 | $brasil, |
||
136 | "complemento", |
||
137 | !empty($br->complemento) ? $br->complemento : null, |
||
138 | false |
||
139 | ); |
||
140 | $this->dom->addChild( |
||
141 | $brasil, |
||
142 | "bairro", |
||
143 | !empty($br->bairro) ? $br->bairro : null, |
||
144 | false |
||
145 | ); |
||
146 | $this->dom->addChild( |
||
147 | $brasil, |
||
148 | "cep", |
||
149 | $br->cep, |
||
150 | true |
||
151 | ); |
||
152 | $this->dom->addChild( |
||
153 | $brasil, |
||
154 | "codMunic", |
||
155 | $br->codmunic, |
||
156 | true |
||
157 | ); |
||
158 | |||
159 | $this->dom->addChild( |
||
160 | $brasil, |
||
161 | "uf", |
||
162 | $br->uf, |
||
163 | true |
||
164 | ); |
||
165 | $endereco->appendChild($brasil); |
||
166 | } |
||
167 | |||
168 | if (isset($this->std->idebenef->dadosbenef->endereco->exterior)) { |
||
169 | $ext = $this->std->idebenef->dadosbenef->endereco->exterior; |
||
170 | $exterior = $this->dom->createElement("exterior"); |
||
171 | |||
172 | $this->dom->addChild( |
||
173 | $exterior, |
||
174 | "paisResid", |
||
175 | $ext->paisresid, |
||
176 | true |
||
177 | ); |
||
178 | $this->dom->addChild( |
||
179 | $exterior, |
||
180 | "dscLograd", |
||
181 | $ext->dsclograd, |
||
182 | true |
||
183 | ); |
||
184 | $this->dom->addChild( |
||
185 | $exterior, |
||
186 | "nrLograd", |
||
187 | $ext->nrlograd, |
||
188 | true |
||
189 | ); |
||
190 | $this->dom->addChild( |
||
191 | $exterior, |
||
192 | "complemento", |
||
193 | !empty($ext->complemento) ? $ext->complemento : null, |
||
194 | false |
||
195 | ); |
||
196 | $this->dom->addChild( |
||
197 | $exterior, |
||
198 | "bairro", |
||
199 | !empty($ext->bairro) ? $ext->bairro : null, |
||
200 | false |
||
201 | ); |
||
202 | $this->dom->addChild( |
||
203 | $exterior, |
||
204 | "nmCid", |
||
205 | $ext->nmcid, |
||
206 | true |
||
207 | ); |
||
208 | $this->dom->addChild( |
||
209 | $exterior, |
||
210 | "codPostal", |
||
211 | $ext->codpostal, |
||
212 | true |
||
213 | ); |
||
214 | $endereco->appendChild($exterior); |
||
215 | } |
||
216 | $dadosBenef->appendChild($endereco); |
||
217 | $ideBenef->appendChild($dadosBenef); |
||
218 | $infoBeneficio = $this->dom->createElement("infoBeneficio"); |
||
219 | $this->dom->addChild( |
||
220 | $infoBeneficio, |
||
221 | "tpPlanRP", |
||
222 | $this->std->infobeneficio->tpplanrp, |
||
223 | true |
||
224 | ); |
||
225 | $this->node->appendChild($infoBeneficio); |
||
226 | if (isset($this->std->infobeneficio->inibeneficio)) { |
||
227 | $iben = $this->std->infobeneficio->inibeneficio; |
||
228 | $iniBeneficio = $this->dom->createElement("iniBeneficio"); |
||
229 | $this->dom->addChild( |
||
230 | $iniBeneficio, |
||
231 | "tpBenef", |
||
232 | $iben->tpbenef, |
||
233 | true |
||
234 | ); |
||
235 | $this->dom->addChild( |
||
236 | $iniBeneficio, |
||
237 | "nrBenefic", |
||
238 | $iben->nrbenefic, |
||
239 | true |
||
240 | ); |
||
241 | $this->dom->addChild( |
||
242 | $iniBeneficio, |
||
243 | "dtIniBenef", |
||
244 | $iben->dtinibenef, |
||
245 | true |
||
246 | ); |
||
247 | $this->dom->addChild( |
||
248 | $iniBeneficio, |
||
249 | "vrBenef", |
||
250 | $iben->vrbenef, |
||
251 | true |
||
252 | ); |
||
253 | if (isset($iben->infopenmorte)) { |
||
254 | $infoPenMorte = $this->dom->createElement("infoPenMorte"); |
||
255 | $this->dom->addChild( |
||
256 | $infoPenMorte, |
||
257 | "idQuota", |
||
258 | $iben->infopenmorte->idquota, |
||
259 | true |
||
260 | ); |
||
261 | $this->dom->addChild( |
||
262 | $infoPenMorte, |
||
263 | "cpfInst", |
||
264 | $iben->infopenmorte->cpfinst, |
||
265 | true |
||
266 | ); |
||
267 | $iniBeneficio->appendChild($infoPenMorte); |
||
268 | } |
||
269 | $infoBeneficio->appendChild($iniBeneficio); |
||
270 | } |
||
271 | |||
272 | if (isset($this->std->infobeneficio->altbeneficio)) { |
||
273 | $iben = $this->std->infobeneficio->altbeneficio; |
||
274 | $altBeneficio = $this->dom->createElement("altBeneficio"); |
||
275 | $this->dom->addChild( |
||
276 | $altBeneficio, |
||
277 | "tpBenef", |
||
278 | $iben->tpbenef, |
||
279 | true |
||
280 | ); |
||
281 | $this->dom->addChild( |
||
282 | $altBeneficio, |
||
283 | "nrBenefic", |
||
284 | $iben->nrbenefic, |
||
285 | true |
||
286 | ); |
||
287 | $this->dom->addChild( |
||
288 | $altBeneficio, |
||
289 | "dtIniBenef", |
||
290 | $iben->dtinibenef, |
||
291 | true |
||
292 | ); |
||
293 | $this->dom->addChild( |
||
294 | $altBeneficio, |
||
295 | "vrBenef", |
||
296 | $iben->vrbenef, |
||
297 | true |
||
298 | ); |
||
299 | if (isset($iben->infopenmorte)) { |
||
300 | $infoPenMorte = $this->dom->createElement("infoPenMorte"); |
||
301 | $this->dom->addChild( |
||
302 | $infoPenMorte, |
||
303 | "idQuota", |
||
304 | $iben->infopenmorte->idquota, |
||
305 | true |
||
306 | ); |
||
307 | $this->dom->addChild( |
||
308 | $infoPenMorte, |
||
309 | "cpfInst", |
||
310 | $iben->infopenmorte->cpfinst, |
||
311 | true |
||
312 | ); |
||
313 | $altBeneficio->appendChild($infoPenMorte); |
||
314 | } |
||
315 | $infoBeneficio->appendChild($altBeneficio); |
||
316 | } |
||
317 | if (isset($this->std->infobeneficio->fimbeneficio)) { |
||
318 | $fim = $this->std->infobeneficio->fimbeneficio; |
||
319 | $fimBeneficio = $this->dom->createElement("fimBeneficio"); |
||
320 | $this->dom->addChild( |
||
321 | $fimBeneficio, |
||
322 | "tpBenef", |
||
323 | $fim->tpbenef, |
||
324 | true |
||
325 | ); |
||
326 | $this->dom->addChild( |
||
327 | $fimBeneficio, |
||
328 | "nrBenefic", |
||
329 | $fim->nrbenefic, |
||
330 | true |
||
331 | ); |
||
332 | $this->dom->addChild( |
||
333 | $fimBeneficio, |
||
334 | "dtFimBenef", |
||
335 | $fim->dtfimbenef, |
||
336 | true |
||
337 | ); |
||
338 | $this->dom->addChild( |
||
339 | $fimBeneficio, |
||
340 | "mtvFim", |
||
341 | $fim->mtvfim, |
||
342 | true |
||
343 | ); |
||
344 | $infoBeneficio->appendChild($fimBeneficio); |
||
345 | } |
||
346 | $this->eSocial->appendChild($this->node); |
||
347 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
348 | $this->sign(); |
||
349 | } |
||
350 | |||
359 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: