Skip to content

Commit

Permalink
Fix coding standard issues in View/
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 3, 2012
1 parent 0df239d commit acccdcd
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 125 deletions.
17 changes: 5 additions & 12 deletions lib/Cake/View/Helper.php
@@ -1,11 +1,5 @@
<?php
/**
* Backend for helpers.
*
* Internal methods for the Helpers.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -146,7 +140,6 @@ class Helper extends Object {
'autoplay', 'controls', 'loop', 'muted'
);


/**
* Default Constructor
*
Expand Down Expand Up @@ -255,11 +248,11 @@ public function webroot($file) {
$file = str_replace('/', '\\', $file);
}

if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->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];
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -532,7 +525,6 @@ public function setEntity($entity, $setScope = false) {
}
}
$this->_entityPath = $entity;
return;
}

/**
Expand Down Expand Up @@ -899,4 +891,5 @@ protected function _clean() {
} while ($oldstring != $this->_cleaned);
$this->_cleaned = str_replace(array("&amp;", "&lt;", "&gt;"), array("&amp;amp;", "&amp;lt;", "&amp;gt;"), $this->_cleaned);
}

}
1 change: 1 addition & 0 deletions lib/Cake/View/Helper/CacheHelper.php
Expand Up @@ -317,4 +317,5 @@ protected function _writeFile($content, $timestamp, $useCallbacks = false) {
$file .= $content;
return cache('views' . DS . $cache, $file, $timestamp);
}

}
111 changes: 53 additions & 58 deletions lib/Cake/View/Helper/FormHelper.php
@@ -1,11 +1,5 @@
<?php
/**
* Automatic generation of HTML FORMs from given data.
*
* Used for scaffolding.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -154,11 +148,11 @@ protected function _getModel($model) {
}

$this->_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;
}

Expand All @@ -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;
}
}
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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']);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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']);

Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -2592,4 +2586,5 @@ protected function _initInputField($field, $options = array()) {
$this->_secure($secure, $fieldName);
return $result;
}

}
6 changes: 3 additions & 3 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions lib/Cake/View/Helper/JqueryEngineHelper.php
Expand Up @@ -38,6 +38,7 @@
* @package Cake.View.Helper
*/
class JqueryEngineHelper extends JsBaseEngineHelper {

/**
* Option mappings for jQuery
*
Expand Down Expand Up @@ -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 . '")';
}
Expand Down Expand Up @@ -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);';
Expand All @@ -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 . '});';
}

/**
Expand Down Expand Up @@ -356,4 +357,5 @@ public function serializeForm($options = array()) {
}
return $selector . $method;
}

}
15 changes: 1 addition & 14 deletions lib/Cake/View/Helper/JsBaseEngineHelper.php
@@ -1,9 +1,5 @@
<?php
/**
* JsEngineBaseClass
*
* PHP 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc.
*
Expand Down Expand Up @@ -59,16 +55,6 @@ abstract class JsBaseEngineHelper extends AppHelper {
*/
protected $_callbackArguments = array();

/**
* Constructor.
*
* @param View $View
* @param array $settings
*/
public function __construct($View, $settings = array()) {
parent::__construct($View, $settings);
}

/**
* Create an `alert()` message in Javascript
*
Expand Down Expand Up @@ -602,4 +588,5 @@ protected function _toQuerystring($parameters) {
}
return $out;
}

}
1 change: 1 addition & 0 deletions lib/Cake/View/Helper/JsHelper.php
Expand Up @@ -430,4 +430,5 @@ protected function _getHtmlOptions($options, $additional = array()) {
}
return array($options, $htmlOptions);
}

}

0 comments on commit acccdcd

Please sign in to comment.