Conditions | 7 |
Paths | 2 |
Total Lines | 123 |
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 |
||
205 | protected function v020500() |
||
206 | { |
||
207 | $exMedOcup = $this->dom->createElement("exMedOcup"); |
||
208 | $this->dom->addChild( |
||
209 | $exMedOcup, |
||
210 | "tpExameOcup", |
||
211 | $this->std->exmedocup->tpexameocup, |
||
212 | true |
||
213 | ); |
||
214 | $stdaso = $this->std->exmedocup->aso; |
||
215 | $aso = $this->dom->createElement("aso"); |
||
216 | $this->dom->addChild( |
||
217 | $aso, |
||
218 | "dtAso", |
||
219 | $stdaso->dtaso, |
||
220 | true |
||
221 | ); |
||
222 | $this->dom->addChild( |
||
223 | $aso, |
||
224 | "resAso", |
||
225 | $stdaso->resaso, |
||
226 | true |
||
227 | ); |
||
228 | |||
229 | foreach ($this->std->exmedocup->aso->exame as $exa) { |
||
230 | $exame = $this->dom->createElement("exame"); |
||
231 | $this->dom->addChild( |
||
232 | $exame, |
||
233 | "dtExm", |
||
234 | $exa->dtexm, |
||
235 | true |
||
236 | ); |
||
237 | $this->dom->addChild( |
||
238 | $exame, |
||
239 | "procRealizado", |
||
240 | $exa->procrealizado, |
||
241 | true |
||
242 | ); |
||
243 | $this->dom->addChild( |
||
244 | $exame, |
||
245 | "obsProc", |
||
246 | !empty($exa->obsproc) ? $exa->obsproc : null, |
||
247 | false |
||
248 | ); |
||
249 | $this->dom->addChild( |
||
250 | $exame, |
||
251 | "ordExame", |
||
252 | $exa->ordexame, |
||
253 | true |
||
254 | ); |
||
255 | $this->dom->addChild( |
||
256 | $exame, |
||
257 | "indResult", |
||
258 | !empty($exa->indresult) ? $exa->indresult : null, |
||
259 | false |
||
260 | ); |
||
261 | $aso->appendChild($exame); |
||
262 | } |
||
263 | |||
264 | $stdmed = $this->std->exmedocup->aso->medico; |
||
265 | $medico = $this->dom->createElement("medico"); |
||
266 | $this->dom->addChild( |
||
267 | $medico, |
||
268 | "cpfMed", |
||
269 | !empty($stdmed->cpfmed) ? $stdmed->cpfmed : null, |
||
270 | false |
||
271 | ); |
||
272 | $this->dom->addChild( |
||
273 | $medico, |
||
274 | "nisMed", |
||
275 | !empty($stdmed->nismed) ? $stdmed->nismed : null, |
||
276 | false |
||
277 | ); |
||
278 | $this->dom->addChild( |
||
279 | $medico, |
||
280 | "nmMed", |
||
281 | $stdmed->nmmed, |
||
282 | true |
||
283 | ); |
||
284 | $this->dom->addChild( |
||
285 | $medico, |
||
286 | "nrCRM", |
||
287 | $stdmed->nrcrm, |
||
288 | true |
||
289 | ); |
||
290 | $this->dom->addChild( |
||
291 | $medico, |
||
292 | "ufCRM", |
||
293 | $stdmed->ufcrm, |
||
294 | true |
||
295 | ); |
||
296 | $aso->appendChild($medico); |
||
297 | $exMedOcup->appendChild($aso); |
||
298 | |||
299 | $stdmon = $this->std->exmedocup->respmonit; |
||
300 | $monit = $this->dom->createElement("respMonit"); |
||
301 | $this->dom->addChild( |
||
302 | $monit, |
||
303 | "cpfResp", |
||
304 | !empty($stdmon->cpfresp) ? $stdmon->cpfresp : null, |
||
305 | false |
||
306 | ); |
||
307 | $this->dom->addChild( |
||
308 | $monit, |
||
309 | "nmResp", |
||
310 | $stdmon->nmresp, |
||
311 | true |
||
312 | ); |
||
313 | $this->dom->addChild( |
||
314 | $monit, |
||
315 | "nrCRM", |
||
316 | $stdmon->nrcrm, |
||
317 | true |
||
318 | ); |
||
319 | $this->dom->addChild( |
||
320 | $monit, |
||
321 | "ufCRM", |
||
322 | $stdmon->ufcrm, |
||
323 | true |
||
324 | ); |
||
325 | $exMedOcup->appendChild($monit); |
||
326 | $this->node->appendChild($exMedOcup); |
||
327 | } |
||
328 | |||
337 |
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: