Passed
Push — master ( 0602c9...8f96ba )
by Thierry
02:02
created

View   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addNamespace() 0 3 1
A __construct() 0 3 1
A render() 0 11 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Ui\Template;
4
5
use Jaxon\Contracts\View as ViewContract;
6
use Jaxon\Ui\View\Store;
7
use Jaxon\Utils\Template\Engine;
8
9
class View implements ViewContract
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class View
Loading history...
10
{
11
    /**
12
     * The Jaxon template engine
13
     *
14
     * @var Engine
15
     */
16
    protected $xEngine;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
17
18
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $xEngine should have a doc-comment as per coding-style.
Loading history...
19
     * The class constructor
20
     */
21
    public function __construct(Engine $xEngine)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
22
    {
23
        $this->xEngine = $xEngine;
24
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
25
26
    /**
27
     * Add a namespace to this view renderer
28
     *
29
     * @param string        $sNamespace         The namespace name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 9 found
Loading history...
30
     * @param string        $sDirectory         The namespace directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 9 found
Loading history...
31
     * @param string        $sExtension         The extension to append to template names
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 9 found
Loading history...
32
     *
33
     * @return void
34
     */
35
    public function addNamespace($sNamespace, $sDirectory, $sExtension = '')
36
    {
37
        $this->xEngine->addNamespace($sNamespace, $sDirectory, $sExtension);
38
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
39
40
    /**
41
     * Render a view
42
     *
43
     * @param Store         $store        A store populated with the view data
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
44
     *
45
     * @return string        The string representation of the view
46
     */
47
    public function render(Store $store)
48
    {
49
        $sViewName = $store->getViewName();
50
        $sNamespace = $store->getNamespace();
51
        // In this view renderer, the namespace must always be prepended to the view name.
52
        if(substr($sViewName, 0, strlen($sNamespace) + 2) != $sNamespace . '::')
53
        {
54
            $sViewName = $sNamespace . '::' . $sViewName;
55
        }
56
        // Render the template
57
        return trim($this->xEngine->render($sViewName, $store->getViewData()), " \t\n");
58
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
59
}
60