Passed
Push — master ( 37d9b5...bf2aee )
by Thierry
04:39 queued 02:29
created

TemplateView::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
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\Ui\View\Store;
6
use Jaxon\Ui\View\ViewInterface;
7
use Jaxon\Utils\Template\TemplateEngine;
0 ignored issues
show
Bug introduced by
The type Jaxon\Utils\Template\TemplateEngine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class TemplateView implements ViewInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class TemplateView
Loading history...
10
{
11
    /**
12
     * The Jaxon template engine
13
     *
14
     * @var TemplateEngine
15
     */
16
    protected $xTemplateEngine;
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 $xTemplateEngine should have a doc-comment as per coding-style.
Loading history...
19
     * The class constructor
20
     */
21
    public function __construct(TemplateEngine $xTemplateEngine)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
22
    {
23
        $this->xTemplateEngine = $xTemplateEngine;
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 name; 4 found
Loading history...
30
     * @param string $sDirectory    The namespace directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 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 name; 4 found
Loading history...
32
     *
33
     * @return void
34
     */
35
    public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = '')
36
    {
37
        $this->xTemplateEngine->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; 4 found
Loading history...
44
     *
45
     * @return string        The string representation of the view
46
     */
47
    public function render(Store $store): string
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->xTemplateEngine->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