Completed
Push — 2.0 ( 2c7009...c833bc )
by Marco
03:23
created

ArrayAccess::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 2
1
<?php namespace Comodojo\Extender\Components;
2
3
/**
4
 * @package     Comodojo Framework
5
 * @author      Marco Giovinazzi <[email protected]>
6
 * @author      Marco Castiello <[email protected]>
7
 * @license     GPL-3.0+
8
 *
9
 * LICENSE:
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
trait ArrayAccess {
26
27
    /**
28
     * Return the value at index
29
     *
30
     * @return string $index The offset
31
     */
32
     public function offsetGet($index) {
33
34
         return $this->data[$index];
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
36
     }
37
38
     /**
39
     * Assigns a value to index offset
40
     *
41
     * @param string $index The offset to assign the value to
42
     * @param mixed  $value The value to set
43
     */
44
     public function offsetSet($index, $value) {
45
46
         $this->data[$index] = $value;
47
48
     }
49
50
     /**
51
     * Unsets an index
52
     *
53
     * @param string $index The offset to unset
54
     */
55
     public function offsetUnset($index) {
56
57
         unset($this->data[$index]);
58
59
     }
60
61
     /**
62
     * Check if an index exists
63
     *
64
     * @param string $index Offset
65
     * @return boolean
66
     */
67
     public function offsetExists($index) {
68
69
         return $this->offsetGet($index) !== null;
70
71
     }
72
73
}
74