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