LatteView   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A with() 0 6 1
A render() 0 10 3
1
<?php
2
namespace Wandu\View\Bridges\Latte;
3
4
use Latte\Engine;
5
use Wandu\View\Contracts\RenderInterface;
6
use Wandu\View\FileNotFoundException;
7
8
class LatteView implements RenderInterface
9
{
10
    /** @var \Latte\Engine */
11
    protected $latte;
12
13
    /** @var string */
14
    protected $basePath;
15
16
    /** @var array */
17
    protected $values = [];
18
19
    /**
20
     * @param \Latte\Engine $latte
21
     * @param string $basePath
22
     */
23
    public function __construct(Engine $latte, $basePath = '')
24
    {
25
        $this->latte = $latte;
26
        $this->basePath = $basePath;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function with(array $values = [])
33
    {
34
        $new = clone $this;
35
        $new->values = $values;
36
        return $new;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function render($template, array $values = [], $basePath = null)
43
    {
44
        if (!isset($basePath)) {
45
            $basePath = $this->basePath;
46
        }
47
        if (!file_exists("{$basePath}/{$template}")) {
48
            throw new FileNotFoundException("Cannot find the file, {$basePath}/{$template}");
49
        }
50
        return $this->latte->renderToString("{$basePath}/{$template}" , $values + $this->values);
51
    }
52
}
53