Conditions | 6 |
Paths | 2 |
Total Lines | 109 |
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 | "indApuracao", |
||
31 | $this->std->indapuracao, |
||
32 | true |
||
33 | ); |
||
34 | $this->dom->addChild( |
||
35 | $ideEvento, |
||
36 | "perApur", |
||
37 | $this->std->perapur, |
||
38 | true |
||
39 | ); |
||
40 | $this->dom->addChild( |
||
41 | $ideEvento, |
||
42 | "tpAmb", |
||
43 | $this->tpAmb, |
||
44 | true |
||
45 | ); |
||
46 | $this->dom->addChild( |
||
47 | $ideEvento, |
||
48 | "procEmi", |
||
49 | $this->procEmi, |
||
50 | true |
||
51 | ); |
||
52 | $this->dom->addChild( |
||
53 | $ideEvento, |
||
54 | "verProc", |
||
55 | $this->verProc, |
||
56 | true |
||
57 | ); |
||
58 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
59 | $ideBenef = $this->dom->createElement("ideBenef"); |
||
60 | $this->dom->addChild( |
||
61 | $ideBenef, |
||
62 | "cpfBenef", |
||
63 | $this->std->cpfbenef, |
||
64 | true |
||
65 | ); |
||
66 | $this->node->appendChild($ideBenef); |
||
67 | if (isset($this->std->dmdev)) { |
||
68 | foreach ($this->std->dmdev as $dev) { |
||
69 | $dmDev = $this->dom->createElement("dmDev"); |
||
70 | $this->dom->addChild( |
||
71 | $dmDev, |
||
72 | "tpBenef", |
||
73 | $dev->tpbenef, |
||
74 | true |
||
75 | ); |
||
76 | $this->dom->addChild( |
||
77 | $dmDev, |
||
78 | "nrBenefic", |
||
79 | $dev->nrbenefic, |
||
80 | true |
||
81 | ); |
||
82 | $this->dom->addChild( |
||
83 | $dmDev, |
||
84 | "ideDmDev", |
||
85 | $dev->idedmdev, |
||
86 | true |
||
87 | ); |
||
88 | if (isset($dev->itens)) { |
||
89 | foreach ($dev->itens as $item) { |
||
90 | $itens = $this->dom->createElement("itens"); |
||
91 | $this->dom->addChild( |
||
92 | $itens, |
||
93 | "codRubr", |
||
94 | $item->codrubr, |
||
95 | true |
||
96 | ); |
||
97 | $this->dom->addChild( |
||
98 | $itens, |
||
99 | "ideTabRubr", |
||
100 | $item->idetabrubr, |
||
101 | true |
||
102 | ); |
||
103 | $this->dom->addChild( |
||
104 | $itens, |
||
105 | "vrRubr", |
||
106 | $item->vrrubr, |
||
107 | true |
||
108 | ); |
||
109 | $dmDev->appendChild($itens); |
||
110 | } |
||
111 | } |
||
112 | $this->node->appendChild($dmDev); |
||
113 | } |
||
114 | } |
||
115 | $this->eSocial->appendChild($this->node); |
||
116 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
117 | $this->sign(); |
||
118 | } |
||
119 | |||
128 |
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: