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

TextCombatLogRender   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 24
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A setTemplate() 0 5 2
A render() 0 2 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
?>