Completed
Push — 4.0 ( 77c0c8...b0bc74 )
by David
03:23
created
src/Mouf/Database/TDBM/ResultIterator.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -30,234 +30,234 @@
 block discarded – undo
30 30
  */
31 31
 class ResultIterator implements Result, \ArrayAccess, \JsonSerializable
32 32
 {
33
-    /**
34
-     * @var Statement
35
-     */
36
-    protected $statement;
33
+	/**
34
+	 * @var Statement
35
+	 */
36
+	protected $statement;
37 37
 
38
-    protected $fetchStarted = false;
39
-    private $objectStorage;
40
-    private $className;
38
+	protected $fetchStarted = false;
39
+	private $objectStorage;
40
+	private $className;
41 41
 
42
-    private $tdbmService;
43
-    private $magicSql;
44
-    private $magicSqlCount;
45
-    private $parameters;
46
-    private $columnDescriptors;
47
-    private $magicQuery;
42
+	private $tdbmService;
43
+	private $magicSql;
44
+	private $magicSqlCount;
45
+	private $parameters;
46
+	private $columnDescriptors;
47
+	private $magicQuery;
48 48
 
49
-    /**
50
-     * @var InnerResultIterator
51
-     */
52
-    private $innerResultIterator;
49
+	/**
50
+	 * @var InnerResultIterator
51
+	 */
52
+	private $innerResultIterator;
53 53
 
54
-    /**
55
-     * The key of the current retrieved object.
56
-     *
57
-     * @var int
58
-     */
59
-    protected $key = -1;
54
+	/**
55
+	 * The key of the current retrieved object.
56
+	 *
57
+	 * @var int
58
+	 */
59
+	protected $key = -1;
60 60
 
61
-    protected $current = null;
61
+	protected $current = null;
62 62
 
63
-    private $databasePlatform;
63
+	private $databasePlatform;
64 64
 
65
-    private $totalCount;
65
+	private $totalCount;
66 66
 
67
-    private $mode;
67
+	private $mode;
68 68
 
69
-    public function __construct($magicSql, $magicSqlCount, array $parameters, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, $mode)
70
-    {
71
-        $this->magicSql = $magicSql;
72
-        $this->magicSqlCount = $magicSqlCount;
73
-        $this->objectStorage = $objectStorage;
74
-        $this->className = $className;
75
-        $this->tdbmService = $tdbmService;
76
-        $this->parameters = $parameters;
77
-        $this->columnDescriptors = $columnDescriptors;
78
-        $this->magicQuery = $magicQuery;
79
-        $this->databasePlatform = $this->tdbmService->getConnection()->getDatabasePlatform();
80
-        $this->mode = $mode;
81
-    }
69
+	public function __construct($magicSql, $magicSqlCount, array $parameters, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, $mode)
70
+	{
71
+		$this->magicSql = $magicSql;
72
+		$this->magicSqlCount = $magicSqlCount;
73
+		$this->objectStorage = $objectStorage;
74
+		$this->className = $className;
75
+		$this->tdbmService = $tdbmService;
76
+		$this->parameters = $parameters;
77
+		$this->columnDescriptors = $columnDescriptors;
78
+		$this->magicQuery = $magicQuery;
79
+		$this->databasePlatform = $this->tdbmService->getConnection()->getDatabasePlatform();
80
+		$this->mode = $mode;
81
+	}
82 82
 
83
-    protected function executeCountQuery()
84
-    {
85
-        $sql = $this->magicQuery->build($this->magicSqlCount, $this->parameters);
86
-        $this->totalCount = $this->tdbmService->getConnection()->fetchColumn($sql, $this->parameters);
87
-    }
83
+	protected function executeCountQuery()
84
+	{
85
+		$sql = $this->magicQuery->build($this->magicSqlCount, $this->parameters);
86
+		$this->totalCount = $this->tdbmService->getConnection()->fetchColumn($sql, $this->parameters);
87
+	}
88 88
 
89
-    /**
90
-     * Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings).
91
-     *
92
-     * @return int
93
-     */
94
-    public function count()
95
-    {
96
-        if ($this->totalCount === null) {
97
-            $this->executeCountQuery();
98
-        }
89
+	/**
90
+	 * Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings).
91
+	 *
92
+	 * @return int
93
+	 */
94
+	public function count()
95
+	{
96
+		if ($this->totalCount === null) {
97
+			$this->executeCountQuery();
98
+		}
99 99
 
100
-        return $this->totalCount;
101
-    }
100
+		return $this->totalCount;
101
+	}
102 102
 
103
-    /**
104
-     * Casts the result set to a PHP array.
105
-     *
106
-     * @return array
107
-     */
108
-    public function toArray()
109
-    {
110
-        return iterator_to_array($this->getIterator());
111
-    }
103
+	/**
104
+	 * Casts the result set to a PHP array.
105
+	 *
106
+	 * @return array
107
+	 */
108
+	public function toArray()
109
+	{
110
+		return iterator_to_array($this->getIterator());
111
+	}
112 112
 
113
-    /**
114
-     * Returns a new iterator mapping any call using the $callable function.
115
-     *
116
-     * @param callable $callable
117
-     *
118
-     * @return MapIterator
119
-     */
120
-    public function map(callable $callable)
121
-    {
122
-        return new MapIterator($this->getIterator(), $callable);
123
-    }
113
+	/**
114
+	 * Returns a new iterator mapping any call using the $callable function.
115
+	 *
116
+	 * @param callable $callable
117
+	 *
118
+	 * @return MapIterator
119
+	 */
120
+	public function map(callable $callable)
121
+	{
122
+		return new MapIterator($this->getIterator(), $callable);
123
+	}
124 124
 
125
-    /**
126
-     * Retrieve an external iterator.
127
-     *
128
-     * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
129
-     *
130
-     * @return InnerResultIterator An instance of an object implementing <b>Iterator</b> or
131
-     *                             <b>Traversable</b>
132
-     *
133
-     * @since 5.0.0
134
-     */
135
-    public function getIterator()
136
-    {
137
-        if ($this->innerResultIterator === null) {
138
-            if ($this->mode === TDBMService::MODE_CURSOR) {
139
-                $this->innerResultIterator = new InnerResultIterator($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery);
140
-            } else {
141
-                $this->innerResultIterator = new InnerResultArray($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery);
142
-            }
143
-        }
125
+	/**
126
+	 * Retrieve an external iterator.
127
+	 *
128
+	 * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
129
+	 *
130
+	 * @return InnerResultIterator An instance of an object implementing <b>Iterator</b> or
131
+	 *                             <b>Traversable</b>
132
+	 *
133
+	 * @since 5.0.0
134
+	 */
135
+	public function getIterator()
136
+	{
137
+		if ($this->innerResultIterator === null) {
138
+			if ($this->mode === TDBMService::MODE_CURSOR) {
139
+				$this->innerResultIterator = new InnerResultIterator($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery);
140
+			} else {
141
+				$this->innerResultIterator = new InnerResultArray($this->magicSql, $this->parameters, null, null, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery);
142
+			}
143
+		}
144 144
 
145
-        return $this->innerResultIterator;
146
-    }
145
+		return $this->innerResultIterator;
146
+	}
147 147
 
148
-    /**
149
-     * @param int $offset
150
-     *
151
-     * @return PageIterator
152
-     */
153
-    public function take($offset, $limit)
154
-    {
155
-        return new PageIterator($this, $this->magicSql, $this->parameters, $limit, $offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->mode);
156
-    }
148
+	/**
149
+	 * @param int $offset
150
+	 *
151
+	 * @return PageIterator
152
+	 */
153
+	public function take($offset, $limit)
154
+	{
155
+		return new PageIterator($this, $this->magicSql, $this->parameters, $limit, $offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->mode);
156
+	}
157 157
 
158
-    /**
159
-     * Whether a offset exists.
160
-     *
161
-     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
162
-     *
163
-     * @param mixed $offset <p>
164
-     *                      An offset to check for.
165
-     *                      </p>
166
-     *
167
-     * @return bool true on success or false on failure.
168
-     *              </p>
169
-     *              <p>
170
-     *              The return value will be casted to boolean if non-boolean was returned.
171
-     *
172
-     * @since 5.0.0
173
-     */
174
-    public function offsetExists($offset)
175
-    {
176
-        return $this->getIterator()->offsetExists($offset);
177
-    }
158
+	/**
159
+	 * Whether a offset exists.
160
+	 *
161
+	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
162
+	 *
163
+	 * @param mixed $offset <p>
164
+	 *                      An offset to check for.
165
+	 *                      </p>
166
+	 *
167
+	 * @return bool true on success or false on failure.
168
+	 *              </p>
169
+	 *              <p>
170
+	 *              The return value will be casted to boolean if non-boolean was returned.
171
+	 *
172
+	 * @since 5.0.0
173
+	 */
174
+	public function offsetExists($offset)
175
+	{
176
+		return $this->getIterator()->offsetExists($offset);
177
+	}
178 178
 
179
-    /**
180
-     * Offset to retrieve.
181
-     *
182
-     * @link http://php.net/manual/en/arrayaccess.offsetget.php
183
-     *
184
-     * @param mixed $offset <p>
185
-     *                      The offset to retrieve.
186
-     *                      </p>
187
-     *
188
-     * @return mixed Can return all value types.
189
-     *
190
-     * @since 5.0.0
191
-     */
192
-    public function offsetGet($offset)
193
-    {
194
-        return $this->getIterator()->offsetGet($offset);
195
-    }
179
+	/**
180
+	 * Offset to retrieve.
181
+	 *
182
+	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
183
+	 *
184
+	 * @param mixed $offset <p>
185
+	 *                      The offset to retrieve.
186
+	 *                      </p>
187
+	 *
188
+	 * @return mixed Can return all value types.
189
+	 *
190
+	 * @since 5.0.0
191
+	 */
192
+	public function offsetGet($offset)
193
+	{
194
+		return $this->getIterator()->offsetGet($offset);
195
+	}
196 196
 
197
-    /**
198
-     * Offset to set.
199
-     *
200
-     * @link http://php.net/manual/en/arrayaccess.offsetset.php
201
-     *
202
-     * @param mixed $offset <p>
203
-     *                      The offset to assign the value to.
204
-     *                      </p>
205
-     * @param mixed $value  <p>
206
-     *                      The value to set.
207
-     *                      </p>
208
-     *
209
-     * @since 5.0.0
210
-     */
211
-    public function offsetSet($offset, $value)
212
-    {
213
-        return $this->getIterator()->offsetSet($offset, $value);
214
-    }
197
+	/**
198
+	 * Offset to set.
199
+	 *
200
+	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
201
+	 *
202
+	 * @param mixed $offset <p>
203
+	 *                      The offset to assign the value to.
204
+	 *                      </p>
205
+	 * @param mixed $value  <p>
206
+	 *                      The value to set.
207
+	 *                      </p>
208
+	 *
209
+	 * @since 5.0.0
210
+	 */
211
+	public function offsetSet($offset, $value)
212
+	{
213
+		return $this->getIterator()->offsetSet($offset, $value);
214
+	}
215 215
 
216
-    /**
217
-     * Offset to unset.
218
-     *
219
-     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
220
-     *
221
-     * @param mixed $offset <p>
222
-     *                      The offset to unset.
223
-     *                      </p>
224
-     *
225
-     * @since 5.0.0
226
-     */
227
-    public function offsetUnset($offset)
228
-    {
229
-        return $this->getIterator()->offsetUnset($offset);
230
-    }
216
+	/**
217
+	 * Offset to unset.
218
+	 *
219
+	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
220
+	 *
221
+	 * @param mixed $offset <p>
222
+	 *                      The offset to unset.
223
+	 *                      </p>
224
+	 *
225
+	 * @since 5.0.0
226
+	 */
227
+	public function offsetUnset($offset)
228
+	{
229
+		return $this->getIterator()->offsetUnset($offset);
230
+	}
231 231
 
232
-    /**
233
-     * Specify data which should be serialized to JSON.
234
-     *
235
-     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
236
-     *
237
-     * @return mixed data which can be serialized by <b>json_encode</b>,
238
-     *               which is a value of any type other than a resource.
239
-     *
240
-     * @since 5.4.0
241
-     */
242
-    public function jsonSerialize()
243
-    {
244
-        return array_map(function (AbstractTDBMObject $item) {
245
-            return $item->jsonSerialize();
246
-        }, $this->toArray());
247
-    }
232
+	/**
233
+	 * Specify data which should be serialized to JSON.
234
+	 *
235
+	 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
236
+	 *
237
+	 * @return mixed data which can be serialized by <b>json_encode</b>,
238
+	 *               which is a value of any type other than a resource.
239
+	 *
240
+	 * @since 5.4.0
241
+	 */
242
+	public function jsonSerialize()
243
+	{
244
+		return array_map(function (AbstractTDBMObject $item) {
245
+			return $item->jsonSerialize();
246
+		}, $this->toArray());
247
+	}
248 248
 
249
-    /**
250
-     * Returns only one value (the first) of the result set.
251
-     * Returns null if no value exists.
252
-     *
253
-     * @return mixed|null
254
-     */
255
-    public function first()
256
-    {
257
-        $page = $this->take(0, 1);
258
-        foreach ($page as $bean) {
259
-            return $bean;
260
-        }
261
-        return null;
262
-    }
249
+	/**
250
+	 * Returns only one value (the first) of the result set.
251
+	 * Returns null if no value exists.
252
+	 *
253
+	 * @return mixed|null
254
+	 */
255
+	public function first()
256
+	{
257
+		$page = $this->take(0, 1);
258
+		foreach ($page as $bean) {
259
+			return $bean;
260
+		}
261
+		return null;
262
+	}
263 263
 }
Please login to merge, or discard this patch.