Skip to content

Commit 62e68d0

Browse files
committed
Simplify constructor logic.
Chaining through multiple objects makes mocking and testing harder. Moving method calls out of the constructor makes the ResultSet simpler to work with. This will be more important as serialize features are implemented.
1 parent f72d2b2 commit 62e68d0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

lib/Cake/ORM/ResultSet.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ class ResultSet implements Iterator {
7070
*/
7171
protected $_defaultTable;
7272

73-
/**
74-
* Default table alias
75-
*
76-
* @var string
77-
*/
78-
protected $_defaultAlias;
79-
8073
/**
8174
* List of associations that should be eager loaded
8275
*
@@ -103,7 +96,6 @@ public function __construct($query, $statement) {
10396
$this->_query = $query;
10497
$this->_statement = $statement;
10598
$this->_defaultTable = $this->_query->repository();
106-
$this->_defaultAlias = $this->_defaultTable->alias();
10799
$this->_calculateAssociationMap();
108100
}
109101

@@ -207,9 +199,10 @@ protected function _fetchResult() {
207199
* @return array
208200
*/
209201
protected function _groupResult() {
202+
$defaultAlias = $this->_defaultTable->alias();
210203
$results = [];
211204
foreach ($this->_current as $key => $value) {
212-
$table = $this->_defaultAlias;
205+
$table = $defaultAlias;
213206
$field = $key;
214207

215208
if (empty($this->_map[$key])) {
@@ -226,9 +219,9 @@ protected function _groupResult() {
226219
$results[$table][$field] = $value;
227220
}
228221

229-
$results[$this->_defaultAlias] = $this->_castValues(
222+
$results[$defaultAlias] = $this->_castValues(
230223
$this->_defaultTable,
231-
$results[$this->_defaultAlias]
224+
$results[$defaultAlias]
232225
);
233226

234227
foreach (array_reverse($this->_associationMap) as $alias => $assoc) {
@@ -239,7 +232,7 @@ protected function _groupResult() {
239232
$results = $assoc->transformRow($results);
240233
}
241234

242-
return $results[$this->_defaultAlias];
235+
return $results[$defaultAlias];
243236
}
244237

245238
/**
@@ -269,4 +262,5 @@ protected function _castValues($table, $values) {
269262

270263
return $values;
271264
}
265+
272266
}

0 commit comments

Comments
 (0)