Completed
Push — master ( 74371a...6da8c0 )
by Vladimir
02:21
created

TwigError::buildException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * @copyright 2018 Vladimir Jimenez
4
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
5
 */
6
7
namespace allejo\stakx\Templating\Twig;
8
9
use allejo\stakx\Templating\TemplateErrorInterface;
10
11
class TwigError extends \Exception implements TemplateErrorInterface
12
{
13
    private $error;
14
    private $content;
15
    private $relativeFilePath;
16
    private $name;
17
18
    public function __construct(\Twig_Error $error)
19
    {
20
        $this->error = $error;
21
        $this->message = $error->getRawMessage();
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getTemplateLine()
28
    {
29
        return $this->error->getTemplateLine();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function setTemplateLine($lineNumber)
36
    {
37
        $this->error->setTemplateLine($lineNumber);
38
39
        return $this;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function setContent($content)
46
    {
47
        $this->content = $content;
48
49
        return $this;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function setName($name)
56
    {
57
        $this->name = $name;
58
59
        return $this;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setRelativeFilePath($filePath)
66
    {
67
        $this->relativeFilePath = $filePath;
68
69
        return $this;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function buildException()
76
    {
77
        $this->error->setSourceContext(new \Twig_Source(
78
            $this->content,
79
            $this->name,
80
            $this->relativeFilePath
81
        ));
82
    }
83
}
84