Completed
Push — master ( c91f7e...031f04 )
by Giancarlos
02:30
created

HtmlReport::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Giansalex
5
 * Date: 17/09/2017
6
 * Time: 21:55
7
 */
8
9
namespace Greenter\Report;
10
11
use Greenter\Model\DocumentInterface;
12
13
/**
14
 * Class HtmlReport
15
 * @package Greenter\Report
16
 */
17
class HtmlReport implements ReportInterface
0 ignored issues
show
Bug introduced by
There is one abstract method build in this class; you could implement it, or declare this class as abstract.
Loading history...
18
{
19
    /**
20
     * @var \Twig_Environment
21
     */
22
    private $twig;
23
24
    /**
25
     * @var string
26
     */
27
    private $template;
28
29
    /**
30
     * HtmlReport constructor.
31
     * @param string $templatesDir
32
     * @param array $optionTwig
33
     */
34 2
    public function __construct($templatesDir = '', $optionTwig = [])
35
    {
36 2
        if (empty($templatesDir)) {
37 2
            $templatesDir = __DIR__ . '/Templates';
38 2
        }
39 2
        $loader = new \Twig_Loader_Filesystem($templatesDir);
40 2
        $this->twig = new \Twig_Environment($loader, $optionTwig);
41 2
    }
42
43
    /**
44
     * Build html report.
45
     *
46
     * @param DocumentInterface $document
47
     * @param array $parameters
48
     * @return bool|string
49
     */
50 2
    public function render(DocumentInterface $document, $parameters = [])
51
    {
52 2
        $html = $this->twig->render($this->template, [
53 2
            'doc' => $document,
54
            'params' => $parameters
55 2
        ]);
56
57 2
        return $html;
58
    }
59
60
    /**
61
     * Set filename templte.
62
     *
63
     * @param string $template
64
     */
65 2
    public function setTemplate($template)
66
    {
67 2
        $this->template = $template;
68
    }
69
}