Skip to content
This repository
Browse code

reduce 5-level if cases to 2 levels

  • Loading branch information...
commit 5e0e85073337620fbd5e9c3ca7d9aefda491e709 1 parent 1ff6375
Mark authored August 08, 2012

Showing 1 changed file with 40 additions and 36 deletions. Show diff stats Hide diff stats

  1. 76  lib/Cake/Model/CakeSchema.php
76  lib/Cake/Model/CakeSchema.php
@@ -254,44 +254,48 @@ public function read($options = array()) {
254 254
 					continue;
255 255
 				}
256 256
 
257  
-				$db = $Object->getDataSource();
258  
-				if (is_object($Object) && $Object->useTable !== false) {
259  
-					$fulltable = $table = $db->fullTableName($Object, false, false);
260  
-					if ($prefix && strpos($table, $prefix) !== 0) {
  257
+				$fulltable = $table = $db->fullTableName($Object, false, false);
  258
+				if ($prefix && strpos($table, $prefix) !== 0) {
  259
+					continue;
  260
+				}
  261
+				if (!is_object($Object) || $Object->useTable === false) {
  262
+					continue;
  263
+				}
  264
+				if (!in_array($fulltable, $currentTables)) {
  265
+					continue;
  266
+				}
  267
+
  268
+				$table = $this->_noPrefixTable($prefix, $table);
  269
+
  270
+				$key = array_search($fulltable, $currentTables);
  271
+				if (empty($tables[$table])) {
  272
+					$tables[$table] = $this->_columns($Object);
  273
+					$tables[$table]['indexes'] = $db->index($Object);
  274
+					$tables[$table]['tableParameters'] = $db->readTableParameters($fulltable);
  275
+					unset($currentTables[$key]);
  276
+				}
  277
+				if (empty($Object->hasAndBelongsToMany)) {
  278
+					continue;
  279
+				}
  280
+				foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) {
  281
+					if (isset($assocData['with'])) {
  282
+						$class = $assocData['with'];
  283
+					}
  284
+					if (!is_object($Object->$class)) {
261 285
 						continue;
262 286
 					}
263  
-					$table = $this->_noPrefixTable($prefix, $table);
264  
-
265  
-					if (in_array($fulltable, $currentTables)) {
266  
-						$key = array_search($fulltable, $currentTables);
267  
-						if (empty($tables[$table])) {
268  
-							$tables[$table] = $this->_columns($Object);
269  
-							$tables[$table]['indexes'] = $db->index($Object);
270  
-							$tables[$table]['tableParameters'] = $db->readTableParameters($fulltable);
271  
-							unset($currentTables[$key]);
272  
-						}
273  
-						if (!empty($Object->hasAndBelongsToMany)) {
274  
-							foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) {
275  
-								if (isset($assocData['with'])) {
276  
-									$class = $assocData['with'];
277  
-								}
278  
-								if (is_object($Object->$class)) {
279  
-									$withTable = $db->fullTableName($Object->$class, false, false);
280  
-									if ($prefix && strpos($withTable, $prefix) !== 0) {
281  
-										continue;
282  
-									}
283  
-									if (in_array($withTable, $currentTables)) {
284  
-										$key = array_search($withTable, $currentTables);
285  
-										$noPrefixWith = $this->_noPrefixTable($prefix, $withTable);
286  
-
287  
-										$tables[$noPrefixWith] = $this->_columns($Object->$class);
288  
-										$tables[$noPrefixWith]['indexes'] = $db->index($Object->$class);
289  
-										$tables[$noPrefixWith]['tableParameters'] = $db->readTableParameters($withTable);
290  
-										unset($currentTables[$key]);
291  
-									}
292  
-								}
293  
-							}
294  
-						}
  287
+					$withTable = $db->fullTableName($Object->$class, false, false);
  288
+					if ($prefix && strpos($withTable, $prefix) !== 0) {
  289
+						continue;
  290
+					}
  291
+					if (in_array($withTable, $currentTables)) {
  292
+						$key = array_search($withTable, $currentTables);
  293
+						$noPrefixWith = $this->_noPrefixTable($prefix, $withTable);
  294
+
  295
+						$tables[$noPrefixWith] = $this->_columns($Object->$class);
  296
+						$tables[$noPrefixWith]['indexes'] = $db->index($Object->$class);
  297
+						$tables[$noPrefixWith]['tableParameters'] = $db->readTableParameters($withTable);
  298
+						unset($currentTables[$key]);
295 299
 					}
296 300
 				}
297 301
 			}

0 notes on commit 5e0e850

Please sign in to comment.
Something went wrong with that request. Please try again.