Completed
Push — master ( 5df011...747e00 )
by Changwan
03:50
created

Attributes::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Support;
3
4
trait Attributes
5
{
6
    /** @var array */
7
    protected $attributes = [];
8
9
    /**
10
     * @param string $name
11
     * @param array $arguments
12
     * @return static
13
     */
14 3
    public function __call($name, array $arguments = [])
15
    {
16 3
        $length = count($arguments);
17 3
        $this->attributes[Helper::camelCaseToUnderscore($name)] =
18 3
            $length ? $length === 1 ? $arguments[0] : $arguments : true;
19 3
        return $this;
20
    }
21
22
    /**
23
     * @param string $name
24
     * @return mixed
25
     */
26
    function __get($name)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
    {
28
        return isset($this->attributes[$name]) ? $this->attributes[$name] : null;
29
    }
30
31
    /**
32
     * @param string $name
33
     * @param string $value
34
     */
35
    function __set($name, $value)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
    {
37
        $this->attributes[$name] = $value;
38
    }
39
40
    /**
41
     * @param string $offset
42
     * @return bool
43
     */
44
    public function offsetExists($offset)
45
    {
46
        return array_key_exists($offset, $this->attributes);
47
    }
48
49
    /**
50
     * @param string $offset
51
     * @return mixed
52
     */
53
    public function offsetGet($offset)
54
    {
55
        return $this->__get($offset);
56
    }
57
58
    /**
59
     * @param string $offset
60
     * @param mixed $value
61
     */
62
    public function offsetSet($offset, $value)
63
    {
64
        $this->__set($offset, $value);
65
    }
66
67
    /**
68
     * @param string $offset
69
     */
70
    public function offsetUnset($offset)
71
    {
72
        unset($this->attributes[$offset]);
73
    }
74
}
75