Conditions | 18 |
Paths | 560 |
Total Lines | 72 |
Code Lines | 59 |
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 |
||
127 | public function commonRender($playerId, $type) { |
||
128 | $r = ''; |
||
129 | $status = ColorResource::getInfo($this->color, 'status'); |
||
130 | |||
131 | $plus = null; |
||
132 | $minus = null; |
||
133 | |||
134 | switch ($type) { |
||
135 | case 'general': |
||
136 | $pos = $this->generalPosition; |
||
137 | $var = $this->generalVariation; break; |
||
138 | case 'xp': |
||
139 | $pos = $this->experiencePosition; |
||
140 | $var = $this->experienceVariation; break; |
||
141 | case 'butcher': |
||
142 | $pos = $this->butcherPosition; |
||
143 | $plus = $this->butcherDestroyedPEV; |
||
144 | $minus = $this->butcherLostPEV; |
||
145 | $var = $this->butcherVariation; break; |
||
146 | case 'trader': |
||
147 | $pos = $this->traderPosition; |
||
148 | $var = $this->traderVariation; break; |
||
149 | case 'fight': |
||
150 | $pos = $this->fightPosition; |
||
151 | $plus = $this->victories; |
||
152 | $minus = $this->defeat; |
||
153 | $var = $this->fightVariation; break; |
||
154 | case 'armies': |
||
155 | $pos = $this->armiesPosition; |
||
156 | $var = $this->armiesVariation; break; |
||
157 | case 'resources': |
||
158 | $pos = $this->resourcesPosition; |
||
159 | $var = $this->resourcesVariation; break; |
||
160 | default: $var = ''; $pos = ''; break; |
||
161 | } |
||
162 | |||
163 | $r .= '<div class="player color' . $this->color . ' ' . ($playerId == $this->rPlayer ? 'active' : NULL) . '">'; |
||
164 | $r .= '<a href="' . APP_ROOT . 'embassy/player-' . $this->rPlayer . '">'; |
||
165 | $r .= '<img src="' . MEDIA . 'avatar/small/' . $this->avatar . '.png" alt="' . $this->name . '" class="picto" />'; |
||
166 | $r .= '</a>'; |
||
167 | |||
168 | $r .= '<span class="title">' . $status[$this->status - 1] . '</span>'; |
||
169 | $r .= '<strong class="name">' . $this->name . '</strong>'; |
||
170 | |||
171 | $r .= '<span class="experience">'; |
||
172 | switch ($type) { |
||
173 | case 'general': $r .= Format::numberFormat($this->general) . ' point' . Format::addPlural($this->general); break; |
||
174 | case 'xp': $r .= Format::numberFormat($this->experience) . ' xp'; break; |
||
175 | case 'butcher': |
||
176 | $r .= Format::numberFormat($this->butcher) . ' point' . Format::addPlural($this->butcher); |
||
177 | break; |
||
178 | case 'trader': $r .= Format::numberFormat($this->trader) . ' <img src="' . MEDIA . 'resources/credit.png" class="icon-color" alt="crédits" />'; break; |
||
179 | case 'fight': |
||
180 | $r .= Format::numberFormat($this->fight) . ' point' . Format::addPlural($this->fight); |
||
181 | break; |
||
182 | # case 'armies': $r .= Format::numberFormat($this->armies) . ' <img src="' . MEDIA . 'resources/pev.png" class="icon-color" alt="pev" />'; break; |
||
183 | case 'resources': $r .= Format::numberFormat($this->resources) . ' <img src="' . MEDIA . 'resources/resource.png" class="icon-color" alt="ressources" />'; break; |
||
184 | default: break; |
||
185 | } |
||
186 | $r .= '</span>'; |
||
187 | |||
188 | $r .= '<span class="position">' . $pos . '</span>'; |
||
189 | |||
190 | if (intval($var) != 0) { |
||
191 | $r .= '<span class="variance ' . ($var > 0 ? ' upper' : ' lower') . '">'; |
||
192 | $r .= ($var > 0 ? '+' : '–') . abs($var); |
||
193 | $r .='</span>'; |
||
194 | } |
||
195 | $r .= '</div>'; |
||
196 | |||
197 | return $r; |
||
198 | } |
||
199 | } |
||
200 |