| Total Complexity | 8 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 6 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | 1 | final class CombatLogger implements \Countable, \IteratorAggregate, \Stringable |
|
| 14 | { |
||
| 15 | private Team $team1; |
||
| 16 | private Team $team2; |
||
| 17 | private array $actions = []; |
||
| 18 | public int $round = 0; |
||
| 19 | public string $title = ""; |
||
| 20 | |||
| 21 | 1 | public function __construct(private readonly ICombatLogRender $render, private readonly Translator $translator) |
|
| 22 | { |
||
| 23 | 1 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Set teams |
||
| 27 | */ |
||
| 28 | public function setTeams(Team $team1, Team $team2): void |
||
| 29 | { |
||
| 30 | 1 | if (isset($this->team1)) { |
|
| 31 | 1 | throw new ImmutableException("Teams has already been set."); |
|
| 32 | } |
||
| 33 | 1 | $this->team1 = $team1; |
|
| 34 | 1 | $this->team2 = $team2; |
|
| 35 | 1 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Adds new entry |
||
| 39 | */ |
||
| 40 | public function log(array $action): void |
||
| 41 | { |
||
| 42 | 1 | $this->actions[$this->round][] = new CombatLogEntry($action); |
|
| 43 | 1 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Adds text entry |
||
| 47 | */ |
||
| 48 | public function logText(string $text, array $params = []): void |
||
| 51 | 1 | } |
|
| 52 | |||
| 53 | public function __toString(): string |
||
| 54 | { |
||
| 55 | 1 | $params = [ |
|
| 56 | 1 | "team1" => $this->team1, "team2" => $this->team2, "actions" => $this->actions, "title" => $this->title, |
|
| 57 | ]; |
||
| 58 | 1 | return $this->render->render($params); |
|
| 59 | } |
||
| 60 | |||
| 61 | public function count(): int |
||
| 64 | } |
||
| 65 | |||
| 66 | public function getIterator(): \ArrayIterator |
||
| 67 | { |
||
| 71 |