Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use an early return to remove a layer of nesting.

  • Loading branch information...
commit bc8ab57e0dad6f384d5fa918a233c2dae9c27fbd 1 parent 0342843
@markstory markstory authored
Showing with 30 additions and 29 deletions.
  1. +30 −29 src/View/Helper/SessionHelper.php
View
59 src/View/Helper/SessionHelper.php
@@ -141,40 +141,41 @@ public function error() {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::flash
*/
public function flash($key = 'flash', $attrs = array()) {
- $out = false;
- if (Session::check('Message.' . $key)) {
- $flash = Session::read('Message.' . $key);
- $message = $flash['message'];
- unset($flash['message']);
+ if (!Session::check('Message.' . $key)) {
+ return '';
+ }
- if (!empty($attrs)) {
- $flash = array_merge($flash, $attrs);
- }
+ $flash = Session::read('Message.' . $key);
+ $message = $flash['message'];
+ unset($flash['message']);
- if ($flash['element'] === 'default') {
- $class = 'message';
- if (!empty($flash['params']['class'])) {
- $class = $flash['params']['class'];
- }
- $out = $this->formatTemplate('flash', [
- 'class' => $class,
- 'key' => $key,
- 'message' => $message
- ]);
- } elseif (!$flash['element']) {
- $out = $message;
- } else {
- $options = array();
- if (isset($flash['params']['plugin'])) {
- $options['plugin'] = $flash['params']['plugin'];
- }
- $tmpVars = $flash['params'];
- $tmpVars['message'] = $message;
- $out = $this->_View->element($flash['element'], $tmpVars, $options);
+ if (!empty($attrs)) {
+ $flash = array_merge($flash, $attrs);
+ }
+
+ if ($flash['element'] === 'default') {
+ $class = 'message';
+ if (!empty($flash['params']['class'])) {
+ $class = $flash['params']['class'];
+ }
+ $out = $this->formatTemplate('flash', [
+ 'class' => $class,
+ 'key' => $key,
+ 'message' => $message
+ ]);
+ } elseif (!$flash['element']) {
+ $out = $message;
+ } else {
+ $options = array();
+ if (isset($flash['params']['plugin'])) {
+ $options['plugin'] = $flash['params']['plugin'];
}
- Session::delete('Message.' . $key);
+ $tmpVars = $flash['params'];
+ $tmpVars['message'] = $message;
+ $out = $this->_View->element($flash['element'], $tmpVars, $options);
}
+ Session::delete('Message.' . $key);
return $out;
}
Please sign in to comment.
Something went wrong with that request. Please try again.