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

HasDataTrait::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 1
crap 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