Passed
Push — feature/packages ( 3445e7...793294 )
by Thierry
03:04
created

View   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addNamespace() 0 4 1
A render() 0 12 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Utils\Template;
4
5
use Jaxon\Contracts\View as ViewContract;
6
use Jaxon\Utils\View\Store;
7
8
class View implements ViewContract
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class View
Loading history...
9
{
10
    /**
11
     * The Jaxon template engine
12
     *
13
     * @var Engine
14
     */
15
    protected $xEngine;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
16
17
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $xEngine should have a doc-comment as per coding-style.
Loading history...
18
     * The class constructor
19
     */
20
    public function __construct(Engine $xEngine)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
21
    {
22
        $this->xEngine = $xEngine;
23
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
24
25
    /**
26
     * Add a namespace to this view renderer
27
     *
28
     * @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...
29
     * @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...
30
     * @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...
31
     *
32
     * @return void
33
     */
34
    public function addNamespace($sNamespace, $sDirectory, $sExtension = '')
35
    {
36
        $this->xEngine->addNamespace($sNamespace, $sDirectory, $sExtension);
37
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39
    /**
40
     * Render a view
41
     *
42
     * @param Store         $store        A store populated with the view data
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 8 found
Loading history...
43
     *
44
     * @return string        The string representation of the view
45
     */
46
    public function render(Store $store)
47
    {
48
        $sViewName = $store->getViewName();
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49
        $sNamespace = $store->getNamespace();
50
        // In this view renderer, the namespace must always be prepended to the view name.
51
        if(substr($sViewName, 0, strlen($sNamespace) + 2) != $sNamespace . '::')
52
        {
53
            $sViewName = $sNamespace . '::' . $sViewName;
54
        }
55
        // Render the template
56
        return trim($this->xEngine->render($sViewName, $store->getViewData()), " \t\n");
57
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
58
}
59