| Conditions | 14 |
| Paths | 192 |
| Total Lines | 112 |
| Code Lines | 82 |
| 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 |
||
| 238 | public function startFight($commanderA, $playerA, $commanderD, $playerD = NULL) { |
||
| 239 | $commanderA->setIsAttacker(TRUE); |
||
| 240 | $commanderD->setIsAttacker(FALSE); |
||
| 241 | |||
| 242 | $commanderA->setPevInBegin(); |
||
| 243 | $commanderD->setPevInBegin(); |
||
| 244 | |||
| 245 | LiveReport::$rPlayerAttacker = $commanderA->rPlayer; |
||
| 246 | LiveReport::$rPlayerDefender = $commanderD->rPlayer; |
||
| 247 | |||
| 248 | LiveReport::$avatarA = $commanderA->avatar; |
||
| 249 | LiveReport::$avatarD = $commanderD->avatar; |
||
| 250 | LiveReport::$nameA = $commanderA->name; |
||
| 251 | LiveReport::$nameD = $commanderD->name; |
||
| 252 | LiveReport::$levelA = $commanderA->level; |
||
| 253 | LiveReport::$levelD = $commanderD->level; |
||
| 254 | LiveReport::$experienceA = $commanderA->experience; |
||
| 255 | LiveReport::$experienceD = $commanderD->experience; |
||
| 256 | LiveReport::$palmaresA = $commanderA->palmares; |
||
| 257 | LiveReport::$palmaresD = $commanderD->palmares; |
||
| 258 | |||
| 259 | $shipsA = $commanderA->getNbrShipByType(); |
||
| 260 | $shipsD = $commanderD->getNbrShipByType(); |
||
| 261 | $weight = 0; |
||
| 262 | |||
| 263 | for ($i = 0; $i < count($shipsA); $i++) { |
||
| 264 | $weight += DataAnalysis::resourceToStdUnit(ShipResource::getInfo($i, 'resourcePrice') * $shipsA[$i]); |
||
| 265 | $weight += DataAnalysis::resourceToStdUnit(ShipResource::getInfo($i, 'resourcePrice') * $shipsD[$i]); |
||
| 266 | } |
||
| 267 | |||
| 268 | LiveReport::$importance = $weight; |
||
| 269 | |||
| 270 | $i = 0; |
||
| 271 | foreach ($commanderA->armyInBegin AS $s) { |
||
| 272 | LiveReport::$squadrons[] = array(0, $i, 0, 0, $commanderA->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
||
| 273 | $i++; |
||
| 274 | } |
||
| 275 | $i = 0; |
||
| 276 | foreach ($commanderD->armyInBegin AS $s) { |
||
| 277 | LiveReport::$squadrons[] = array(0, $i, 0, 0, $commanderD->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
||
| 278 | $i++; |
||
| 279 | } |
||
| 280 | |||
| 281 | while(1) { |
||
| 282 | if (LiveReport::$round == 1000) { |
||
| 283 | break; |
||
| 284 | } |
||
| 285 | $nbrShipsD = 0; |
||
| 286 | $nbrShipsA = 0; |
||
| 287 | |||
| 288 | foreach ($commanderA->getArmy() as $squadronA) { |
||
| 289 | $nbrShipsA += $squadronA->getNbrShips(); |
||
| 290 | } |
||
| 291 | if ($nbrShipsA == 0) { |
||
| 292 | $this->commanderManager->resultOfFight($commanderD, TRUE, $commanderA); |
||
| 293 | $this->commanderManager->resultOfFight($commanderA, FALSE, $commanderD); |
||
| 294 | $commanderA->setStatement(3); |
||
| 295 | $commanderD->setDDeath(Utils::now()); |
||
| 296 | LiveReport::$rPlayerWinner = $commanderD->rPlayer; |
||
| 297 | |||
| 298 | if ($commanderD->rPlayer != ID_GAIA) { |
||
| 299 | $playerD->increaseVictory(1); |
||
| 300 | $playerA->increaseDefeat(1); |
||
| 301 | } else{ |
||
| 302 | $playerA->increaseDefeat(1); |
||
| 303 | } |
||
| 304 | |||
| 305 | break; |
||
| 306 | } else { |
||
| 307 | $commanderA = $this->commanderManager->engage($commanderD, $commanderA); |
||
| 308 | LiveReport::$halfround++; |
||
| 309 | } |
||
| 310 | |||
| 311 | foreach ($commanderD->getArmy() as $squadronD) { |
||
| 312 | $nbrShipsD += $squadronD->getNbrShips(); |
||
| 313 | } |
||
| 314 | if($nbrShipsD == 0) { |
||
| 315 | $this->commanderManager->resultOfFight($commanderA, TRUE, $commanderD); |
||
| 316 | $this->commanderManager->resultOfFight($commanderD, FALSE, $commanderA); |
||
| 317 | $commanderD->setStatement(3); |
||
| 318 | $commanderD->setDDeath(Utils::now()); |
||
| 319 | LiveReport::$rPlayerWinner = $commanderA->rPlayer; |
||
| 320 | |||
| 321 | if ($commanderD->rPlayer != ID_GAIA) { |
||
| 322 | $playerA->increaseVictory(1); |
||
| 323 | $playerD->increaseDefeat(1); |
||
| 324 | } else { |
||
| 325 | $playerA->increaseVictory(1); |
||
| 326 | } |
||
| 327 | |||
| 328 | break; |
||
| 329 | } else { |
||
| 330 | $commanderD = $this->commanderManager->engage($commanderA, $commanderD); |
||
| 331 | LiveReport::$halfround++; |
||
| 332 | } |
||
| 333 | |||
| 334 | LiveReport::$round++; |
||
| 335 | self::$currentLine++; |
||
| 336 | } |
||
| 337 | |||
| 338 | $i = 0; |
||
| 339 | foreach ($commanderA->armyAtEnd AS $s) { |
||
| 340 | LiveReport::$squadrons[] = array(0, $i, 0, -1, $commanderA->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
||
| 341 | $i++; |
||
| 342 | } |
||
| 343 | $i = 0; |
||
| 344 | foreach ($commanderD->armyAtEnd AS $s) { |
||
| 345 | LiveReport::$squadrons[] = array(0, $i, 0, -1, $commanderD->id, $s[0], $s[1], $s[2], $s[3], $s[4], $s[5], $s[6], $s[7], $s[8], $s[9], $s[10], $s[11]); |
||
| 346 | $i++; |
||
| 347 | } |
||
| 348 | return array($commanderA, $commanderD); |
||
| 349 | } |
||
| 350 | } |