Test Failed
Push — master ( 22db96...000286 )
by Giancarlos
04:11
created

TwigBuilder::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Giansalex
5
 * Date: 09/08/2017
6
 * Time: 19:23
7
 */
8
9
namespace Greenter\Xml\Builder;
10
11
/**
12
 * Class TwigBuilder
13
 * @package Greenter\Xml\Builder
14
 */
15
class TwigBuilder
16
{
17
    /**
18
     * @var \Twig_Environment
19
     */
20
    protected $twig;
21
22
    /**
23
     * TwigBuilder constructor.
24
     * @param array $options [optional] Recommended: 'cache' => '/dir/cache'
25
     */
26 4
    public function __construct($options = [])
27
    {
28 4
        $this->initTwig($options);
29 4
    }
30
31
    /**
32
     * Get Content XML from template.
33
     *
34
     * @param string $template
35
     * @param object $doc
36
     * @return string
37
     */
38 4
    public function render($template, $doc)
39
    {
40 4
        return $this->twig->render($template, [
41
            'doc' => $doc
42 4
        ]);
43
    }
44
45 4
    private function initTwig($options)
46
    {
47 4
        $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../Templates');
48 4
        $numFilter = new \Twig_SimpleFilter('n_format', function ($number, $decimals = 2) {
49 4
            return number_format($number, $decimals, '.', '');
50 4
        });
51 4
        $twig = new \Twig_Environment($loader, $options);
52 4
        $twig->addFilter($numFilter);
53
54 4
        $this->twig = $twig;
55
    }
56
}