Skip to content

Commit fea72f8

Browse files
committed
Renaming reformatting function to better express its purpose, also
making it a real method instead of a closure as there was no need for it to be one
1 parent f909cae commit fea72f8

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/Cake/ORM/Query.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,28 +245,35 @@ public function contain($associations = null, $override = false) {
245245
return $this;
246246
}
247247

248-
$normalizer = function($associations) use (&$normalizer) {
249-
$result = [];
250-
foreach ((array)$associations as $table => $options) {
251-
if (is_int($table)) {
252-
$table = $options;
253-
$options = [];
254-
} elseif (is_array($options) && !isset($this->_containOptions[$table])) {
255-
$options = $normalizer($options);
256-
}
257-
$result[$table] = $options;
258-
}
259-
return $result;
260-
};
261-
262248
$old = $this->_containments->getArrayCopy();
263-
$associations = array_merge($old, $normalizer($associations));
249+
$associations = array_merge($old, $this->_reformatContain($associations));
264250
$this->_containments->exchangeArray($associations);
265251
$this->_normalizedContainments = null;
266252
$this->_dirty = true;
267253
return $this;
268254
}
269255

256+
/**
257+
* Formats the containments array so that associations are always set as keys
258+
* in the array.
259+
*
260+
* @param array $associations user provided containments array
261+
* @return array
262+
*/
263+
protected function _reformatContain($associations) {
264+
$result = [];
265+
foreach ((array)$associations as $table => $options) {
266+
if (is_int($table)) {
267+
$table = $options;
268+
$options = [];
269+
} elseif (is_array($options) && !isset($this->_containOptions[$table])) {
270+
$options = $this->_reformatContain($options);
271+
}
272+
$result[$table] = $options;
273+
}
274+
return $result;
275+
}
276+
270277
/**
271278
* Returns the fully normalized array of associations that should be eagerly
272279
* loaded. The normalized array will restructure the original one by sorting
@@ -275,7 +282,6 @@ public function contain($associations = null, $override = false) {
275282
* Additionally it will set an 'instance' key per association containing the
276283
* association instance from the corresponding source table
277284
*
278-
*
279285
* @return array
280286
*/
281287
public function normalizedContainments() {

0 commit comments

Comments
 (0)