Passed
Push — master ( 50d1ae...1ff9a4 )
by Gabriel
08:59
created

View::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A View::isBlock() 0 3 2
1
<?php
2
3
namespace Nip\View;
4
5
use Nip\View\Extensions\Helpers\HasHelpersTrait;
6
use Nip\View\ViewFinder\HasViewFinder;
7
8
/**
9
 * Class View
10
 *
11
 */
12
class View implements ViewInterface
13
{
14
    use Traits\CanRenderTrait;
15
    use Traits\HasDataTrait;
16
    use Traits\HasExtensionsTrait;
17
    use HasHelpersTrait;
18
    use Traits\HasMethodsTrait;
19
    use Traits\HasPathsTrait;
20
    use Traits\HasRequestTrait;
21
    use Traits\MethodsOverloadingTrait;
22
23
    use HasViewFinder;
24
25
    protected $helpers = [];
26
    protected $blocks = [];
27
28 9
    public function __construct()
29
    {
30 9
        $this->addMethodsPipelineStage();
31 9
        $this->addHelpersExtension();
32 9
        $this->initFinder();
33 9
    }
34
35
    /**
36
     * @param $name
37
     * @param $block
38
     */
39
    public function setBlock($name, $block)
40
    {
41
        $this->blocks[$name] = $block;
42
    }
43
44
    /**
45
     * @param string $block
46
     */
47
    public function render($block = 'default')
48
    {
49
        if (!empty($this->blocks[$block])) {
50
            $this->load("/" . $this->blocks[$block]);
51
        } else {
52
            trigger_error("No $block block", E_USER_ERROR);
53
        }
54
    }
55
56
    /**
57
     * Builds path for including
58
     * If $view starts with / the path will be relative to the root of the views folder.
59
     * Otherwise to caller file location.
60
     *
61
     * @param string $view
62
     * @return string
63
     */
64 4
    public function buildPath($view)
65
    {
66 4
        return $this->getFinder()->find($view);
67
    }
68
69
    /**
70
     * @param string $block
71
     * @return bool
72
     */
73
    public function isBlock($block = 'default')
74
    {
75
        return empty($this->blocks[$block]) ? false : true;
76
    }
77
78
    /**
79
     * Assigns variables in bulk in the current scope
80
     *
81
     * @param array $array
82
     * @return $this
83
     */
84
    public function assign($array = [])
85
    {
86
        foreach ($array as $key => $value) {
87
            if (is_string($key)) {
88
                $this->set($key, $value);
89
            }
90
        }
91
92
        return $this;
93
    }
94
}
95