| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 28 | public function testRendering(): void |
||
| 29 | { |
||
| 30 | /** @var TextCombatLogRender $render */ |
||
| 31 | $render = $this->getService(TextCombatLogRender::class); |
||
| 32 | /** @var CombatLogger $logger */ |
||
| 33 | $logger = $this->getService(CombatLogger::class); |
||
| 34 | $team1 = new Team("Team 1"); |
||
| 35 | $team1[] = $character1 = $this->generateCharacter(1); |
||
| 36 | $team2 = new Team("Team 2"); |
||
| 37 | $team2[] = $character2 = $this->generateCharacter(2); |
||
| 38 | $logger->setTeams($team1, $team2); |
||
| 39 | $logger->round = 1; |
||
| 40 | $logger->logText("abc.abc"); |
||
| 41 | $logger->log([ |
||
| 42 | "action" => CombatActions\Attack::ACTION_NAME, "name" => "", "result" => true, "amount" => 1, |
||
| 43 | "character1" => $character1, "character2" => $character2, |
||
| 44 | ]); |
||
| 45 | $logger->log([ |
||
| 46 | "action" => CombatActions\Attack::ACTION_NAME, "name" => "", "result" => false, "amount" => 1, |
||
| 47 | "character1" => $character2, "character2" => $character1, |
||
| 48 | ]); |
||
| 49 | $logger->round = 2; |
||
| 50 | $logger->log([ |
||
| 51 | "action" => CombatActions\SkillAttack::ACTION_NAME, "name" => "Abc", "result" => true, "amount" => 1, |
||
| 52 | "character1" => $character1, "character2" => $character2, |
||
| 53 | ]); |
||
| 54 | $logger->log([ |
||
| 55 | "action" => CombatActions\SkillAttack::ACTION_NAME, "name" => "Def", "result" => false, "amount" => 1, |
||
| 56 | "character1" => $character2, "character2" => $character1, |
||
| 57 | ]); |
||
| 58 | $logger->log([ |
||
| 59 | "action" => CombatActions\SkillSpecial::ACTION_NAME, "name" => "Abc", "result" => true, "amount" => 1, |
||
| 60 | "character1" => $character1, "character2" => $character2, |
||
| 61 | ]); |
||
| 62 | $logger->log([ |
||
| 63 | "action" => CombatActions\SkillSpecial::ACTION_NAME, "name" => "Def", "result" => false, "amount" => 1, |
||
| 64 | "character1" => $character2, "character2" => $character1, |
||
| 65 | ]); |
||
| 66 | $logger->log([ |
||
| 67 | "action" => CombatActions\Heal::ACTION_NAME, "name" => "", "result" => true, "amount" => 1, |
||
| 68 | "character1" => $character1, "character2" => $character2, |
||
| 69 | ]); |
||
| 70 | $logger->log([ |
||
| 71 | "action" => CombatActions\Heal::ACTION_NAME, "name" => "", "result" => false, "amount" => 1, |
||
| 72 | "character1" => $character2, "character2" => $character1, |
||
| 73 | ]); |
||
| 74 | $logger->log([ |
||
| 75 | "action" => CombatLogEntry::ACTION_POISON, "name" => "", "result" => true, "amount" => 1, |
||
| 76 | "character1" => $character1, "character2" => $character2, |
||
| 77 | ]); |
||
| 78 | $params = [ |
||
| 79 | "team1" => $team1, "team2" => $team2, "actions" => $logger->getIterator(), "title" => "", |
||
| 80 | ]; |
||
| 81 | Assert::same(file_get_contents(__DIR__ . "/CombatLogExpected.latte"), $render->render($params)); |
||
| 82 | } |
||
| 87 |