Completed
Pull Request — 3.4 (#46)
by David
06:17
created

TDBMObject::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Mouf\Database\TDBM;
3
4
/*
5
 Copyright (C) 2006-2009 David Négrier - THE CODING MACHINE
6
7
 This program is free software; you can redistribute it and/or modify
8
 it under the terms of the GNU General Public License as published by
9
 the Free Software Foundation; either version 2 of the License, or
10
 (at your option) any later version.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 GNU General Public License for more details.
16
17
 You should have received a copy of the GNU General Public License
18
 along with this program; if not, write to the Free Software
19
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
21
use Doctrine\DBAL\Driver\Connection;
22
23
24
/**
25
 * Instances of this class represent an object that is bound to a row in a database table.
26
 * You access access the rows using there name, as a property of an object, or as a table.
27
 * For instance:
28
 *    <code>$tdbmObject->myrow</code>
29
 * or
30
 *    <code>$tdbmObject['myrow']</code>
31
 * are both valid.
32
 *
33
 * @author David Negrier
34
 */
35
class TDBMObject extends AbstractTDBMObject implements \ArrayAccess, \Iterator
36
{
37
38
    public function __get($var)
39
    {
40
        return $this->get($var);
41
    }
42
43
    /**
44
     * Returns true if a column is set, false otherwise.
45
     *
46
     * @param string $var
47
     * @return boolean
48
     */
49
    public function __isset($var)
50
    {
51
        return $this->has($var);
52
    }
53
54
    public function __set($var, $value)
55
    {
56
        $this->set($var, $value);
57
    }
58
59
    /**
60
     * Implements array behaviour for our object.
61
     *
62
     * @param string $offset
63
     * @param string $value
64
     */
65
    public function offsetSet($offset, $value)
66
    {
67
        $this->__set($offset, $value);
68
    }
69
70
    /**
71
     * Implements array behaviour for our object.
72
     *
73
     * @param string $offset
74
     * @return bool
75
     */
76
    public function offsetExists($offset)
77
    {
78
        $this->_dbLoadIfNotLoaded();
0 ignored issues
show
Bug introduced by
The method _dbLoadIfNotLoaded() does not seem to exist on object<Mouf\Database\TDBM\TDBMObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
        return isset($this->dbRow[$offset]);
0 ignored issues
show
Bug introduced by
The property dbRow does not seem to exist. Did you mean dbRows?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
80
    }
81
82
    /**
83
     * Implements array behaviour for our object.
84
     *
85
     * @param string $offset
86
     */
87
    public function offsetUnset($offset)
88
    {
89
        $this->__set($offset, null);
90
    }
91
92
    /**
93
     * Implements array behaviour for our object.
94
     *
95
     * @param string $offset
96
     * @return mixed|null
97
     */
98
    public function offsetGet($offset)
99
    {
100
        return $this->__get($offset);
101
    }
102
103
    private $_validIterator = false;
104
105
    /**
106
     * Implements iterator behaviour for our object (so we can each column).
107
     */
108
    public function rewind()
109
    {
110
        $this->_dbLoadIfNotLoaded();
0 ignored issues
show
Bug introduced by
The method _dbLoadIfNotLoaded() does not seem to exist on object<Mouf\Database\TDBM\TDBMObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
        if (count($this->dbRow) > 0) {
0 ignored issues
show
Bug introduced by
The property dbRow does not seem to exist. Did you mean dbRows?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
112
            $this->_validIterator = true;
113
        } else {
114
            $this->_validIterator = false;
115
        }
116
        reset($this->dbRow);
0 ignored issues
show
Bug introduced by
The property dbRow does not seem to exist. Did you mean dbRows?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
117
    }
118
119
    /**
120
     * Implements iterator behaviour for our object (so we can each column).
121
     */
122
    public function next()
123
    {
124
        $val = next($this->dbRow);
0 ignored issues
show
Bug introduced by
The property dbRow does not seem to exist. Did you mean dbRows?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
125
        $this->_validIterator = !($val === false);
126
    }
127
128
    /**
129
     * Implements iterator behaviour for our object (so we can each column).
130
     */
131
    public function key()
132
    {
133
        return key($this->dbRow);
0 ignored issues
show
Bug introduced by
The property dbRow does not seem to exist. Did you mean dbRows?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
134
    }
135
136
    /**
137
     * Implements iterator behaviour for our object (so we can each column).
138
     */
139
    public function current()
140
    {
141
        return current($this->dbRow);
0 ignored issues
show
Bug introduced by
The property dbRow does not seem to exist. Did you mean dbRows?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
142
    }
143
144
    /**
145
     * Implements iterator behaviour for our object (so we can each column).
146
     */
147
    public function valid()
148
    {
149
        return $this->_validIterator;
150
    }
151
}