Completed
Push — master ( 5eb6e2...5eaa75 )
by Jakub
05:29
created

TextCombatLogRender::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Nette\Bridges\ApplicationLatte\ILatteFactory;
7
8
/**
9
 * TextCombatLogRender
10
 *
11
 * @property string $template
12
 */
13 1
final class TextCombatLogRender implements ICombatLogRender {
14 1
  use \Nette\SmartObject;
15
16
  /** @var \Latte\Engine */
17
  protected $latte;
18
  /** @var string */
19
  protected $template = __DIR__ . "/CombatLog.latte";
20
21
  public function __construct(ILatteFactory $latteFactory) {
22 1
    $this->latte = $latteFactory->create();
23 1
  }
24
25
  /**
26
   * @throws \RuntimeException
27
   */
28
  public function setTemplate(string $template): void {
29
    if(!is_file($template)) {
30
      throw new \RuntimeException("File $template does not exist.");
31
    }
32
    $this->template = $template;
33
  }
34
35
  public function render(array $params): string {
36 1
    return $this->latte->renderToString($this->template, $params);
37
  }
38
}
39
?>