Row::offsetUnset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid;
8
9
use ArrayAccess;
10
11
/**
12
 * Class Row
13
 * @package Nnx\DataGrid
14
 */
15
class Row implements ArrayAccess
16
{
17
    /**
18
     * Данные строки
19
     * @var array|ArrayAccess
20
     */
21
    protected $data;
22
23
    /**
24
     * Опции строки
25
     * @var array
26
     */
27
    protected $options;
28
29
    /**
30
     * @param array|ArrayAccess $data
31
     * @param array $options
32
     */
33
    public function __construct($data, array $options = [])
34
    {
35
        $this->setData($data);
36
        $this->setOptions($options);
37
    }
38
39
    /**
40
     * @return array|ArrayAccess
41
     */
42
    public function getData()
43
    {
44
        return $this->data;
45
    }
46
47
    /**
48
     * @param array|ArrayAccess $data
49
     * @return $this
50
     */
51
    public function setData($data)
52
    {
53
        $this->data = $data;
54
        return $this;
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getOptions()
61
    {
62
        return $this->options;
63
    }
64
65
    /**
66
     * @param array $options
67
     * @return $this
68
     */
69
    public function setOptions($options)
70
    {
71
        $this->options = $options;
72
        return $this;
73
    }
74
75
    /**
76
     * @param string $name
77
     * @return mixed
78
     * @throws Exception\InvalidArgumentException
79
     * @throws Exception\RuntimeException
80
     */
81
    public function get($name)
82
    {
83
        return $this->offsetGet($name);
84
    }
85
86
    /**
87
     * (PHP 5 &gt;= 5.0.0)<br/>
88
     * Whether a offset exists
89
     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
90
     * @param mixed $offset <p>
91
     * An offset to check for.
92
     * </p>
93
     * @return boolean true on success or false on failure.
94
     * </p>
95
     * <p>
96
     * The return value will be casted to boolean if non-boolean was returned.
97
     */
98
    public function offsetExists($offset)
99
    {
100
        return array_key_exists($offset, $this->data);
101
    }
102
103
    /**
104
     * (PHP 5 &gt;= 5.0.0)<br/>
105
     * Offset to retrieve
106
     * @link http://php.net/manual/en/arrayaccess.offsetget.php
107
     * @param mixed $offset <p>
108
     * The offset to retrieve.
109
     * </p>
110
     * @return mixed Can return all value types.
111
     * @throws Exception\InvalidArgumentException
112
     * @throws Exception\RuntimeException
113
     */
114
    public function offsetGet($offset)
115
    {
116
        if (!$offset || !is_string($offset)) {
117
            throw new Exception\InvalidArgumentException('Некооректное имя столбца для получения из строки таблицы');
118
        }
119
        if (!array_key_exists($offset, $this->data)) {
120
            throw new Exception\RuntimeException(sprintf('Не найден столбец с именем %s в строке', $offset));
121
        }
122
        return $this->data[$offset];
123
    }
124
125
    /**
126
     * (PHP 5 &gt;= 5.0.0)<br/>
127
     * Offset to set
128
     * @link http://php.net/manual/en/arrayaccess.offsetset.php
129
     * @param mixed $offset <p>
130
     * The offset to assign the value to.
131
     * </p>
132
     * @param mixed $value <p>
133
     * The value to set.
134
     * </p>
135
     * @return void
136
     */
137
    public function offsetSet($offset, $value)
138
    {
139
        $this->data[$offset] = $value;
140
    }
141
142
    /**
143
     * (PHP 5 &gt;= 5.0.0)<br/>
144
     * Offset to unset
145
     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
146
     * @param mixed $offset <p>
147
     * The offset to unset.
148
     * </p>
149
     * @return void
150
     */
151
    public function offsetUnset($offset)
152
    {
153
        unset($this->data[$offset]);
154
    }
155
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
156