ViewHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A __construct() 0 8 2
A name() 0 3 1
1
<?php
2
3
namespace Staticka\Helpers;
4
5
use Staticka\Contracts\HelperContract;
6
use Staticka\Contracts\WebsiteContract;
7
use Staticka\Contracts\RendererContract;
8
9
/**
10
 * View Helper
11
 *
12
 * @package Rouginsons
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
class ViewHelper implements HelperContract
16
{
17
    /**
18
     * @var \Staticka\Contracts\RendererContract
19
     */
20
    protected $renderer;
21
22
    /**
23
     * TODO: Remove Website instance in v1.0.0.
24
     * RendererContract should only be used.
25
     *
26
     * Initializes the helper instance.
27
     *
28
     * @param \Staticka\Contracts\WebsiteContract|\Staticka\Contracts\RendererContract $website
29
     */
30 6
    public function __construct($renderer)
31
    {
32 6
        if ($renderer instanceof WebsiteContract)
33 2
        {
34 6
            $renderer = $renderer->renderer();
35 2
        }
36
37 6
        $this->renderer = $renderer;
38 6
    }
39
40
    /**
41
     * Renders the partial template.
42
     *
43
     * @param  string $name
44
     * @param  array  $data
45
     * @return string
46
     */
47 3
    public function render($name, array $data = array())
48
    {
49 3
        return $this->renderer->render($name, $data);
50
    }
51
52
    /**
53
     * Returns the name of the helper.
54
     *
55
     * @return string
56
     */
57 3
    public function name()
58
    {
59 3
        return 'view';
60
    }
61
}
62