Skip to content
This repository
Browse code

removing nested if statement

  • Loading branch information...
commit 0ada30f3bcd0c83f50264775381fa030abd5f64b 1 parent b99066d
Carl Sutton authored December 05, 2012

Showing 1 changed file with 23 additions and 21 deletions. Show diff stats Hide diff stats

  1. 44  lib/Cake/Model/Model.php
44  lib/Cake/Model/Model.php
@@ -2438,31 +2438,33 @@ protected function _deleteDependent($id, $cascade) {
2438 2438
 		}
2439 2439
 
2440 2440
 		foreach (array_merge($this->hasMany, $this->hasOne) as $assoc => $data) {
2441  
-			if ($data['dependent'] === true) {
2442  
-				$model = $this->{$assoc};
  2441
+			if ($data['dependent'] !== true) {
  2442
+				continue;
  2443
+			}
2443 2444
 
2444  
-				if ($data['foreignKey'] === false && $data['conditions'] && in_array($this->name, $model->getAssociated('belongsTo'))) {
2445  
-					$model->recursive = 0;
2446  
-					$conditions = array($this->escapeField(null, $this->name) => $id);
2447  
-				} else {
2448  
-					$model->recursive = -1;
2449  
-					$conditions = array($model->escapeField($data['foreignKey']) => $id);
2450  
-					if ($data['conditions']) {
2451  
-						$conditions = array_merge((array)$data['conditions'], $conditions);
2452  
-					}
  2445
+			$model = $this->{$assoc};
  2446
+
  2447
+			if ($data['foreignKey'] === false && $data['conditions'] && in_array($this->name, $model->getAssociated('belongsTo'))) {
  2448
+				$model->recursive = 0;
  2449
+				$conditions = array($this->escapeField(null, $this->name) => $id);
  2450
+			} else {
  2451
+				$model->recursive = -1;
  2452
+				$conditions = array($model->escapeField($data['foreignKey']) => $id);
  2453
+				if ($data['conditions']) {
  2454
+					$conditions = array_merge((array)$data['conditions'], $conditions);
2453 2455
 				}
  2456
+			}
2454 2457
 
2455  
-				if (isset($data['exclusive']) && $data['exclusive']) {
2456  
-					$model->deleteAll($conditions);
2457  
-				} else {
2458  
-					$records = $model->find('all', array(
2459  
-						'conditions' => $conditions, 'fields' => $model->primaryKey
2460  
-					));
  2458
+			if (isset($data['exclusive']) && $data['exclusive']) {
  2459
+				$model->deleteAll($conditions);
  2460
+			} else {
  2461
+				$records = $model->find('all', array(
  2462
+					'conditions' => $conditions, 'fields' => $model->primaryKey
  2463
+				));
2461 2464
 
2462  
-					if (!empty($records)) {
2463  
-						foreach ($records as $record) {
2464  
-							$model->delete($record[$model->alias][$model->primaryKey]);
2465  
-						}
  2465
+				if (!empty($records)) {
  2466
+					foreach ($records as $record) {
  2467
+						$model->delete($record[$model->alias][$model->primaryKey]);
2466 2468
 					}
2467 2469
 				}
2468 2470
 			}

0 notes on commit 0ada30f

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