Conditions | 15 |
Paths | 48 |
Total Lines | 230 |
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 |
||
18 | protected function toNodeS100() |
||
19 | { |
||
20 | $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); |
||
21 | //o idEvento pode variar de evento para evento |
||
22 | //então cada factory individualmente terá de construir o seu |
||
23 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
24 | $this->dom->addChild( |
||
25 | $ideEvento, |
||
26 | "indRetif", |
||
27 | $this->std->indretif, |
||
28 | true |
||
29 | ); |
||
30 | if ($this->std->indretif == 2) { |
||
31 | $this->dom->addChild( |
||
32 | $ideEvento, |
||
33 | "nrRecibo", |
||
34 | $this->std->nrrecibo, |
||
35 | true |
||
36 | ); |
||
37 | } |
||
38 | $this->dom->addChild( |
||
39 | $ideEvento, |
||
40 | "tpAmb", |
||
41 | $this->tpAmb, |
||
42 | true |
||
43 | ); |
||
44 | $this->dom->addChild( |
||
45 | $ideEvento, |
||
46 | "procEmi", |
||
47 | $this->procEmi, |
||
48 | true |
||
49 | ); |
||
50 | $this->dom->addChild( |
||
51 | $ideEvento, |
||
52 | "verProc", |
||
53 | $this->verProc, |
||
54 | true |
||
55 | ); |
||
56 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
57 | |||
58 | $beneficiario = $this->dom->createElement("beneficiario"); |
||
59 | $this->dom->addChild( |
||
60 | $beneficiario, |
||
61 | "cpfBenef", |
||
62 | $this->std->cpfbenef, |
||
63 | true |
||
64 | ); |
||
65 | $this->dom->addChild( |
||
66 | $beneficiario, |
||
67 | "matricula", |
||
68 | !empty($this->std->matricula) ? $this->std->matricula : null, |
||
69 | false |
||
70 | ); |
||
71 | $this->dom->addChild( |
||
72 | $beneficiario, |
||
73 | "cnpjOrigem", |
||
74 | !empty($this->std->cnpjorigem) ? $this->std->cnpjorigem : null, |
||
75 | false |
||
76 | ); |
||
77 | $this->node->appendChild($beneficiario); |
||
78 | |||
79 | $infoBenInicio = $this->dom->createElement("infoBenInicio"); |
||
80 | $this->dom->addChild( |
||
81 | $infoBenInicio, |
||
82 | "cadIni", |
||
83 | $this->std->cadini, |
||
84 | true |
||
85 | ); |
||
86 | $this->dom->addChild( |
||
87 | $infoBenInicio, |
||
88 | "indSitBenef", |
||
89 | !empty($this->std->indsitbenef) ? $this->std->indsitbenef : null, |
||
90 | false |
||
91 | ); |
||
92 | $this->dom->addChild( |
||
93 | $infoBenInicio, |
||
94 | "nrBeneficio", |
||
95 | $this->std->nrbeneficio, |
||
96 | true |
||
97 | ); |
||
98 | $this->dom->addChild( |
||
99 | $infoBenInicio, |
||
100 | "dtIniBeneficio", |
||
101 | $this->std->dtinibeneficio, |
||
102 | true |
||
103 | ); |
||
104 | $this->dom->addChild( |
||
105 | $infoBenInicio, |
||
106 | "dtPublic", |
||
107 | !empty($this->std->dtpublic) ? $this->std->dtpublic : null, |
||
108 | false |
||
109 | ); |
||
110 | $dadosBeneficio = $this->dom->createElement("dadosBeneficio"); |
||
111 | $this->dom->addChild( |
||
112 | $dadosBeneficio, |
||
113 | "tpBeneficio", |
||
114 | $this->std->tpbeneficio, |
||
115 | true |
||
116 | ); |
||
117 | $this->dom->addChild( |
||
118 | $dadosBeneficio, |
||
119 | "tpPlanRP", |
||
120 | $this->std->tpplanrp, |
||
121 | true |
||
122 | ); |
||
123 | $this->dom->addChild( |
||
124 | $dadosBeneficio, |
||
125 | "dsc", |
||
126 | !empty($this->std->dsc) ? $this->std->dsc : null, |
||
127 | false |
||
128 | ); |
||
129 | $this->dom->addChild( |
||
130 | $dadosBeneficio, |
||
131 | "indDecJud", |
||
132 | !empty($this->std->inddecjud) ? $this->std->inddecjud : null, |
||
133 | false |
||
134 | ); |
||
135 | |||
136 | if (!empty($this->std->infopenmorte)) { |
||
137 | $infoPenMorte = $this->dom->createElement("infoPenMorte"); |
||
138 | $this->dom->addChild( |
||
139 | $infoPenMorte, |
||
140 | "tpPenMorte", |
||
141 | $this->std->infopenmorte->tppenmorte, |
||
142 | true |
||
143 | ); |
||
144 | if (!empty($this->std->infopenmorte->instpenmorte)) { |
||
145 | $instPenMorte = $this->dom->createElement("instPenMorte"); |
||
146 | $this->dom->addChild( |
||
147 | $instPenMorte, |
||
148 | "cpfInst", |
||
149 | $this->std->infopenmorte->instpenmorte->cpfinst, |
||
150 | true |
||
151 | ); |
||
152 | $this->dom->addChild( |
||
153 | $instPenMorte, |
||
154 | "dtInst", |
||
155 | $this->std->infopenmorte->instpenmorte->dtinst, |
||
156 | true |
||
157 | ); |
||
158 | $infoPenMorte->appendChild($instPenMorte); |
||
159 | } |
||
160 | $dadosBeneficio->appendChild($infoPenMorte); |
||
161 | } |
||
162 | $infoBenInicio->appendChild($dadosBeneficio); |
||
163 | |||
164 | if (!empty($this->std->sucessaobenef)) { |
||
165 | $sucessaoBenef = $this->dom->createElement("sucessaoBenef"); |
||
166 | $this->dom->addChild( |
||
167 | $sucessaoBenef, |
||
168 | "cnpjOrgaoAnt", |
||
169 | $this->std->sucessaobenef->cnpjorgaoant, |
||
170 | true |
||
171 | ); |
||
172 | $this->dom->addChild( |
||
173 | $sucessaoBenef, |
||
174 | "nrBeneficioAnt", |
||
175 | $this->std->sucessaobenef->nrbeneficioant, |
||
176 | true |
||
177 | ); |
||
178 | $this->dom->addChild( |
||
179 | $sucessaoBenef, |
||
180 | "dtTransf", |
||
181 | $this->std->sucessaobenef->dttransf, |
||
182 | true |
||
183 | ); |
||
184 | $this->dom->addChild( |
||
185 | $sucessaoBenef, |
||
186 | "observacao", |
||
187 | !empty($this->std->sucessaobenef->observacao) |
||
188 | ? $this->std->sucessaobenef->observacao : null, |
||
189 | false |
||
190 | ); |
||
191 | $infoBenInicio->appendChild($sucessaoBenef); |
||
192 | } |
||
193 | |||
194 | if (!empty($this->std->mudancacpf)) { |
||
195 | $mudancaCPF = $this->dom->createElement("mudancaCPF"); |
||
196 | $this->dom->addChild( |
||
197 | $mudancaCPF, |
||
198 | "cpfAnt", |
||
199 | $this->std->mudancacpf->cpfant, |
||
200 | true |
||
201 | ); |
||
202 | $this->dom->addChild( |
||
203 | $mudancaCPF, |
||
204 | "nrBeneficioAnt", |
||
205 | $this->std->mudancacpf->nrbeneficioant, |
||
206 | true |
||
207 | ); |
||
208 | $this->dom->addChild( |
||
209 | $mudancaCPF, |
||
210 | "dtAltCPF", |
||
211 | $this->std->mudancacpf->dtaltcpf, |
||
212 | true |
||
213 | ); |
||
214 | $this->dom->addChild( |
||
215 | $mudancaCPF, |
||
216 | "observacao", |
||
217 | !empty($this->std->mudancacpf->observacao) |
||
218 | ? $this->std->mudancacpf->observacao : null, |
||
219 | false |
||
220 | ); |
||
221 | $infoBenInicio->appendChild($mudancaCPF); |
||
222 | } |
||
223 | |||
224 | if (!empty($this->std->infobentermino)) { |
||
225 | $infoBenTermino = $this->dom->createElement("infoBenTermino"); |
||
226 | $this->dom->addChild( |
||
227 | $infoBenTermino, |
||
228 | "dtTermBeneficio", |
||
229 | $this->std->infobentermino->dttermbeneficio, |
||
230 | true |
||
231 | ); |
||
232 | $this->dom->addChild( |
||
233 | $infoBenTermino, |
||
234 | "mtvTermino", |
||
235 | $this->std->infobentermino->mtvtermino, |
||
236 | true |
||
237 | ); |
||
238 | $infoBenInicio->appendChild($infoBenTermino); |
||
239 | } |
||
240 | |||
241 | $this->node->appendChild($infoBenInicio); |
||
242 | |||
243 | //finalização do xml |
||
244 | $this->eSocial->appendChild($this->node); |
||
245 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
246 | $this->sign(); |
||
247 | } |
||
248 | } |
||
249 |
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: