| Conditions | 18 |
| Paths | 72 |
| Total Lines | 212 |
| 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 | $ideEvento = $this->dom->createElement("ideEvento"); |
||
| 14 | $this->dom->addChild( |
||
| 15 | $ideEvento, |
||
| 16 | "indRetif", |
||
| 17 | $this->std->indretif, |
||
| 18 | true |
||
| 19 | ); |
||
| 20 | $this->dom->addChild( |
||
| 21 | $ideEvento, |
||
| 22 | "nrRecibo", |
||
| 23 | ! empty($this->std->nrrecibo) ? $this->std->nrrecibo : null, |
||
| 24 | false |
||
| 25 | ); |
||
| 26 | $this->dom->addChild( |
||
| 27 | $ideEvento, |
||
| 28 | "tpAmb", |
||
| 29 | $this->tpAmb, |
||
| 30 | true |
||
| 31 | ); |
||
| 32 | $this->dom->addChild( |
||
| 33 | $ideEvento, |
||
| 34 | "procEmi", |
||
| 35 | $this->procEmi, |
||
| 36 | true |
||
| 37 | ); |
||
| 38 | $this->dom->addChild( |
||
| 39 | $ideEvento, |
||
| 40 | "verProc", |
||
| 41 | $this->verProc, |
||
| 42 | true |
||
| 43 | ); |
||
| 44 | $this->node->insertBefore($ideEvento, $ideEmpregador); |
||
| 45 | |||
| 46 | $this->tagVinculo(); |
||
| 47 | |||
| 48 | $cat = $this->tagCAT(); |
||
| 49 | |||
| 50 | $localAcidente = $this->tagLocalAcidente($cat); |
||
| 51 | |||
| 52 | if (!empty($this->std->idelocalacid)) { |
||
| 53 | $this->tagIdeLocalAcid($localAcidente); |
||
| 54 | } |
||
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | foreach ($this->std->parteatingida as $pa) { |
||
| 59 | $parteAtingida = $this->dom->createElement("parteAtingida"); |
||
| 60 | $this->dom->addChild( |
||
| 61 | $parteAtingida, |
||
| 62 | "codParteAting", |
||
| 63 | $pa->codparteating, |
||
| 64 | true |
||
| 65 | ); |
||
| 66 | $this->dom->addChild( |
||
| 67 | $parteAtingida, |
||
| 68 | "lateralidade", |
||
| 69 | $pa->lateralidade, |
||
| 70 | true |
||
| 71 | ); |
||
| 72 | $cat->appendChild($parteAtingida); |
||
| 73 | } |
||
| 74 | |||
| 75 | foreach ($this->std->agentecausador as $pa) { |
||
| 76 | $agenteCausador = $this->dom->createElement("agenteCausador"); |
||
| 77 | $this->dom->addChild( |
||
| 78 | $agenteCausador, |
||
| 79 | "codAgntCausador", |
||
| 80 | $pa->codagntcausador, |
||
| 81 | true |
||
| 82 | ); |
||
| 83 | $cat->appendChild($agenteCausador); |
||
| 84 | } |
||
| 85 | if (!empty($this->std->atestado)) { |
||
| 86 | $pa = $this->std->atestado; |
||
| 87 | $atestado = $this->dom->createElement("atestado"); |
||
| 88 | $this->dom->addChild( |
||
| 89 | $atestado, |
||
| 90 | "codCNES", |
||
| 91 | !empty($pa->codcnes) ? $pa->codcnes : null, |
||
| 92 | false |
||
| 93 | ); |
||
| 94 | $this->dom->addChild( |
||
| 95 | $atestado, |
||
| 96 | "dtAtendimento", |
||
| 97 | $pa->dtatendimento, |
||
| 98 | true |
||
| 99 | ); |
||
| 100 | $this->dom->addChild( |
||
| 101 | $atestado, |
||
| 102 | "hrAtendimento", |
||
| 103 | $pa->hratendimento, |
||
| 104 | true |
||
| 105 | ); |
||
| 106 | $this->dom->addChild( |
||
| 107 | $atestado, |
||
| 108 | "indInternacao", |
||
| 109 | $pa->indinternacao, |
||
| 110 | true |
||
| 111 | ); |
||
| 112 | $this->dom->addChild( |
||
| 113 | $atestado, |
||
| 114 | "durTrat", |
||
| 115 | $pa->durtrat, |
||
| 116 | true |
||
| 117 | ); |
||
| 118 | $this->dom->addChild( |
||
| 119 | $atestado, |
||
| 120 | "indAfast", |
||
| 121 | $pa->indafast, |
||
| 122 | true |
||
| 123 | ); |
||
| 124 | $this->dom->addChild( |
||
| 125 | $atestado, |
||
| 126 | "dscLesao", |
||
| 127 | !empty($pa->dsclesao) ? $pa->dsclesao : null, |
||
| 128 | false |
||
| 129 | ); |
||
| 130 | $this->dom->addChild( |
||
| 131 | $atestado, |
||
| 132 | "dscCompLesao", |
||
| 133 | !empty($pa->dsccomplesao) ? $pa->dsccomplesao : null, |
||
| 134 | false |
||
| 135 | ); |
||
| 136 | $this->dom->addChild( |
||
| 137 | $atestado, |
||
| 138 | "diagProvavel", |
||
| 139 | !empty($pa->diagprovavel) ? $pa->diagprovavel : null, |
||
| 140 | false |
||
| 141 | ); |
||
| 142 | $this->dom->addChild( |
||
| 143 | $atestado, |
||
| 144 | "codCID", |
||
| 145 | $pa->codcid, |
||
| 146 | true |
||
| 147 | ); |
||
| 148 | $this->dom->addChild( |
||
| 149 | $atestado, |
||
| 150 | "observacao", |
||
| 151 | !empty($pa->observacao) ? $pa->observacao : null, |
||
| 152 | false |
||
| 153 | ); |
||
| 154 | $emitente = $this->dom->createElement("emitente"); |
||
| 155 | $this->dom->addChild( |
||
| 156 | $emitente, |
||
| 157 | "nmEmit", |
||
| 158 | $pa->nmemit, |
||
| 159 | true |
||
| 160 | ); |
||
| 161 | $this->dom->addChild( |
||
| 162 | $emitente, |
||
| 163 | "ideOC", |
||
| 164 | $pa->ideoc, |
||
| 165 | true |
||
| 166 | ); |
||
| 167 | if ($this->layoutStr == 'v02_05_00') { |
||
| 168 | $this->dom->addChild( |
||
| 169 | $emitente, |
||
| 170 | "nrOC", |
||
| 171 | $pa->nroc, |
||
| 172 | true |
||
| 173 | ); |
||
| 174 | } else { |
||
| 175 | $this->dom->addChild( |
||
| 176 | $emitente, |
||
| 177 | "nrOc", |
||
| 178 | $pa->nroc, |
||
| 179 | true |
||
| 180 | ); |
||
| 181 | } |
||
| 182 | $this->dom->addChild( |
||
| 183 | $emitente, |
||
| 184 | "ufOC", |
||
| 185 | !empty($pa->ufoc) ? $pa->ufoc : null, |
||
| 186 | true |
||
| 187 | ); |
||
| 188 | $atestado->appendChild($emitente); |
||
| 189 | $cat->appendChild($atestado); |
||
| 190 | } |
||
| 191 | if (!empty($this->std->catorigem)) { |
||
| 192 | $pa = $this->std->catorigem; |
||
| 193 | $catOrigem = $this->dom->createElement("catOrigem"); |
||
| 194 | $this->dom->addChild( |
||
| 195 | $catOrigem, |
||
| 196 | "dtCatOrig", |
||
| 197 | !empty($pa->dtcatorig) ? $pa->dtcatorig : null, |
||
| 198 | false |
||
| 199 | ); |
||
| 200 | if ($this->layoutStr != 'v02_05_00') { |
||
| 201 | $this->dom->addChild( |
||
| 202 | $catOrigem, |
||
| 203 | "nrCatOrig", |
||
| 204 | !empty($pa->nrcatorig) ? $pa->nrcatorig : null, |
||
| 205 | false |
||
| 206 | ); |
||
| 207 | } else { |
||
| 208 | $this->dom->addChild( |
||
| 209 | $catOrigem, |
||
| 210 | "nrRecCatOrig", |
||
| 211 | !empty($pa->nrreccatorig) ? $pa->nrreccatorig : null, |
||
| 212 | false |
||
| 213 | ); |
||
| 214 | } |
||
| 215 | $cat->appendChild($catOrigem); |
||
| 216 | } |
||
| 217 | $this->node->appendChild($cat); |
||
| 218 | $this->eSocial->appendChild($this->node); |
||
| 219 | //$this->xml = $this->dom->saveXML($this->eSocial); |
||
| 220 | $this->sign(); |
||
| 221 | } |
||
| 222 | |||
| 494 |
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: