Passed
Push — master ( 8a0ecd...051b5d )
by Thierry
03:49 queued 13s
created

ViewTrait::addNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 3
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\App\View;
4
5
use function ltrim;
6
use function rtrim;
7
8
trait ViewTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait ViewTrait
Loading history...
9
{
10
    /**
11
     * The template directories
12
     *
13
     * @var array
14
     */
15
    protected $aDirectories = [];
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
16
17
    /**
18
     * The directory of the current template
19
     *
20
     * @var string
21
     */
22
    protected $sDirectory = '';
23
24
    /**
25
     * The extension of the current template
26
     *
27
     * @var string
28
     */
29
    protected $sExtension = '';
30
31
    /**
32
     * Add a namespace to the view renderer
33
     *
34
     * @param string $sNamespace    The namespace name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
35
     * @param string $sDirectory    The namespace directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
36
     * @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...
37
     *
38
     * @return void
39
     */
40
    public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = '')
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
41
    {
42
        $this->aDirectories[$sNamespace] = ['path' => $sDirectory, 'ext' => $sExtension];
43
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
44
45
    /**
46
     * Set the namespace of the template being rendered
47
     *
48
     * @param string $sNamespace    The namespace name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
49
     *
50
     * @return void
51
     */
52
    public function setCurrentNamespace(string $sNamespace)
53
    {
54
        $this->sDirectory = '';
55
        $this->sExtension = '';
56
        if(isset($this->aDirectories[$sNamespace]))
57
        {
58
            // Make sure there's only one '/' at the end of the string
59
            $this->sDirectory = rtrim($this->aDirectories[$sNamespace]['path'], '/') . '/';
60
            // Make sure there's only one '.' at the beginning of the string
61
            $this->sExtension = '.' . ltrim($this->aDirectories[$sNamespace]['ext'], '.');
62
        }
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
64
}
65