Conditions | 15 |
Paths | 2700 |
Total Lines | 70 |
Code Lines | 46 |
Lines | 8 |
Ratio | 11.43 % |
Changes | 5 | ||
Bugs | 1 | Features | 1 |
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 |
||
36 | public function simulate() |
||
37 | { |
||
38 | $homePoints = $this->homeTeam->getAvgSkill(); |
||
39 | $awayPoints = $this->awayTeam->getAvgSkill(); |
||
40 | |||
41 | $homePoints += $this->malusModule( |
||
42 | $this->homeTeam->coach->favouriteModule, |
||
43 | $this->homeTeam->playersPerRoleArray() |
||
44 | ); |
||
45 | $awayPoints += $this->malusModule( |
||
46 | $this->awayTeam->coach->favouriteModule, |
||
47 | $this->awayTeam->playersPerRoleArray() |
||
48 | ); |
||
49 | |||
50 | $goalHome = 0; |
||
51 | $goalAway = 0; |
||
52 | |||
53 | if (Randomizer::boolOnPercentage(80)) { |
||
54 | |||
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 | |||
66 | } else { |
||
67 | $goalHome += $this->chance(); |
||
68 | $goalAway += $this->chance(); |
||
69 | $goalHome += $this->bonusHome(); |
||
70 | } |
||
71 | |||
72 | $goalHome += $this->bonusAge($this->homeTeam); |
||
73 | $goalAway += $this->bonusAge($this->awayTeam); |
||
74 | |||
75 | |||
76 | //Bonus on Good GoalKeeper |
||
77 | $goalies = $this->homeTeam->getBestPlayerForRole("GK"); |
||
1 ignored issue
–
show
|
|||
78 | $goalAway -= $this->bonusGoalkeeper($goalies); |
||
79 | $goalies = $this->awayTeam->getBestPlayerForRole("GK"); |
||
1 ignored issue
–
show
|
|||
80 | $goalHome -= $this->bonusGoalkeeper($goalies); |
||
81 | // |
||
82 | |||
83 | $homeModule = new Module($this->homeTeam->coach->favouriteModule); |
||
84 | $awayModule = new Module($this->awayTeam->coach->favouriteModule); |
||
85 | |||
86 | View Code Duplication | if ($homeModule->isOffensive()) { |
|
1 ignored issue
–
show
|
|||
87 | $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
||
88 | $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; |
||
89 | } |
||
90 | View Code Duplication | if ($awayModule->isOffensive()) { |
|
1 ignored issue
–
show
|
|||
91 | $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; |
||
92 | $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; |
||
93 | } |
||
94 | |||
95 | if ($awayModule->isDefensive()) { |
||
96 | $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
||
97 | } |
||
98 | if ($homeModule->isDefensive()) { |
||
99 | $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; |
||
100 | } |
||
101 | |||
102 | $goalHome = $goalHome < 0 ? 0 : $goalHome; |
||
103 | $goalAway = $goalAway < 0 ? 0 : $goalAway; |
||
104 | return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); |
||
105 | } |
||
106 | |||
158 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.