Skip to content
This repository
Browse code

Reduce some code complexity.

  • Loading branch information...
commit feda6e06a0f4041427a1d924788a2712cc0e074b 1 parent e58c93c
Mark Story authored October 03, 2012
18  lib/Cake/Error/ExceptionRenderer.php
@@ -102,10 +102,7 @@ public function __construct(Exception $exception) {
102 102
 
103 103
 		if ($exception instanceof CakeException && !$methodExists) {
104 104
 			$method = '_cakeError';
105  
-			if (empty($template)) {
106  
-				$template = 'error500';
107  
-			}
108  
-			if ($template == 'internalError') {
  105
+			if (empty($template) || $template == 'internalError') {
109 106
 				$template = 'error500';
110 107
 			}
111 108
 		} elseif ($exception instanceof PDOException) {
@@ -119,13 +116,12 @@ public function __construct(Exception $exception) {
119 116
 			}
120 117
 		}
121 118
 
122  
-		if (Configure::read('debug') == 0) {
123  
-			if ($method == '_cakeError') {
124  
-				$method = 'error400';
125  
-			}
126  
-			if ($code == 500) {
127  
-				$method = 'error500';
128  
-			}
  119
+		$isDebug = (Configure::read('debug') == 0);
  120
+		if ($isDebug && $method == '_cakeError') {
  121
+			$method = 'error400';
  122
+		}
  123
+		if ($isDebug && $code == 500) {
  124
+			$method = 'error500';
129 125
 		}
130 126
 		$this->template = $template;
131 127
 		$this->method = $method;
5  lib/Cake/Routing/Route/CakeRoute.php
@@ -154,7 +154,8 @@ protected function _writeRoute() {
154 154
 		if (preg_match('#\/\*\*$#', $route)) {
155 155
 			$parsed = preg_replace('#/\\\\\*\\\\\*$#', '(?:/(?P<_trailing_>.*))?', $parsed);
156 156
 			$this->_greedy = true;
157  
-		} elseif (preg_match('#\/\*$#', $route)) {
  157
+		}
  158
+		if (preg_match('#\/\*$#', $route)) {
158 159
 			$parsed = preg_replace('#/\\\\\*$#', '(?:/(?P<_args_>.*))?', $parsed);
159 160
 			$this->_greedy = true;
160 161
 		}
@@ -163,7 +164,7 @@ protected function _writeRoute() {
163 164
 		$this->_compiledRoute = '#^' . $parsed . '[/]*$#';
164 165
 		$this->keys = $names;
165 166
 
166  
-		//remove defaults that are also keys. They can cause match failures
  167
+		// Remove defaults that are also keys. They can cause match failures
167 168
 		foreach ($this->keys as $key) {
168 169
 			unset($this->defaults[$key]);
169 170
 		}
26  lib/Cake/View/Helper.php
@@ -293,8 +293,9 @@ public function webroot($file) {
293 293
  */
294 294
 	public function assetUrl($path, $options = array()) {
295 295
 		if (is_array($path)) {
296  
-			$path = $this->url($path, !empty($options['fullBase']));
297  
-		} elseif (strpos($path, '://') === false) {
  296
+			return $this->url($path, !empty($options['fullBase']));
  297
+		}
  298
+		if (strpos($path, '://') === false) {
298 299
 			if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
299 300
 				list($plugin, $path) = $this->_View->pluginSplit($path, false);
300 301
 			}
@@ -322,7 +323,6 @@ public function assetUrl($path, $options = array()) {
322 323
 				$path = $base . $path;
323 324
 			}
324 325
 		}
325  
-
326 326
 		return $path;
327 327
 	}
328 328
 
@@ -460,21 +460,21 @@ protected function _parseAttributes($options, $exclude = null, $insertBefore = '
460 460
  * @deprecated This method will be moved to HtmlHelper in 3.0
461 461
  */
462 462
 	protected function _formatAttribute($key, $value, $escape = true) {
463  
-		$attribute = '';
464 463
 		if (is_array($value)) {
465 464
 			$value = implode(' ' , $value);
466 465
 		}
467  
-
468 466
 		if (is_numeric($key)) {
469  
-			$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
470  
-		} elseif (in_array($key, $this->_minimizedAttributes)) {
471  
-			if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
472  
-				$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
473  
-			}
474  
-		} else {
475  
-			$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
  467
+			return sprintf($this->_minimizedAttributeFormat, $value, $value);
  468
+		}
  469
+		$truthy = array(1, '1', true, 'true', $key);
  470
+		$isMinimized = in_array($key, $this->_minimizedAttributes);
  471
+		if ($isMinimized && in_array($value, $truthy, true)) {
  472
+			return sprintf($this->_minimizedAttributeFormat, $key, $key);
  473
+		}
  474
+		if ($isMinimized) {
  475
+			return '';
476 476
 		}
477  
-		return $attribute;
  477
+		return sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
478 478
 	}
479 479
 
480 480
 /**

0 notes on commit feda6e0

Mark

better $isDebug = !Configure::read('debug') ; - but isnt the variable wrong now? it should probably be $isNotDebug = !Configure::read('debug') ; - or the positive one and if (!$isDebug) checks

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