Conditions | 12 |
Paths | 12 |
Total Lines | 44 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Tests | 27 |
CRAP Score | 12.5487 |
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 |
||
114 | protected function parse(): void { |
||
115 | 1 | $character1 = $this->character1->name; |
|
116 | 1 | $character2 = $this->character2->name; |
|
117 | 1 | $text = ""; |
|
118 | 1 | switch($this->action) { |
|
119 | 1 | case static::ACTION_ATTACK: |
|
120 | 1 | if($this->result) { |
|
121 | 1 | $text = $this->translator->translate("combat.log.attackHits", $this->amount, ["character1" => $character1, "character2" => $character2]); |
|
122 | 1 | if($this->character2->hitpoints < 1) { |
|
123 | 1 | $text .= $this->translator->translate("combat.log.characterFalls"); |
|
124 | } |
||
125 | } else { |
||
126 | 1 | $text = $this->translator->translate("combat.log.attackFails", $this->amount, ["character1" => $character1, "character2" => $character2]); |
|
127 | } |
||
128 | 1 | break; |
|
129 | 1 | case static::ACTION_SKILL_ATTACK: |
|
130 | 1 | if($this->result) { |
|
131 | 1 | $text = $this->translator->translate("combat.log.specialAttackHits", $this->amount, ["character1" => $character1, "character2" => $character2, "name" => $this->name]); |
|
132 | 1 | if($this->character2->hitpoints < 1) { |
|
133 | 1 | $text .= $this->translator->translate("combat.log.characterFalls"); |
|
134 | } |
||
135 | } else { |
||
136 | 1 | $text = $this->translator->translate("combat.log.specialAttackFails", $this->amount, ["character1" => $character1, "character2" => $character2, "name" => $this->name]); |
|
137 | } |
||
138 | 1 | break; |
|
139 | 1 | case static::ACTION_SKILL_SPECIAL: |
|
140 | 1 | if($this->result) { |
|
141 | 1 | $text = $this->translator->translate("combat.log.specialSkillSuccess", 0, ["character1" => $character1, "character2" => $character2, "name" => $this->name]); |
|
142 | } else { |
||
143 | $text = $this->translator->translate("combat.log.specialSKillFailure", 0, ["character1" => $character1, "character2" => $character2, "name" => $this->name]); |
||
144 | } |
||
145 | 1 | break; |
|
146 | 1 | case static::ACTION_HEALING: |
|
147 | if($this->result) { |
||
148 | $text = $this->translator->translate("combat.log.healingSuccess", $this->amount, ["character1" => $character1, "character2" => $character2]); |
||
149 | } else { |
||
150 | $text = $this->translator->translate("combat.log.healingFailure", $this->amount, ["character1" => $character1, "character2" => $character2]); |
||
151 | } |
||
152 | break; |
||
153 | 1 | case static::ACTION_POISON: |
|
154 | 1 | $text = $this->translator->translate("combat.log.poison", $this->amount, ["character1" => $character1]); |
|
155 | 1 | break; |
|
156 | } |
||
157 | 1 | $this->message = $text; |
|
1 ignored issue
–
show
|
|||
158 | 1 | } |
|
164 | ?> |