Twig   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compiler() 0 8 2
A render() 0 8 1
1
<?php 
2
3
namespace Helmut\Forms\Engines;
4
5
use Helmut\Forms\Engine;
6
use Twig_Environment;
7
use Twig_Loader_Array;
8
9
class Twig implements Engine {
10
11
    /**
12
     * The twig compiler engine.
13
     *
14
     * @var \Twig_Environment
15
     */ 
16
    protected $compiler;
17
18
    /**
19
     * Fetch the compiler.
20
     *
21
     * @return \Twig_Environment
22
     */
23
    public function compiler()
24
    {
25
        if ( ! $this->compiler) {
26
            $this->compiler = new Twig_Environment(new Twig_Loader_Array([]));
27
        }
28
29
        return $this->compiler;
30
    }
31
32
    /**
33
     * Render the template content.
34
     *
35
     * @param  string  $path
36
     * @param  array  $properties
37
     * @return string
38
     */
39
    public function render($path, $properties = []) 
40
    {
41
        $content = file_get_contents($path);
42
43
        $template = $this->compiler()->createTemplate($content);
44
45
        return $template->render($properties);
46
    }
47
48
}
49