Conditions | 18 |
Paths | 102 |
Total Lines | 217 |
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 | "tpAmb", |
||
19 | $this->tpAmb, |
||
20 | true |
||
21 | ); |
||
22 | $this->dom->addChild( |
||
23 | $ideEvento, |
||
24 | "procEmi", |
||
25 | $this->procEmi, |
||
26 | true |
||
27 | ); |
||
28 | $this->dom->addChild( |
||
29 | $ideEvento, |
||
30 | "verProc", |
||
31 | $this->verProc, |
||
32 | true |
||
33 | ); |
||
34 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
35 | |||
36 | //tag deste evento em particular |
||
37 | $infoRubrica = $this->dom->createElement("infoRubrica"); |
||
38 | //tag comum a todos os modos |
||
39 | $ideRubrica = $this->dom->createElement("ideRubrica"); |
||
40 | $this->dom->addChild( |
||
41 | $ideRubrica, |
||
42 | "codRubr", |
||
43 | $this->std->codrubr, |
||
44 | true |
||
45 | ); |
||
46 | $this->dom->addChild( |
||
47 | $ideRubrica, |
||
48 | "ideTabRubr", |
||
49 | $this->std->idetabrubr, |
||
50 | true |
||
51 | ); |
||
52 | $this->dom->addChild( |
||
53 | $ideRubrica, |
||
54 | "iniValid", |
||
55 | $this->std->inivalid, |
||
56 | true |
||
57 | ); |
||
58 | $this->dom->addChild( |
||
59 | $ideRubrica, |
||
60 | "fimValid", |
||
61 | ! empty($this->std->fimvalid) ? $this->std->fimvalid : null, |
||
62 | false |
||
63 | ); |
||
64 | //seleção do modo |
||
65 | if ($this->std->modo == 'INC') { |
||
66 | $node = $this->dom->createElement("inclusao"); |
||
67 | } elseif ($this->std->modo == 'ALT') { |
||
68 | $node = $this->dom->createElement("alteracao"); |
||
69 | } else { |
||
70 | $node = $this->dom->createElement("exclusao"); |
||
71 | } |
||
72 | $node->appendChild($ideRubrica); |
||
73 | |||
74 | if (!empty($this->std->dadosrubrica) && $this->std->modo != 'EXC') { |
||
75 | $dadosRubrica = $this->dom->createElement("dadosRubrica"); |
||
76 | $this->dom->addChild( |
||
77 | $dadosRubrica, |
||
78 | "dscRubr", |
||
79 | $this->std->dadosrubrica->dscrubr, |
||
80 | true |
||
81 | ); |
||
82 | $this->dom->addChild( |
||
83 | $dadosRubrica, |
||
84 | "natRubr", |
||
85 | $this->std->dadosrubrica->natrubr, |
||
86 | true |
||
87 | ); |
||
88 | $this->dom->addChild( |
||
89 | $dadosRubrica, |
||
90 | "tpRubr", |
||
91 | $this->std->dadosrubrica->tprubr, |
||
92 | true |
||
93 | ); |
||
94 | $this->dom->addChild( |
||
95 | $dadosRubrica, |
||
96 | "codIncCP", |
||
97 | $this->std->dadosrubrica->codinccp, |
||
98 | true |
||
99 | ); |
||
100 | $this->dom->addChild( |
||
101 | $dadosRubrica, |
||
102 | "codIncIRRF", |
||
103 | $this->std->dadosrubrica->codincirrf, |
||
104 | true |
||
105 | ); |
||
106 | $this->dom->addChild( |
||
107 | $dadosRubrica, |
||
108 | "codIncFGTS", |
||
109 | $this->std->dadosrubrica->codincfgts, |
||
110 | true |
||
111 | ); |
||
112 | $this->dom->addChild( |
||
113 | $dadosRubrica, |
||
114 | "codIncSIND", |
||
115 | $this->std->dadosrubrica->codincsind, |
||
116 | true |
||
117 | ); |
||
118 | $this->dom->addChild( |
||
119 | $dadosRubrica, |
||
120 | "observacao", |
||
121 | ! empty($this->std->dadosrubrica->observacao) |
||
122 | ? $this->std->dadosrubrica->observacao |
||
123 | : null, |
||
124 | false |
||
125 | ); |
||
126 | |||
127 | if (! empty($this->std->dadosrubrica->ideprocessocp)) { |
||
128 | foreach ($this->std->dadosrubrica->ideprocessocp as $cp) { |
||
129 | $ideProcessoCP = $this->dom->createElement("ideProcessoCP"); |
||
130 | $this->dom->addChild( |
||
131 | $ideProcessoCP, |
||
132 | "tpProc", |
||
133 | $cp->tpproc, |
||
134 | true |
||
135 | ); |
||
136 | $this->dom->addChild( |
||
137 | $ideProcessoCP, |
||
138 | "nrProc", |
||
139 | $cp->nrproc, |
||
140 | true |
||
141 | ); |
||
142 | $this->dom->addChild( |
||
143 | $ideProcessoCP, |
||
144 | "extDecisao", |
||
145 | $cp->extdecisao, |
||
146 | true |
||
147 | ); |
||
148 | $this->dom->addChild( |
||
149 | $ideProcessoCP, |
||
150 | "codSusp", |
||
151 | $cp->codsusp, |
||
152 | true |
||
153 | ); |
||
154 | $dadosRubrica->appendChild($ideProcessoCP); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | if (! empty($this->std->dadosrubrica->ideprocessoirrf)) { |
||
159 | foreach ($this->std->dadosrubrica->ideprocessoirrf as $irrf) { |
||
160 | $ideProcessoIRRF = $this->dom->createElement("ideProcessoIRRF"); |
||
161 | $this->dom->addChild( |
||
162 | $ideProcessoIRRF, |
||
163 | "nrProc", |
||
164 | $irrf->nrproc, |
||
165 | true |
||
166 | ); |
||
167 | $this->dom->addChild( |
||
168 | $ideProcessoIRRF, |
||
169 | "codSusp", |
||
170 | $irrf->codsusp, |
||
171 | true |
||
172 | ); |
||
173 | $dadosRubrica->appendChild($ideProcessoIRRF); |
||
174 | } |
||
175 | } |
||
176 | if (! empty($this->std->dadosrubrica->ideprocessofgts)) { |
||
177 | foreach ($this->std->dadosrubrica->ideprocessofgts as $fgts) { |
||
178 | $ideProcessoFGTS = $this->dom->createElement("ideProcessoFGTS"); |
||
179 | $this->dom->addChild( |
||
180 | $ideProcessoFGTS, |
||
181 | "nrProc", |
||
182 | $fgts->nrproc, |
||
183 | true |
||
184 | ); |
||
185 | $dadosRubrica->appendChild($ideProcessoFGTS); |
||
186 | } |
||
187 | } |
||
188 | if (! empty($this->std->dadosrubrica->ideprocessosind)) { |
||
189 | foreach ($this->std->dadosrubrica->ideprocessosind as $sind) { |
||
190 | $ideProcessoSIND = $this->dom->createElement("ideProcessoSIND"); |
||
191 | $this->dom->addChild( |
||
192 | $ideProcessoSIND, |
||
193 | "nrProc", |
||
194 | $sind->nrproc, |
||
195 | true |
||
196 | ); |
||
197 | $dadosRubrica->appendChild($ideProcessoSIND); |
||
198 | } |
||
199 | } |
||
200 | $node->appendChild($dadosRubrica); |
||
201 | } |
||
202 | if (! empty($this->std->novavalidade) && $this->std->modo == 'ALT') { |
||
203 | $newVal = $this->std->novavalidade; |
||
204 | $novaValidade = $this->dom->createElement("novaValidade"); |
||
205 | $this->dom->addChild( |
||
206 | $novaValidade, |
||
207 | "iniValid", |
||
208 | $newVal->inivalid, |
||
209 | true |
||
210 | ); |
||
211 | $this->dom->addChild( |
||
212 | $novaValidade, |
||
213 | "fimValid", |
||
214 | ! empty($newVal->fimvalid) ? $newVal->fimvalid : null, |
||
215 | false |
||
216 | ); |
||
217 | $node->appendChild($novaValidade); |
||
218 | } |
||
219 | |||
220 | //finalização do xml |
||
221 | $infoRubrica->appendChild($node); |
||
222 | $this->node->appendChild($infoRubrica); |
||
223 | $this->eSocial->appendChild($this->node); |
||
224 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
225 | $this->sign(); |
||
226 | } |
||
227 | |||
443 |
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: