Reduce some code complexity.

This commit is contained in:
mark_story 2012-10-03 22:59:35 -04:00
parent e58c93c39d
commit feda6e06a0
3 changed files with 23 additions and 26 deletions

View file

@ -102,10 +102,7 @@ class ExceptionRenderer {
if ($exception instanceof CakeException && !$methodExists) {
$method = '_cakeError';
if (empty($template)) {
$template = 'error500';
}
if ($template == 'internalError') {
if (empty($template) || $template == 'internalError') {
$template = 'error500';
}
} elseif ($exception instanceof PDOException) {
@ -119,13 +116,12 @@ class ExceptionRenderer {
}
}
if (Configure::read('debug') == 0) {
if ($method == '_cakeError') {
$method = 'error400';
}
if ($code == 500) {
$method = 'error500';
}
$isDebug = (Configure::read('debug') == 0);
if ($isDebug && $method == '_cakeError') {
$method = 'error400';
}
if ($isDebug && $code == 500) {
$method = 'error500';
}
$this->template = $template;
$this->method = $method;

View file

@ -154,7 +154,8 @@ class CakeRoute {
if (preg_match('#\/\*\*$#', $route)) {
$parsed = preg_replace('#/\\\\\*\\\\\*$#', '(?:/(?P<_trailing_>.*))?', $parsed);
$this->_greedy = true;
} elseif (preg_match('#\/\*$#', $route)) {
}
if (preg_match('#\/\*$#', $route)) {
$parsed = preg_replace('#/\\\\\*$#', '(?:/(?P<_args_>.*))?', $parsed);
$this->_greedy = true;
}
@ -163,7 +164,7 @@ class CakeRoute {
$this->_compiledRoute = '#^' . $parsed . '[/]*$#';
$this->keys = $names;
//remove defaults that are also keys. They can cause match failures
// Remove defaults that are also keys. They can cause match failures
foreach ($this->keys as $key) {
unset($this->defaults[$key]);
}

View file

@ -293,8 +293,9 @@ class Helper extends Object {
*/
public function assetUrl($path, $options = array()) {
if (is_array($path)) {
$path = $this->url($path, !empty($options['fullBase']));
} elseif (strpos($path, '://') === false) {
return $this->url($path, !empty($options['fullBase']));
}
if (strpos($path, '://') === false) {
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
list($plugin, $path) = $this->_View->pluginSplit($path, false);
}
@ -322,7 +323,6 @@ class Helper extends Object {
$path = $base . $path;
}
}
return $path;
}
@ -460,21 +460,21 @@ class Helper extends Object {
* @deprecated This method will be moved to HtmlHelper in 3.0
*/
protected function _formatAttribute($key, $value, $escape = true) {
$attribute = '';
if (is_array($value)) {
$value = implode(' ' , $value);
}
if (is_numeric($key)) {
$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
} elseif (in_array($key, $this->_minimizedAttributes)) {
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
}
} else {
$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
return sprintf($this->_minimizedAttributeFormat, $value, $value);
}
return $attribute;
$truthy = array(1, '1', true, 'true', $key);
$isMinimized = in_array($key, $this->_minimizedAttributes);
if ($isMinimized && in_array($value, $truthy, true)) {
return sprintf($this->_minimizedAttributeFormat, $key, $key);
}
if ($isMinimized) {
return '';
}
return sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
}
/**