Completed
Push — master ( 48b451...90ac5a )
by Amine
47s queued 43s
created

TwigTemplate::clean()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Tarsana\Command\Template\Twig;
2
3
use Tarsana\Command\Interfaces\Template\TemplateInterface;
4
5
class TwigTemplate implements TemplateInterface {
6
7
    /**
8
     * Twig template instance.
9
     */
10
    protected $twig;
11
12
    /**
13
     * Data to pass to the template.
14
     *
15
     * @var array
16
     */
17
    protected $data;
18
19
    public function __construct ($twig)
20
    {
21
        $this->twig = $twig;
22
        $this->data = [];
23
    }
24
25
    /**
26
     * Binds data to the template.
27
     *
28
     * @param  array $data
29
     * @return self
30
     */
31
    public function bind (array $data) : TemplateInterface
32
    {
33
        $this->data = array_merge($this->data, $data);
34
        return $this;
35
    }
36
37
    /**
38
     * Renders the template.
39
     *
40
     * @return string
41
     */
42
    public function render(array $data = null) : string
43
    {
44
        if (null !== $data) {
45
            $this->bind($data);
46
        }
47
        return $this->twig->render($this->data);
48
    }
49
50
    /**
51
     * Clears the data.
52
     *
53
     * @return self
54
     */
55
    public function clean () : TemplateInterface
56
    {
57
        $this->data = [];
58
        return $this;
59
    }
60
}
61