| Conditions | 15 |
| Paths | 2700 |
| Total Lines | 62 |
| Code Lines | 46 |
| Lines | 8 |
| Ratio | 12.9 % |
| Changes | 8 | ||
| Bugs | 1 | Features | 4 |
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 |
||
| 37 | public function simulate() |
||
| 38 | {
|
||
| 39 | $homePoints = $this->homeTeam->getAvgSkill(); |
||
| 40 | $awayPoints = $this->awayTeam->getAvgSkill(); |
||
| 41 | |||
| 42 | $homePoints += $this->malusModule( |
||
| 43 | $this->homeTeam->coach->favouriteModule, |
||
| 44 | $this->homeTeam->playersPerRoleArray() |
||
| 45 | ); |
||
| 46 | $awayPoints += $this->malusModule( |
||
| 47 | $this->awayTeam->coach->favouriteModule, |
||
| 48 | $this->awayTeam->playersPerRoleArray() |
||
| 49 | ); |
||
| 50 | |||
| 51 | $goalHome = 0; |
||
| 52 | $goalAway = 0; |
||
| 53 | |||
| 54 | if (Randomizer::boolOnPercentage(80)) {
|
||
| 55 | if (($homePoints - $awayPoints) < 0) {
|
||
| 56 | $goalAway = ($awayPoints - $homePoints) % 6; |
||
| 57 | $goalHome += $this->chance(); |
||
| 58 | $goalAway += $this->chance(); |
||
| 59 | $goalHome += $this->bonusHome(); |
||
| 60 | } else {
|
||
| 61 | $goalHome = ($homePoints - $awayPoints) % 6; |
||
| 62 | $goalAway += $this->chance(); |
||
| 63 | $goalHome += $this->bonusHome(); |
||
| 64 | } |
||
| 65 | } else {
|
||
| 66 | $goalHome += $this->chance(); |
||
| 67 | $goalAway += $this->chance(); |
||
| 68 | $goalHome += $this->bonusHome(); |
||
| 69 | } |
||
| 70 | $goalHome += $this->bonusAge($this->homeTeam); |
||
| 71 | $goalAway += $this->bonusAge($this->awayTeam); |
||
| 72 | |||
| 73 | //Bonus on Good GoalKeeper |
||
| 74 | $goalies = $this->homeTeam->getBestPlayerForRole("GK");
|
||
| 75 | $goalAway -= $this->bonusGoalKeeper($goalies); |
||
| 76 | $goalies = $this->awayTeam->getBestPlayerForRole("GK");
|
||
| 77 | $goalHome -= $this->bonusGoalKeeper($goalies); |
||
| 78 | // |
||
| 79 | $homeModule = new Module($this->homeTeam->coach->favouriteModule); |
||
| 80 | $awayModule = new Module($this->awayTeam->coach->favouriteModule); |
||
| 81 | View Code Duplication | if ($homeModule->isOffensive()) {
|
|
| 82 | $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
||
| 83 | $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; |
||
| 84 | } |
||
| 85 | View Code Duplication | if ($awayModule->isOffensive()) {
|
|
| 86 | $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
||
| 87 | $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; |
||
| 88 | } |
||
| 89 | if ($awayModule->isDefensive()) {
|
||
| 90 | $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
||
| 91 | } |
||
| 92 | if ($homeModule->isDefensive()) {
|
||
| 93 | $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
||
| 94 | } |
||
| 95 | $goalHome = $goalHome < 0 ? 0 : $goalHome; |
||
| 96 | $goalAway = $goalAway < 0 ? 0 : $goalAway; |
||
| 97 | return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); |
||
| 98 | } |
||
| 99 | |||
| 174 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.