Completed
Push — master ( dcf16a...f444a3 )
by Giancarlos
05:31
created

HtmlReport::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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
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
    public function __construct($templatesDir = '', $optionTwig = [])
35
    {
36
        if (empty($templatesDir)) {
37
            $templatesDir = __DIR__ . '/Templates';
38
        }
39
        $loader = new \Twig_Loader_Filesystem($templatesDir);
40
        $this->twig = new \Twig_Environment($loader, $optionTwig);
41
    }
42
43
    /**
44
     * Build html report.
45
     *
46
     * @param DocumentInterface $document
47
     * @param array $parameters
48
     * @return bool|string
49
     */
50
    public function build(DocumentInterface $document, $parameters = [])
51
    {
52
        $html = $this->twig->render($this->template, [
53
            'doc' => $document,
54
            'params' => $parameters
55
        ]);
56
57
        return $html;
58
    }
59
60
    /**
61
     * Set filename templte.
62
     *
63
     * @param string $template
64
     */
65
    public function setTemplate($template)
66
    {
67
        $this->template = $template;
68
    }
69
}