From acccdcde1f8818378c12459139e9cda6b46c705d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Mar 2012 17:10:12 -0500 Subject: [PATCH] Fix coding standard issues in View/ --- lib/Cake/View/Helper.php | 17 +-- lib/Cake/View/Helper/CacheHelper.php | 1 + lib/Cake/View/Helper/FormHelper.php | 111 +++++++++--------- lib/Cake/View/Helper/HtmlHelper.php | 6 +- lib/Cake/View/Helper/JqueryEngineHelper.php | 8 +- lib/Cake/View/Helper/JsBaseEngineHelper.php | 15 +-- lib/Cake/View/Helper/JsHelper.php | 1 + lib/Cake/View/Helper/MootoolsEngineHelper.php | 16 +-- lib/Cake/View/Helper/NumberHelper.php | 9 +- lib/Cake/View/Helper/PaginatorHelper.php | 12 +- .../View/Helper/PrototypeEngineHelper.php | 8 +- lib/Cake/View/Helper/RssHelper.php | 3 +- lib/Cake/View/Helper/SessionHelper.php | 1 + lib/Cake/View/Helper/TextHelper.php | 1 + lib/Cake/View/Helper/TimeHelper.php | 1 + lib/Cake/View/HelperCollection.php | 1 + lib/Cake/View/MediaView.php | 11 +- lib/Cake/View/ScaffoldView.php | 1 + lib/Cake/View/ViewBlock.php | 1 + 19 files changed, 99 insertions(+), 125 deletions(-) diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index c2b04e0468c..ea092da5a04 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -1,11 +1,5 @@ theme . DS . $file)) { + if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->theme . DS . $file)) { $webPath = "{$this->request->webroot}theme/" . $theme . $asset[0]; } else { $themePath = App::themePath($this->theme); - $path = $themePath . 'webroot' . DS . $file; + $path = $themePath . 'webroot' . DS . $file; if (file_exists($path)) { $webPath = "{$this->request->webroot}theme/" . $theme . $asset[0]; } @@ -414,13 +407,13 @@ public function clean($output) { */ protected function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { if (!is_string($options)) { - $options = (array) $options + array('escape' => true); + $options = (array)$options + array('escape' => true); if (!is_array($exclude)) { $exclude = array(); } - $exclude = array('escape' => true) + array_flip($exclude); + $exclude = array('escape' => true) + array_flip($exclude); $escape = $options['escape']; $attributes = array(); @@ -532,7 +525,6 @@ public function setEntity($entity, $setScope = false) { } } $this->_entityPath = $entity; - return; } /** @@ -899,4 +891,5 @@ protected function _clean() { } while ($oldstring != $this->_cleaned); $this->_cleaned = str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $this->_cleaned); } + } diff --git a/lib/Cake/View/Helper/CacheHelper.php b/lib/Cake/View/Helper/CacheHelper.php index b87b8c6808a..61dd457e5a2 100644 --- a/lib/Cake/View/Helper/CacheHelper.php +++ b/lib/Cake/View/Helper/CacheHelper.php @@ -317,4 +317,5 @@ protected function _writeFile($content, $timestamp, $useCallbacks = false) { $file .= $content; return cache('views' . DS . $cache, $file, $timestamp); } + } diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 245c2d97423..c9bf9d63aa2 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1,11 +1,5 @@ _models[$model] = $object; - if (!$object) {; + if (!$object) { return null; } - $this->fieldset[$model] = array('fields' => null, 'key' => $object->primaryKey, 'validates' => null); + $this->fieldset[$model] = array('fields' => null, 'key' => $object->primaryKey, 'validates' => null); return $object; } @@ -183,58 +177,58 @@ protected function _getModel($model) { * @return mixed information extracted for the special key and field in a model */ protected function _introspectModel($model, $key, $field = null) { - $object = $this->_getModel($model); - if (!$object) { - return; - } + $object = $this->_getModel($model); + if (!$object) { + return; + } - if ($key === 'key') { - return $this->fieldset[$model]['key'] = $object->primaryKey; - } + if ($key === 'key') { + return $this->fieldset[$model]['key'] = $object->primaryKey; + } - if ($key === 'fields') { - if (!isset($this->fieldset[$model]['fields'])) { - $fields = $this->fieldset[$model]['fields'] = $object->schema(); - foreach ($object->hasAndBelongsToMany as $alias => $assocData) { - $this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple'); - } - } - if (empty($field)) { - return $this->fieldset[$model]['fields']; - } elseif (isset($this->fieldset[$model]['fields'][$field])) { - return $this->fieldset[$model]['fields'][$field]; - } else { - return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null; + if ($key === 'fields') { + if (!isset($this->fieldset[$model]['fields'])) { + $fields = $this->fieldset[$model]['fields'] = $object->schema(); + foreach ($object->hasAndBelongsToMany as $alias => $assocData) { + $this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple'); } } - - if ($key === 'errors' && !isset($this->validationErrors[$model])) { - $this->validationErrors[$model] =& $object->validationErrors; - return $this->validationErrors[$model]; - } elseif ($key === 'errors' && isset($this->validationErrors[$model])) { - return $this->validationErrors[$model]; + if (empty($field)) { + return $this->fieldset[$model]['fields']; + } elseif (isset($this->fieldset[$model]['fields'][$field])) { + return $this->fieldset[$model]['fields'][$field]; + } else { + return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null; } + } - if ($key === 'validates' && !isset($this->fieldset[$model]['validates'])) { - $validates = array(); - if (!empty($object->validate)) { - foreach ($object->validate as $validateField => $validateProperties) { - if ($this->_isRequiredField($validateProperties)) { - $validates[$validateField] = true; - } + if ($key === 'errors' && !isset($this->validationErrors[$model])) { + $this->validationErrors[$model] =& $object->validationErrors; + return $this->validationErrors[$model]; + } elseif ($key === 'errors' && isset($this->validationErrors[$model])) { + return $this->validationErrors[$model]; + } + + if ($key === 'validates' && !isset($this->fieldset[$model]['validates'])) { + $validates = array(); + if (!empty($object->validate)) { + foreach ($object->validate as $validateField => $validateProperties) { + if ($this->_isRequiredField($validateProperties)) { + $validates[$validateField] = true; } } - $this->fieldset[$model]['validates'] = $validates; } + $this->fieldset[$model]['validates'] = $validates; + } - if ($key === 'validates') { - if (empty($field)) { - return $this->fieldset[$model]['validates']; - } else { - return isset($this->fieldset[$model]['validates'][$field]) ? - $this->fieldset[$model]['validates'] : null; - } + if ($key === 'validates') { + if (empty($field)) { + return $this->fieldset[$model]['validates']; + } else { + return isset($this->fieldset[$model]['validates'][$field]) ? + $this->fieldset[$model]['validates'] : null; } + } } /** @@ -675,9 +669,9 @@ public function error($field, $text = null, $options = array()) { $tmp = array(); foreach ($error as &$e) { if (isset($text[$e])) { - $tmp []= $text[$e]; + $tmp[] = $text[$e]; } else { - $tmp []= $e; + $tmp[] = $e; } } $text = $tmp; @@ -702,16 +696,16 @@ public function error($field, $text = null, $options = array()) { $listParams = array(); if (isset($options['listOptions'])) { if (is_string($options['listOptions'])) { - $listParams []= $options['listOptions']; + $listParams[] = $options['listOptions']; } else { if (isset($options['listOptions']['itemOptions'])) { - $listParams []= $options['listOptions']['itemOptions']; + $listParams[] = $options['listOptions']['itemOptions']; unset($options['listOptions']['itemOptions']); } else { - $listParams []= array(); + $listParams[] = array(); } if (isset($options['listOptions']['tag'])) { - $listParams []= $options['listOptions']['tag']; + $listParams[] = $options['listOptions']['tag']; unset($options['listOptions']['tag']); } array_unshift($listParams, $options['listOptions']); @@ -1028,7 +1022,7 @@ public function input($fieldName, $options = array()) { $options['maxlength'] = $fieldDef['length']; } if ($autoLength && $fieldDef['type'] == 'float') { - $options['maxlength'] = array_sum(explode(',', $fieldDef['length']))+1; + $options['maxlength'] = array_sum(explode(',', $fieldDef['length'])) + 1; } $divOptions = array(); @@ -1999,7 +1993,7 @@ public function month($fieldName, $attributes = array()) { $attributes['value'] = null; } $defaults = array('monthNames' => true); - $attributes = array_merge($defaults, (array) $attributes); + $attributes = array_merge($defaults, (array)$attributes); $monthNames = $attributes['monthNames']; unset($attributes['monthNames']); @@ -2229,7 +2223,7 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a 'minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true ); - $attributes = array_merge($defaults, (array) $attributes); + $attributes = array_merge($defaults, (array)$attributes); if (isset($attributes['minuteInterval'])) { $attributes['interval'] = $attributes['minuteInterval']; unset($attributes['minuteInterval']); @@ -2592,4 +2586,5 @@ protected function _initInputField($field, $options = array()) { $this->_secure($secure, $fieldName); return $result; } + } diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 7f66d9e0110..e464c68aeee 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -431,7 +431,7 @@ public function css($path, $rel = null, $options = array()) { foreach ($path as $i) { $out .= "\n\t" . $this->css($i, $rel, $options); } - if (empty($options['block'])) { + if (empty($options['block'])) { return $out . "\n"; } return; @@ -523,7 +523,7 @@ public function script($url, $options = array()) { foreach ($url as $i) { $out .= "\n\t" . $this->script($i, $options); } - if (empty($options['block'])) { + if (empty($options['block'])) { return $out . "\n"; } return null; @@ -645,7 +645,7 @@ public function style($data, $oneline = true) { return $data; } $out = array(); - foreach ($data as $key=> $value) { + foreach ($data as $key => $value) { $out[] = $key . ':' . $value . ';'; } if ($oneline) { diff --git a/lib/Cake/View/Helper/JqueryEngineHelper.php b/lib/Cake/View/Helper/JqueryEngineHelper.php index 06db8adda21..a0577229458 100644 --- a/lib/Cake/View/Helper/JqueryEngineHelper.php +++ b/lib/Cake/View/Helper/JqueryEngineHelper.php @@ -38,6 +38,7 @@ * @package Cake.View.Helper */ class JqueryEngineHelper extends JsBaseEngineHelper { + /** * Option mappings for jQuery * @@ -149,7 +150,7 @@ protected function _methodTemplate($method, $template, $options, $extraSafeKeys */ public function get($selector) { if ($selector == 'window' || $selector == 'document') { - $this->selection = $this->jQueryObject . '(' . $selector .')'; + $this->selection = $this->jQueryObject . '(' . $selector . ')'; } else { $this->selection = $this->jQueryObject . '("' . $selector . '")'; } @@ -258,7 +259,7 @@ public function request($url, $options = array()) { if (isset($options['update'])) { $wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true; $success = ''; - if (isset($options['success']) AND !empty($options['success'])) { + if (isset($options['success']) && !empty($options['success'])) { $success .= $options['success']; } $success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);'; @@ -276,7 +277,7 @@ public function request($url, $options = array()) { } $options = $this->_prepareCallbacks('request', $options); $options = $this->_parseOptions($options, $callbacks); - return $this->jQueryObject . '.ajax({' . $options .'});'; + return $this->jQueryObject . '.ajax({' . $options . '});'; } /** @@ -356,4 +357,5 @@ public function serializeForm($options = array()) { } return $selector . $method; } + } diff --git a/lib/Cake/View/Helper/JsBaseEngineHelper.php b/lib/Cake/View/Helper/JsBaseEngineHelper.php index 01dd5bf2291..b129f293a10 100644 --- a/lib/Cake/View/Helper/JsBaseEngineHelper.php +++ b/lib/Cake/View/Helper/JsBaseEngineHelper.php @@ -1,9 +1,5 @@ _multipleSelection = false; if ($selector == 'window' || $selector == 'document') { - $this->selection = "$(" . $selector .")"; + $this->selection = "$(" . $selector . ")"; return $this; } if (preg_match('/^#[^\s.]+$/', $selector)) { @@ -383,4 +372,5 @@ public function serializeForm($options = array()) { } return $selection . $method; } + } diff --git a/lib/Cake/View/Helper/NumberHelper.php b/lib/Cake/View/Helper/NumberHelper.php index ba4130130c1..addd01b6d3d 100644 --- a/lib/Cake/View/Helper/NumberHelper.php +++ b/lib/Cake/View/Helper/NumberHelper.php @@ -33,11 +33,15 @@ */ class NumberHelper extends AppHelper { -/** CakeNumber instance +/** + * CakeNumber instance + * + * @var CakeNumber */ protected $_engine = null; -/* Default Constructor +/** + * Default Constructor * * ### Settings: * @@ -46,6 +50,7 @@ class NumberHelper extends AppHelper { * * @param View $View The View this helper is being attached to. * @param array $settings Configuration settings for the helper + * @throws CakeException When the engine class could not be found. */ public function __construct(View $View, $settings = array()) { $settings = Set::merge(array('engine' => 'CakeNumber'), $settings); diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 38688269dd4..9f43cfa69c1 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -690,7 +690,7 @@ public function numbers($options = array()) { $start = $params['page'] - ($modulus - ($end - $params['page'])); if ($start <= 1) { $start = 1; - $end = $params['page'] + ($modulus - $params['page']) + 1; + $end = $params['page'] + ($modulus - $params['page']) + 1; } if ($first && $start > 1) { @@ -705,8 +705,7 @@ public function numbers($options = array()) { $out .= $before; for ($i = $start; $i < $params['page']; $i++) { - $out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')) - . $separator; + $out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')) . $separator; } if ($class) { @@ -719,8 +718,7 @@ public function numbers($options = array()) { $start = $params['page'] + 1; for ($i = $start; $i < $end; $i++) { - $out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')) - . $separator; + $out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')) . $separator; } if ($end != $params['page']) { @@ -823,8 +821,7 @@ public function first($first = '<< first', $options = array()) { $out .= $after; } elseif ($params['page'] > 1 && is_string($first)) { $options += array('rel' => 'first'); - $out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options), compact('class')) - . $after; + $out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options), compact('class')) . $after; } return $out; } @@ -897,4 +894,5 @@ public function last($last = 'last >>', $options = array()) { } return $out; } + } diff --git a/lib/Cake/View/Helper/PrototypeEngineHelper.php b/lib/Cake/View/Helper/PrototypeEngineHelper.php index 69f755699c3..79943090fbe 100644 --- a/lib/Cake/View/Helper/PrototypeEngineHelper.php +++ b/lib/Cake/View/Helper/PrototypeEngineHelper.php @@ -31,6 +31,7 @@ * @package Cake.View.Helper */ class PrototypeEngineHelper extends JsBaseEngineHelper { + /** * Is the current selection a multiple selection? or is it just a single element. * @@ -119,7 +120,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { public function get($selector) { $this->_multiple = false; if ($selector == 'window' || $selector == 'document') { - $this->selection = "$(" . $selector .")"; + $this->selection = "$(" . $selector . ")"; return $this; } if (preg_match('/^#[^\s.]+$/', $selector)) { @@ -219,7 +220,7 @@ public function effect($name, $options = array()) { case 'fadeIn': case 'fadeOut': $name = ($name == 'fadeIn') ? 'appear' : 'fade'; - $effect = $this->selection . '.' . $name .'(' . substr($optionString, 2) . ');'; + $effect = $this->selection . '.' . $name . '(' . substr($optionString, 2) . ');'; break; } return $effect; @@ -233,7 +234,7 @@ public function effect($name, $options = array()) { * @return string The completed ajax call. */ public function request($url, $options = array()) { - $url = '"'. $this->url($url) . '"'; + $url = '"' . $this->url($url) . '"'; $options = $this->_mapOptions('request', $options); $type = '.Request'; $data = null; @@ -365,4 +366,5 @@ public function serializeForm($options = array()) { } return $selection . $method; } + } diff --git a/lib/Cake/View/Helper/RssHelper.php b/lib/Cake/View/Helper/RssHelper.php index f7c7a305d4f..8dffdafc45b 100644 --- a/lib/Cake/View/Helper/RssHelper.php +++ b/lib/Cake/View/Helper/RssHelper.php @@ -326,7 +326,7 @@ public function elem($name, $attrib = array(), $content = null, $endTag = true) if ($cdata && !empty($content)) { $content = ''; } - $xml .= '>' . $content . ''; + $xml .= '>' . $content . ''; $elem = Xml::build($xml, array('return' => 'domdocument')); $nodes = $elem->getElementsByTagName($bareName); foreach ($attrib as $key => $value) { @@ -341,4 +341,5 @@ public function elem($name, $attrib = array(), $content = null, $endTag = true) $xml = trim(substr($xml, strpos($xml, '?>') + 2)); return $xml; } + } diff --git a/lib/Cake/View/Helper/SessionHelper.php b/lib/Cake/View/Helper/SessionHelper.php index c22d4c7af9f..f23b6b741d5 100644 --- a/lib/Cake/View/Helper/SessionHelper.php +++ b/lib/Cake/View/Helper/SessionHelper.php @@ -159,4 +159,5 @@ public function flash($key = 'flash', $attrs = array()) { public function valid() { return CakeSession::valid(); } + } diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index 99b65bb15cb..473caf0bc45 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -63,6 +63,7 @@ class TextHelper extends AppHelper { * * @param View $View the view object the helper is attached to. * @param array $settings Settings array Settings array + * @throws CakeException when the engine class could not be found. */ public function __construct(View $View, $settings = array()) { $settings = Set::merge(array('engine' => 'String'), $settings); diff --git a/lib/Cake/View/Helper/TimeHelper.php b/lib/Cake/View/Helper/TimeHelper.php index 3b4a295f866..48d8aaea84d 100644 --- a/lib/Cake/View/Helper/TimeHelper.php +++ b/lib/Cake/View/Helper/TimeHelper.php @@ -47,6 +47,7 @@ class TimeHelper extends AppHelper { * * @param View $View the view object the helper is attached to. * @param array $settings Settings array Settings array + * @throws CakeException When the engine class could not be found. */ public function __construct(View $View, $settings = array()) { $settings = Set::merge(array('engine' => 'CakeTime'), $settings); diff --git a/lib/Cake/View/HelperCollection.php b/lib/Cake/View/HelperCollection.php index 5e593f51dd8..a6d7ee0a962 100644 --- a/lib/Cake/View/HelperCollection.php +++ b/lib/Cake/View/HelperCollection.php @@ -152,4 +152,5 @@ public function trigger($callback, $params = array(), $options = array()) { } return parent::trigger($callback, $params, $options); } + } diff --git a/lib/Cake/View/MediaView.php b/lib/Cake/View/MediaView.php index 3f8f172762b..a023aba8276 100644 --- a/lib/Cake/View/MediaView.php +++ b/lib/Cake/View/MediaView.php @@ -58,6 +58,7 @@ * @package Cake.View */ class MediaView extends View { + /** * Indicates whether response gzip compression was enabled for this class * @@ -65,15 +66,6 @@ class MediaView extends View { */ protected $_compressionEnabled = false; -/** - * Constructor - * - * @param Controller $controller The controller with viewVars - */ - public function __construct(Controller $controller = null) { - parent::__construct($controller); - } - /** * Display or download the given file * @@ -242,4 +234,5 @@ protected function _flushBuffer() { @flush(); @ob_flush(); } + } diff --git a/lib/Cake/View/ScaffoldView.php b/lib/Cake/View/ScaffoldView.php index f97ecc65384..fd63dd77e6a 100644 --- a/lib/Cake/View/ScaffoldView.php +++ b/lib/Cake/View/ScaffoldView.php @@ -87,4 +87,5 @@ protected function _getViewFileName($name = null) { throw new MissingViewException($paths[0] . $name . $this->ext); } + } diff --git a/lib/Cake/View/ViewBlock.php b/lib/Cake/View/ViewBlock.php index fe725f25c51..4508a2cef3f 100644 --- a/lib/Cake/View/ViewBlock.php +++ b/lib/Cake/View/ViewBlock.php @@ -154,4 +154,5 @@ public function active() { public function unclosed() { return $this->_active; } + }