Completed
Push — master ( 8155ff...9fff48 )
by Changwan
03:00
created

Attributes   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 5
cts 20
cp 0.25
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 7 3
A __get() 0 4 2
A __set() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
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