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

HtmlReport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A build() 0 9 1
A setTemplate() 0 4 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
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
}