Passed
Push — master ( 7bd07e...7e5ad5 )
by 世昌
02:03
created

EmptyTemplate::extends()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\component\template;
3
4
class EmptyTemplate implements Template
5
{
6
    /**
7
     * 值
8
     *
9
     * @var array
10
     */
11
    protected $value;
12
    /**
13
     * 继承
14
     *
15
     * @var Template
16
     */
17
    protected $extens;
18
19
    public function get(string $name=null, $default=null)
20
    {
21
        if (is_null($name)) {
22
            return $this->value;
23
        }
24
        return $this->value[$name] ?? $default;
25
    }
26
27
    public function set(string $name, $value)
28
    {
29
        $this->value[$name] = $value;
30
        return $this;
31
    }
32
    
33
    public function has(string $name)
34
    {
35
        return \array_key_exists($name, $this->value);
36
    }
37
38
    public function assign(array $values)
39
    {
40
        $this->value=array_merge($this->value, $values);
41
        return $this;
42
    }
43
    
44
    public function include(Template $template)
45
    {
46
        $template->assign($this->value);
47
        $template->getRenderedString();
48
    }
49
50
    public function extends(Template $template)
51
    {
52
        $this->extends = $template;
0 ignored issues
show
Bug Best Practice introduced by
The property extends does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
53
    }
54
    
55
    public function insert(string $name, $callback)
56
    {
57
    }
58
    
59
    public function exec(string $name)
60
    {
61
    }
62
63
    public function getRenderedString()
64
    {
65
        $text =  'EmptyTemplate<'.$this->get('name', 'null').'>';
66
        if ($this->extends) {
67
            $text = $this->extends->getRenderedString();
68
        }
69
        return $text;
70
    }
71
}
72