Skip to content

Commit

Permalink
Reduce some code complexity.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 4, 2012
1 parent e58c93c commit feda6e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
18 changes: 7 additions & 11 deletions lib/Cake/Error/ExceptionRenderer.php
Expand Up @@ -102,10 +102,7 @@ public function __construct(Exception $exception) {

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) {
Expand All @@ -119,13 +116,12 @@ public function __construct(Exception $exception) {
}
}

if (Configure::read('debug') == 0) {
if ($method == '_cakeError') {
$method = 'error400';
}
if ($code == 500) {
$method = 'error500';
}
$isDebug = (Configure::read('debug') == 0);

This comment has been minimized.

Copy link
@dereuromark

dereuromark Oct 4, 2012

Member

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

This comment has been minimized.

Copy link
@markstory

markstory Oct 4, 2012

Author Member

True, I'll update it.

if ($isDebug && $method == '_cakeError') {
$method = 'error400';
}
if ($isDebug && $code == 500) {
$method = 'error500';
}
$this->template = $template;
$this->method = $method;
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Routing/Route/CakeRoute.php
Expand Up @@ -154,7 +154,8 @@ protected function _writeRoute() {
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;
}
Expand All @@ -163,7 +164,7 @@ protected function _writeRoute() {
$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]);
}
Expand Down
26 changes: 13 additions & 13 deletions lib/Cake/View/Helper.php
Expand Up @@ -293,8 +293,9 @@ public function webroot($file) {
*/
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);
}
Expand Down Expand Up @@ -322,7 +323,6 @@ public function assetUrl($path, $options = array()) {
$path = $base . $path;
}
}

return $path;
}

Expand Down Expand Up @@ -460,21 +460,21 @@ protected function _parseAttributes($options, $exclude = null, $insertBefore = '
* @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);
}
$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 $attribute;
return sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
}

/**
Expand Down

0 comments on commit feda6e0

Please sign in to comment.