| Conditions | 34 |
| Paths | 12366 |
| Total Lines | 194 |
| Code Lines | 165 |
| 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 |
||
| 198 | public function update(Research $research, $playerId, $naturalInvest, $lifeInvest, $socialInvest, $informaticInvest) { |
||
| 199 | # prestige |
||
| 200 | $player = $this->playerManager->get($playerId); |
||
| 201 | $applyPrestige = FALSE; |
||
| 202 | if ($player->rColor == ColorResource::APHERA) { |
||
| 203 | $applyPrestige = TRUE; |
||
| 204 | } |
||
| 205 | // natural technologies |
||
| 206 | do { |
||
| 207 | if ($research->naturalToPay > $naturalInvest) { |
||
| 208 | $research->naturalToPay -= $naturalInvest; |
||
| 209 | $naturalInvest = 0; |
||
| 210 | } else { |
||
| 211 | $naturalInvest -= $research->naturalToPay; |
||
| 212 | switch ($research->naturalTech) { |
||
| 213 | case 0 : |
||
| 214 | $research->mathLevel++; |
||
| 215 | $levelReached = $research->mathLevel; |
||
| 216 | break; |
||
| 217 | case 1 : |
||
| 218 | $research->physLevel++; |
||
| 219 | $levelReached = $research->physLevel; |
||
| 220 | break; |
||
| 221 | case 2 : |
||
| 222 | $research->chemLevel++; |
||
| 223 | $levelReached = $research->chemLevel; |
||
| 224 | break; |
||
| 225 | default : |
||
| 226 | $levelReached = 0; |
||
| 227 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 228 | } |
||
| 229 | |||
| 230 | $n = new Notification(); |
||
| 231 | $n->setRPlayer($playerId); |
||
| 232 | $n->setTitle($this->researchHelper->getInfo($research->naturalTech, 'name') . ' niveau ' . $levelReached); |
||
| 233 | $n->setContent('Vos investissements dans l\'Université ont payé !<br /> |
||
| 234 | Vos chercheurs du département des <strong>Sciences Naturelles</strong> ont fait des avancées en <strong>' |
||
| 235 | . $this->researchHelper->getInfo($research->naturalTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' |
||
| 236 | . $levelReached . '</strong> dans ce domaine. Félicitations !'); |
||
| 237 | $this->notificationManager->add($n); |
||
| 238 | do { |
||
| 239 | $research->naturalTech = rand(0, 2); // 0, 1 ou 2 |
||
| 240 | $tech1 = $research->mathLevel; |
||
| 241 | $tech2 = $research->physLevel; |
||
| 242 | $tech3 = $research->chemLevel; |
||
| 243 | switch ($research->naturalTech) { |
||
| 244 | case 0 : $tech1++; break; |
||
| 245 | case 1 : $tech2++; break; |
||
| 246 | case 2 : $tech3++; break; |
||
| 247 | default : |
||
| 248 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 249 | } |
||
| 250 | } while (!$this->researchHelper->isResearchPermit($tech1, $tech2, $tech3)); |
||
| 251 | $research->naturalToPay = $this->researchHelper->getInfo($research->naturalTech, 'level', $research->getLevel($research->naturalTech) + 1, 'price'); |
||
| 252 | } |
||
| 253 | } while ($naturalInvest > 0); |
||
| 254 | // life technologies (en fait ce sont les sciences politiques) |
||
| 255 | do { |
||
| 256 | if ($research->lifeToPay > $lifeInvest) { |
||
| 257 | $research->lifeToPay -= $lifeInvest; |
||
| 258 | $lifeInvest = 0; |
||
| 259 | } else { |
||
| 260 | $lifeInvest -= $research->lifeToPay; |
||
| 261 | switch ($research->lifeTech) { |
||
| 262 | case 3 : |
||
| 263 | $research->bioLevel++; |
||
| 264 | $levelReached = $research->bioLevel; |
||
| 265 | break; |
||
| 266 | case 4 : |
||
| 267 | $research->mediLevel++; |
||
| 268 | $levelReached = $research->mediLevel; |
||
| 269 | break; |
||
| 270 | default : |
||
| 271 | $levelReached = 0; |
||
| 272 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 273 | } |
||
| 274 | |||
| 275 | $n = new Notification(); |
||
| 276 | $n->setRPlayer($playerId); |
||
| 277 | $n->setTitle($this->researchHelper->getInfo($research->lifeTech, 'name') . ' niveau ' . $levelReached); |
||
| 278 | $n->setContent('Vos investissements dans l\'Université ont payé !<br /> |
||
| 279 | Vos chercheurs du département des <strong>Sciences Politiques</strong> ont fait des avancées en <strong>' |
||
| 280 | . $this->researchHelper->getInfo($research->lifeTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' |
||
| 281 | . $levelReached . '</strong> dans ce domaine. Félicitations !'); |
||
| 282 | $this->notificationManager->add($n); |
||
| 283 | |||
| 284 | do { |
||
| 285 | $research->lifeTech = rand(3, 4); |
||
| 286 | $tech1 = $research->bioLevel; |
||
| 287 | $tech2 = $research->mediLevel; |
||
| 288 | switch ($research->lifeTech) { |
||
| 289 | case 3 : $tech1++; break; |
||
| 290 | case 4 : $tech2++; break; |
||
| 291 | default : |
||
| 292 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 293 | } |
||
| 294 | } while (!$this->researchHelper->isResearchPermit($tech1, $tech2)); |
||
| 295 | $research->lifeToPay = $this->researchHelper->getInfo($research->lifeTech, 'level', $research->getLevel($research->lifeTech) + 1, 'price'); |
||
| 296 | } |
||
| 297 | } while ($lifeInvest > 0); |
||
| 298 | // social technologies |
||
| 299 | do { |
||
| 300 | if ($research->socialToPay > $socialInvest) { |
||
| 301 | $research->socialToPay -= $socialInvest; |
||
| 302 | $socialInvest = 0; |
||
| 303 | } else { |
||
| 304 | $socialInvest -= $research->socialToPay; |
||
| 305 | switch ($research->socialTech) { |
||
| 306 | case 5 : |
||
| 307 | $research->econoLevel++; |
||
| 308 | $levelReached = $research->econoLevel; |
||
| 309 | break; |
||
| 310 | case 6 : |
||
| 311 | $research->psychoLevel++; |
||
| 312 | $levelReached = $research->psychoLevel; |
||
| 313 | break; |
||
| 314 | default : |
||
| 315 | $levelReached = 0; |
||
| 316 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 317 | } |
||
| 318 | |||
| 319 | $n = new Notification(); |
||
| 320 | $n->setRPlayer($playerId); |
||
| 321 | $n->setTitle($this->researchHelper->getInfo($research->socialTech, 'name') . ' niveau ' . $levelReached); |
||
| 322 | $n->setContent('Vos investissements dans l\'Université ont payé !<br /> |
||
| 323 | Vos chercheurs du département des <strong>Sciences Economiques et Sociales</strong> ont fait des avancées en <strong>' |
||
| 324 | . $this->researchHelper->getInfo($research->socialTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' |
||
| 325 | . $levelReached . '</strong> dans ce domaine. Félicitations !'); |
||
| 326 | $this->notificationManager->add($n); |
||
| 327 | do { |
||
| 328 | $research->socialTech = rand(5, 6); |
||
| 329 | $tech1 = $research->econoLevel; |
||
| 330 | $tech2 = $research->psychoLevel; |
||
| 331 | switch ($research->socialTech) { |
||
| 332 | case 5 : $tech1++; break; |
||
| 333 | case 6 : $tech2++; break; |
||
| 334 | default : |
||
| 335 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 336 | } |
||
| 337 | } while (!$this->researchHelper->isResearchPermit($tech1, $tech2)); |
||
| 338 | $research->socialToPay = $this->researchHelper->getInfo($research->socialTech, 'level', $research->getLevel($research->socialTech) + 1, 'price'); |
||
| 339 | } |
||
| 340 | } while ($socialInvest > 0); |
||
| 341 | // informatic technologies |
||
| 342 | do { |
||
| 343 | if ($research->informaticToPay > $informaticInvest) { |
||
| 344 | $research->informaticToPay -= $informaticInvest; |
||
| 345 | $informaticInvest = 0; |
||
| 346 | } else { |
||
| 347 | $informaticInvest -= $research->informaticToPay; |
||
| 348 | switch ($research->informaticTech) { |
||
| 349 | case 7 : |
||
| 350 | $research->networkLevel++; |
||
| 351 | $levelReached = $research->networkLevel; |
||
| 352 | break; |
||
| 353 | case 8 : |
||
| 354 | $research->algoLevel++; |
||
| 355 | $levelReached = $research->algoLevel; |
||
| 356 | break; |
||
| 357 | case 9 : |
||
| 358 | $research->statLevel++; |
||
| 359 | $levelReached = $research->statLevel; |
||
| 360 | break; |
||
| 361 | default : |
||
| 362 | $levelReached = 0; |
||
| 363 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 364 | } |
||
| 365 | |||
| 366 | $n = new Notification(); |
||
| 367 | $n->setRPlayer($playerId); |
||
| 368 | $n->setTitle($this->researchHelper->getInfo($research->informaticTech, 'name') . ' niveau ' . $levelReached); |
||
| 369 | $n->setContent('Vos investissements dans l\'Université ont payé !<br /> |
||
| 370 | Vos chercheurs du département de l\'<strong>Ingénierie Informatique</strong> ont fait des avancées en <strong>' |
||
| 371 | . $this->researchHelper->getInfo($research->informaticTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' |
||
| 372 | . $levelReached . '</strong> dans ce domaine. Félicitations !'); |
||
| 373 | $this->notificationManager->add($n); |
||
| 374 | |||
| 375 | do { |
||
| 376 | $research->informaticTech = rand(7, 9); |
||
| 377 | $tech1 = $research->networkLevel; |
||
| 378 | $tech2 = $research->algoLevel; |
||
| 379 | $tech3 = $research->statLevel; |
||
| 380 | switch ($research->informaticTech) { |
||
| 381 | case 7 : $tech1++; break; |
||
| 382 | case 8 : $tech2++; break; |
||
| 383 | case 9 : $tech3++; break; |
||
| 384 | default : |
||
| 385 | throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies'); |
||
| 386 | } |
||
| 387 | } while (!$this->researchHelper->isResearchPermit($tech1, $tech2, $tech3)); |
||
| 388 | $research->informaticToPay = $this->researchHelper->getInfo($research->informaticTech, 'level', $research->getLevel($research->informaticTech) + 1, 'price'); |
||
| 389 | } |
||
| 390 | } while ($informaticInvest > 0); |
||
| 391 | } |
||
| 392 | |||
| 413 | } |