Passed
Pull Request — master (#9)
by Rafael
03:29
created

Storage::setData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Behat\Storage;
12
13
/**
14
 * Store tmp values to use during tests
15
 */
16
class Storage implements \ArrayAccess, \Iterator
17
{
18
    protected $data = [];
19
20
    /**
21
     * Storage constructor.
22
     *
23
     * @param array $data
24
     */
25 1
    public function __construct(array $data = [])
26
    {
27 1
        $this->data = $data;
28 1
    }
29
30
    public function getData(): array
31
    {
32
        return $this->data;
33
    }
34
35
    public function setData(array $data): Storage
36
    {
37
        $this->data = $data;
38
39
        return $this;
40
    }
41
42
    public function clear()
43
    {
44
        $this->setData([]);
45
    }
46
47
    public function setValue(string $key, $value)
48
    {
49
        $this->data[$key] = $value;
50
    }
51
52
    public function getValue(string $key)
53
    {
54
        return $this->data[$key] ?? null;
55
    }
56
57
    public function offsetExists($offset)
58
    {
59
        return isset($this->data[$offset]);
60
    }
61
62
    public function offsetGet($offset)
63
    {
64
        $this->getValue($offset);
65
    }
66
67
    public function offsetSet($offset, $value)
68
    {
69
        $this->setValue($offset, $value);
70
    }
71
72
    public function offsetUnset($offset)
73
    {
74
        unset($this->data[$offset]);
75
    }
76
77
    /**
78
     * @return mixed
79
     */
80 1
    public function current()
81
    {
82 1
        return current($this->data);
83
    }
84
85
    /**
86
     *
87
     */
88 1
    public function next()
89
    {
90 1
        next($this->data);
91 1
    }
92
93
    /**
94
     * @return mixed
95
     */
96 1
    public function key()
97
    {
98 1
        return key($this->data);
99
    }
100
101
    /**
102
     * @return bool
103
     */
104 1
    public function valid()
105
    {
106 1
        return key($this->data) !== null;
107
    }
108
109
    /**
110
     *
111
     */
112 1
    public function rewind()
113
    {
114 1
        reset($this->data);
115 1
    }
116
117
    /**
118
     * @param string $name
119
     *
120
     * @return mixed
121
     */
122
    public function __get($name)
123
    {
124
        return $this->getValue($name);
125
    }
126
127
    /**
128
     * @param string $name
129
     * @param mixed  $value
130
     */
131
    public function __set($name, $value)
132
    {
133
        return $this->setValue($name, $value);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->setValue($name, $value) targeting Ynlo\GraphQLBundle\Behat...age\Storage::setValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
134
    }
135
136
    /**
137
     * @param string $name
138
     *
139
     * @return bool
140
     */
141
    public function __isset($name)
142
    {
143
        return $this->offsetExists($name);
144
    }
145
146
    /**
147
     * @param string $name
148
     */
149
    public function __unset($name)
150
    {
151
        return $this->offsetUnset($name);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->offsetUnset($name) targeting Ynlo\GraphQLBundle\Behat...\Storage::offsetUnset() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
152
    }
153
}
154