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

HtmlReport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 53
ccs 15
cts 15
cp 1
rs 10

3 Methods

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