Passed
Push — master ( cb21e9...877f87 )
by Gabriel
12:19
created

HasDataTrait   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 30%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
eloc 14
c 2
b 0
f 0
dl 0
loc 90
rs 10
ccs 3
cts 10
cp 0.3

10 Methods

Rating   Name   Duplication   Size   Complexity  
A initData() 0 3 1
A offsetSet() 0 3 1
A offsetGet() 0 3 1
A offsetUnset() 0 3 1
A __set() 0 3 1
A all() 0 3 1
A with() 0 6 3
A offsetExists() 0 3 1
A __get() 0 3 1
A set() 0 3 1
1
<?php
2
3
namespace Nip\Controllers\Response\ResponsePayload;
4
5
use Nip\Controllers\Response\ResponseData;
6
7
/**
8
 * Trait HasDataTrait
9
 * @package Nip\Controllers\Response\ResponsePayload
10
 */
11
trait HasDataTrait
12
{
13
    /**
14
     * @var ResponseData
15
     */
16
    public $data;
17
18 3
    /**
19
     * @inheritDoc
20 3
     */
21 3
    public function offsetExists($offset): bool
22
    {
23
        return $this->data->has($offset);
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function offsetGet($offset)
30
    {
31
        return $this->data->get($offset);
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function offsetSet($offset, $value)
38
    {
39
        $this->set($offset, $value);
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45
    public function offsetUnset($offset)
46
    {
47
        $this->data->unset($offset);
48
    }
49
50
    /**
51
     * @param string $key
52
     * @return mixed|null
53
     */
54
    public function __get(string $key)
55
    {
56
        return $this->data->get($key);
57
    }
58
59
    /**
60
     * @param $name
61
     * @param $value
62
     */
63
    public function __set($name, $value)
64
    {
65
        $this->data->set($name, $value);
66
    }
67
68
    /**
69
     * @param $name
70
     * @param $value
71
     */
72
    public function set($name, $value)
73
    {
74
        $this->data->set($name, $value);
75
    }
76
77
    /**
78
     * @param $name
79
     * @param $value
80
     */
81
    public function with($key, $value = null)
82
    {
83
        $data = is_array($key) ? $key : [$key => $value];
84
85
        foreach ($data as $key => $value) {
0 ignored issues
show
introduced by
$key is overwriting one of the parameters of this function.
Loading history...
86
            $this->set($key, $value);
87
        }
88
    }
89
90
    /**
91
     * @return mixed
92
     */
93
    public function all()
94
    {
95
        return $this->data->all();
96
    }
97
98
    protected function initData()
99
    {
100
        $this->data = new ResponseData();
101
    }
102
}
103