Completed
Push — master ( 22c257...e714e6 )
by Gabriel
13:14 queued 10:09
created

HasDataTrait::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\View\Traits;
4
5
/**
6
 * Trait HasDataTrait
7
 * @package Nip\View\Traits
8
 */
9
trait HasDataTrait
10
{
11
    protected $data = [];
12
13
    /**
14
     * @param $name
15
     * @return mixed|null
16
     */
17
    public function __get($name)
18
    {
19
        return $this->get($name);
20
    }
21
22
    /**
23
     * @param $name
24
     * @param $value
25
     * @return $this
26
     */
27
    public function __set($name, $value)
28
    {
29
        return $this->set($name, $value);
30
    }
31
32
    /**
33
     * @param  string $name
34
     * @return mixed|null
35
     */
36
    public function get($name)
37
    {
38
        if ($this->has($name)) {
39
            return $this->data[$name];
40
        } else {
41
            return null;
42
        }
43
    }
44
45
    /**
46
     * @param string $name
47
     * @return bool
48
     */
49
    public function has($name)
50
    {
51
        return isset($this->data[$name]);
52
    }
53
54
    /**
55
     * @param string $name
56
     * @param mixed $value
57
     * @return $this
58
     */
59
    public function set($name, $value)
60
    {
61
        $this->data[$name] = $value;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @param $name
68
     * @return bool
69
     */
70
    public function __isset($name)
71
    {
72
        return isset($this->data[$name]);
73
    }
74
75
    /**
76
     * @param $name
77
     */
78
    public function __unset($name)
79
    {
80
        unset($this->data[$name]);
81
    }
82
83
    /**
84
     * @param string $name
85
     * @param string $appended
86
     * @return $this
87
     */
88
    public function append($name, $appended)
89
    {
90
        $value = $this->has($name) ? $this->get($name) : '';
91
        $value .= $appended;
92
93
        return $this->set($name, $value);
94
    }
95
}
96