HasDataTrait::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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