ソースを参照

cleanup helpers

euromark 11 年 前
コミット
cbdba5d86d

+ 5 - 5
View/Helper/CaptchaHelper.php

@@ -21,7 +21,7 @@ class CaptchaHelper extends AppHelper {
 
 
 	public $helpers = array('Form');
 	public $helpers = array('Form');
 
 
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'difficulty' => 1, # initial diff. level (@see operator: + = 0, +- = 1, +-* = 2)
 		'difficulty' => 1, # initial diff. level (@see operator: + = 0, +- = 1, +-* = 2)
 		'raiseDifficulty' => 2, # number of failed trails, after the x. one the following one it will be more difficult
 		'raiseDifficulty' => 2, # number of failed trails, after the x. one the following one it will be more difficult
 	);
 	);
@@ -39,10 +39,10 @@ class CaptchaHelper extends AppHelper {
 		// Set up an array with the operators that we want to use. With difficulty=1 it is only subtraction and addition.
 		// Set up an array with the operators that we want to use. With difficulty=1 it is only subtraction and addition.
 		$this->operatorConvert = array(0 => array('+', __('calcPlus')), 1 => array('-', __('calcMinus')), 2 => '*', __('calcTimes'));
 		$this->operatorConvert = array(0 => array('+', __('calcPlus')), 1 => array('-', __('calcMinus')), 2 => '*', __('calcTimes'));
 
 
-		$this->settings = array_merge(CaptchaLib::$defaults, $this->_defaults);
+		$this->settings = $this->_defaultConfig + CaptchaLib::$defaults;
 		$settings = (array)Configure::read('Captcha');
 		$settings = (array)Configure::read('Captcha');
 		if (!empty($settings)) {
 		if (!empty($settings)) {
-			$this->settings = array_merge($this->settings, $settings);
+			$this->settings = $settings + $this->settings;
 		}
 		}
 	}
 	}
 
 
@@ -121,7 +121,7 @@ class CaptchaHelper extends AppHelper {
 	 * @return string HTML
 	 * @return string HTML
 	 */
 	 */
 	public function input($modelName = null, $options = array()) {
 	public function input($modelName = null, $options = array()) {
-		$defaultOptions = array(
+		$defaults = array(
 			'type' => 'text',
 			'type' => 'text',
 			'class' => 'captcha',
 			'class' => 'captcha',
 			'value' => '',
 			'value' => '',
@@ -131,7 +131,7 @@ class CaptchaHelper extends AppHelper {
 			'autocomplete' => 'off',
 			'autocomplete' => 'off',
 			'after' => __('captchaTip'),
 			'after' => __('captchaTip'),
 		);
 		);
-		$options = array_merge($defaultOptions, $options);
+		$options += $defaults;
 
 
 		if ($options['combined'] === true) {
 		if ($options['combined'] === true) {
 			$options['between'] = $this->captcha($modelName);
 			$options['between'] = $this->captcha($modelName);

+ 2 - 2
View/Helper/DiffHelper.php

@@ -75,7 +75,7 @@ class DiffHelper extends AppHelper {
 		$defaults = array(
 		$defaults = array(
 			'class' => 'diff'
 			'class' => 'diff'
 		);
 		);
-		$options = array_merge($defaults, $options);
+		$options += $defaults;
 		$options['escape'] = null;
 		$options['escape'] = null;
 		return $this->Html->tag('div', $string, $options);
 		return $this->Html->tag('div', $string, $options);
 	}
 	}
@@ -94,7 +94,7 @@ class DiffHelper extends AppHelper {
 		$defaults = array(
 		$defaults = array(
 			'class' => 'diff'
 			'class' => 'diff'
 		);
 		);
-		$options = array_merge($defaults, $options);
+		$options += $defaults;
 		$options['escape'] = null;
 		$options['escape'] = null;
 		return $this->Html->tag('div', $string, $options);
 		return $this->Html->tag('div', $string, $options);
 	}
 	}

+ 2 - 2
View/Helper/FlattrHelper.php

@@ -45,7 +45,7 @@ class FlattrHelper extends AppHelper {
 			//'hidden' => '',
 			//'hidden' => '',
 			//'description' => '',
 			//'description' => '',
 		);
 		);
-		$options = array_merge($defaults, $options);
+		$options += $defaults;
 
 
 		$mode = $options['mode'];
 		$mode = $options['mode'];
 		unset($options['mode']);
 		unset($options['mode']);
@@ -63,7 +63,7 @@ class FlattrHelper extends AppHelper {
 			'style' => 'display:none;',
 			'style' => 'display:none;',
 			'rel' => 'flattr;' . implode(';', $rev)
 			'rel' => 'flattr;' . implode(';', $rev)
 		);
 		);
-		$linkOptions = array_merge($linkOptions, $attr);
+		$linkOptions = $attr + $linkOptions;
 
 
 		$js = "(function() {
 		$js = "(function() {
 	var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
 	var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];

+ 4 - 4
View/Helper/FormExtHelper.php

@@ -861,7 +861,7 @@ class FormExtHelper extends FormHelper {
 		}
 		}
 		$fieldname = Inflector::camelize($field);
 		$fieldname = Inflector::camelize($field);
 
 
-		$customOptions = array_merge($defaultOptions, $options);
+		$customOptions = $options + $defaultOptions;
 		$format24Hours = (int)$customOptions['timeFormat'] !== 24 ? false : true;
 		$format24Hours = (int)$customOptions['timeFormat'] !== 24 ? false : true;
 
 
 		$blacklist = array('timeFormat' => null, 'dateFormat' => null, 'separator' => null);
 		$blacklist = array('timeFormat' => null, 'dateFormat' => null, 'separator' => null);
@@ -1038,10 +1038,10 @@ jQuery(\'' . $selector . '\').maxlength(' . $this->Js->object($settings, array('
 	public function autoComplete($field = null, $options = array(), $jquery = null) {
 	public function autoComplete($field = null, $options = array(), $jquery = null) {
 		$this->autoCompleteScripts();
 		$this->autoCompleteScripts();
 
 
-		$defaultOptions = array(
+		$defaults = array(
 			'autocomplete' => 'off'
 			'autocomplete' => 'off'
 		);
 		);
-		$options = array_merge($defaultOptions, $options);
+		$options += $defaults;
 		if (empty($options['id']) && is_array($jquery)) {
 		if (empty($options['id']) && is_array($jquery)) {
 			$options['id'] = Inflector::camelize(str_replace(".", "_", $field));
 			$options['id'] = Inflector::camelize(str_replace(".", "_", $field));
 		}
 		}
@@ -1141,7 +1141,7 @@ jQuery(\'' . $selector . '\').maxlength(' . $this->Js->object($settings, array('
 		$defaults = array(
 		$defaults = array(
 			'class' => 'checkbox-toggle checkboxToggle'
 			'class' => 'checkbox-toggle checkboxToggle'
 		);
 		);
-		$options = array_merge($defaults, $options);
+		$options += $defaults;
 		return $script . parent::checkbox($fieldName, $options);
 		return $script . parent::checkbox($fieldName, $options);
 	}
 	}
 
 

+ 3 - 3
View/Helper/GoogleMapV3Helper.php

@@ -471,7 +471,7 @@ class GoogleMapV3Helper extends AppHelper {
 			$defaults = array_merge($defaults, $options['icon']);
 			$defaults = array_merge($defaults, $options['icon']);
 			unset($options['icon']);
 			unset($options['icon']);
 		}
 		}
-		$options = array_merge($defaults, $options);
+		$options += $defaults;
 
 
 		$params = array();
 		$params = array();
 		$params['map'] = $this->name();
 		$params['map'] = $this->name();
@@ -797,7 +797,7 @@ var iconShape = {
 	 */
 	 */
 	public function addInfoWindow($options = array()) {
 	public function addInfoWindow($options = array()) {
 		$defaults = $this->_currentOptions['infoWindow'];
 		$defaults = $this->_currentOptions['infoWindow'];
-		$options = array_merge($defaults, $options);
+		$options += $defaults;
 
 
 		if (!empty($options['lat']) && !empty($options['lng'])) {
 		if (!empty($options['lat']) && !empty($options['lng'])) {
 			$position = "new google.maps.LatLng(" . $options['lat'] . ", " . $options['lng'] . ")";
 			$position = "new google.maps.LatLng(" . $options['lat'] . ", " . $options['lng'] . ")";
@@ -1313,7 +1313,7 @@ var iconShape = {
 		*/
 		*/
 
 
 		$defaults = array_merge($this->_defaultOptions, $this->_defaultOptions['staticMap']);
 		$defaults = array_merge($this->_defaultOptions, $this->_defaultOptions['staticMap']);
-		$mapOptions = array_merge($defaults, $options);
+		$mapOptions = $options + $defaults;
 
 
 		$params = array_intersect_key($mapOptions, array(
 		$params = array_intersect_key($mapOptions, array(
 			'sensor' => null,
 			'sensor' => null,

+ 12 - 13
View/Helper/GravatarHelper.php

@@ -28,21 +28,23 @@ class GravatarHelper extends AppHelper {
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected $_allowedRatings = array('g', 'pg', 'r', 'x');
+	protected $_allowedRatings = array(
+		'g', 'pg', 'r', 'x');
 
 
 	/**
 	/**
 	 * Default Icon sets
 	 * Default Icon sets
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected $_defaultIcons = array('none', 'mm', 'identicon', 'monsterid', 'retro', 'wavatar', '404');
+	protected $_defaultIcons = array(
+		'none', 'mm', 'identicon', 'monsterid', 'retro', 'wavatar', '404');
 
 
 	/**
 	/**
 	 * Default settings
 	 * Default settings
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected $_default = array(
+	protected $_defaultConfig = array(
 		'default' => null,
 		'default' => null,
 		'size' => null,
 		'size' => null,
 		'rating' => null,
 		'rating' => null,
@@ -59,15 +61,12 @@ class GravatarHelper extends AppHelper {
 	 * Constructor
 	 * Constructor
 	 *
 	 *
 	 */
 	 */
-	public function __construct($View = null, $settings = array()) {
-		if (!is_array($settings)) {
-			$settings = array();
-		}
-		$this->_default = array_merge($this->_default, array_intersect_key($settings, $this->_default));
+	public function __construct($View = null, $config = array()) {
+		$config += $this->_defaultConfig;
 
 
 		// Default the secure option to match the current URL.
 		// Default the secure option to match the current URL.
-		$this->_default['secure'] = env('HTTPS');
-		parent::__construct($View, $settings);
+		$config['secure'] = env('HTTPS');
+		parent::__construct($View, $config);
 	}
 	}
 
 
 	/**
 	/**
@@ -92,7 +91,7 @@ class GravatarHelper extends AppHelper {
 	 * @return string Gravatar Image URL
 	 * @return string Gravatar Image URL
 	 */
 	 */
 	public function imageUrl($email, $options = array()) {
 	public function imageUrl($email, $options = array()) {
-		$options = $this->_cleanOptions(array_merge($this->_default, $options));
+		$options = $this->_cleanOptions($options + $this->settings);
 		$ext = $options['ext'];
 		$ext = $options['ext'];
 		$secure = $options['secure'];
 		$secure = $options['secure'];
 		unset($options['ext'], $options['secure']);
 		unset($options['ext'], $options['secure']);
@@ -115,7 +114,7 @@ class GravatarHelper extends AppHelper {
 	 * @return array Default images array
 	 * @return array Default images array
 	 */
 	 */
 	public function defaultImages($options = array()) {
 	public function defaultImages($options = array()) {
-		$options = $this->_cleanOptions(array_merge($this->_default, $options));
+		$options = $this->_cleanOptions($options + $this->settings);
 		$images = array();
 		$images = array();
 		foreach ($this->_defaultIcons as $defaultIcon) {
 		foreach ($this->_defaultIcons as $defaultIcon) {
 			$options['default'] = $defaultIcon;
 			$options['default'] = $defaultIcon;
@@ -170,7 +169,7 @@ class GravatarHelper extends AppHelper {
 	 * @return string URL string of options
 	 * @return string URL string of options
 	 */
 	 */
 	protected function _buildOptions($options = array()) {
 	protected function _buildOptions($options = array()) {
-		$gravatarOptions = array_intersect(array_keys($options), array_keys($this->_default));
+		$gravatarOptions = array_intersect(array_keys($options), array_keys($this->_defaultConfig));
 		if (!empty($gravatarOptions)) {
 		if (!empty($gravatarOptions)) {
 			$optionArray = array();
 			$optionArray = array();
 			foreach ($gravatarOptions as $key) {
 			foreach ($gravatarOptions as $key) {

+ 3 - 2
View/Helper/HtmlExtHelper.php

@@ -58,11 +58,12 @@ class HtmlExtHelper extends HtmlHelper {
 		if (!isset($this->tags['time'])) {
 		if (!isset($this->tags['time'])) {
 			$this->tags['time'] = '<time%s>%s</time>';
 			$this->tags['time'] = '<time%s>%s</time>';
 		}
 		}
-		$options = array_merge(array(
+		$defaults = array(
 			'datetime' => '%Y-%m-%d %T',
 			'datetime' => '%Y-%m-%d %T',
 			'pubdate' => false,
 			'pubdate' => false,
 			'format' => '%Y-%m-%d %T',
 			'format' => '%Y-%m-%d %T',
-		), $options);
+		);
+		$options += $defaults;
 
 
 		if ($options['format'] !== null) {
 		if ($options['format'] !== null) {
 			if (!isset($this->Time)) {
 			if (!isset($this->Time)) {

+ 1 - 1
View/Helper/QrCodeHelper.php

@@ -95,7 +95,7 @@ class QrCodeHelper extends AppHelper {
 	 * @return string Url
 	 * @return string Url
 	 */
 	 */
 	protected function _uri($params = array()) {
 	protected function _uri($params = array()) {
-		$params = array_merge($this->options, $params);
+		$params += $this->options;
 		$pieces = array();
 		$pieces = array();
 		foreach ($params as $key => $value) {
 		foreach ($params as $key => $value) {
 			$pieces[] = $key . '=' . $value;
 			$pieces[] = $key . '=' . $value;

+ 2 - 2
View/Helper/TimelineHelper.php

@@ -18,7 +18,7 @@ class TimelineHelper extends AppHelper {
 
 
 	public $helpers = array('Js');
 	public $helpers = array('Js');
 
 
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'id' => 'mytimeline',
 		'id' => 'mytimeline',
 		'selectable' => false,
 		'selectable' => false,
 		'editable' => false,
 		'editable' => false,
@@ -39,7 +39,7 @@ class TimelineHelper extends AppHelper {
 	 * @param array $settings Configuration settings for the helper.
 	 * @param array $settings Configuration settings for the helper.
 	 */
 	 */
 	public function __construct(View $View, $settings = array()) {
 	public function __construct(View $View, $settings = array()) {
-		$this->settings = $this->_defaults;
+		$this->settings = $this->_defaultConfig;
 		parent::__construct($View, $settings);
 		parent::__construct($View, $settings);
 	}
 	}
 
 

+ 10 - 10
View/Helper/TreeHelper.php

@@ -119,12 +119,12 @@ class TreeHelper extends AppHelper {
 	 * @return string html representation of the passed data
 	 * @return string html representation of the passed data
 	 * @throws CakeException
 	 * @throws CakeException
 	 */
 	 */
-	public function generate($data, $settings = array()) {
+	public function generate(array $data, array $settings = array()) {
 		if (!$data) {
 		if (!$data) {
 			return '';
 			return '';
 		}
 		}
 
 
-		$this->_settings = array_merge($this->_defaults, (array)$settings);
+		$this->_settings = $settings + $this->_defaults;
 		if ($this->_settings['autoPath'] && !isset($this->_settings['autoPath'][2])) {
 		if ($this->_settings['autoPath'] && !isset($this->_settings['autoPath'][2])) {
 			$this->_settings['autoPath'][2] = 'active';
 			$this->_settings['autoPath'][2] = 'active';
 		}
 		}
@@ -255,7 +255,7 @@ class TreeHelper extends AppHelper {
 				$result['children'] = array();
 				$result['children'] = array();
 			}
 			}
 
 
-			$this->_settings = array_merge($this->_settings, $elementData);
+			$this->_settings = $elementData + $this->_settings;
 			if ($this->_settings['fullSettings']) {
 			if ($this->_settings['fullSettings']) {
 				$elementData = $this->_settings;
 				$elementData = $this->_settings;
 			}
 			}
@@ -464,13 +464,13 @@ class TreeHelper extends AppHelper {
 	 *
 	 *
 	 * Logic to apply styles to tags.
 	 * Logic to apply styles to tags.
 	 *
 	 *
-	 * @param mixed $rType
+	 * @param string $rType
 	 * @param array $elementData
 	 * @param array $elementData
 	 * @return void
 	 * @return void
 	 */
 	 */
-	protected function _attributes($rType, $elementData = array(), $clear = true) {
+	protected function _attributes($rType, array $elementData = array(), $clear = true) {
 		extract($this->_settings);
 		extract($this->_settings);
-		if ($rType == $type) {
+		if ($rType === $type) {
 			$attributes = $this->_typeAttributes;
 			$attributes = $this->_typeAttributes;
 			if ($clear) {
 			if ($clear) {
 				$this->_typeAttributes = $this->_typeAttributesNext;
 				$this->_typeAttributes = $this->_typeAttributesNext;
@@ -483,7 +483,7 @@ class TreeHelper extends AppHelper {
 				$this->_itemAttributes = array();
 				$this->_itemAttributes = array();
 			}
 			}
 		}
 		}
-		if ($rType == $itemType && $elementData['activePathElement']) {
+		if ($rType === $itemType && $elementData['activePathElement']) {
 			if ($elementData['activePathElement'] === true) {
 			if ($elementData['activePathElement'] === true) {
 				$attributes['class'][] = $autoPath[2];
 				$attributes['class'][] = $autoPath[2];
 			} else {
 			} else {
@@ -515,13 +515,13 @@ class TreeHelper extends AppHelper {
 	 * Mark unrelated records as hidden using `'hide' => 1`.
 	 * Mark unrelated records as hidden using `'hide' => 1`.
 	 * In the callback or element you can then return early in this case.
 	 * In the callback or element you can then return early in this case.
 	 *
 	 *
-	 * @param array $tree
-	 * @param array $treePath
+	 * @param array $tree Tree
+	 * @param array $path Tree path
 	 * @param int $level
 	 * @param int $level
 	 * @return void
 	 * @return void
 	 * @throws CakeException
 	 * @throws CakeException
 	 */
 	 */
-	protected function _markUnrelatedAsHidden(&$tree, $path, $level = 0) {
+	protected function _markUnrelatedAsHidden(&$tree, array $path, $level = 0) {
 		extract($this->_settings);
 		extract($this->_settings);
 		$siblingIsActive = false;
 		$siblingIsActive = false;
 		foreach ($tree as $key => &$subTree) {
 		foreach ($tree as $key => &$subTree) {

+ 6 - 6
View/Helper/WeatherHelper.php

@@ -12,13 +12,13 @@ class WeatherHelper extends AppHelper {
 
 
 	public $helpers = array('Html');
 	public $helpers = array('Html');
 
 
-	protected $_defaults = array(
+	protected $_defaultConfig = array(
 		'imageUrl' => 'http://www.google.com/ig/images/weather/'
 		'imageUrl' => 'http://www.google.com/ig/images/weather/'
 	);
 	);
 
 
 	public function __construct($View = null, $settings = array()) {
 	public function __construct($View = null, $settings = array()) {
-		$this->_defaults = (array)Configure::read('Weather') + $this->_defaults;
-		parent::__construct($View, $settings + $this->_defaults);
+		$this->_defaultConfig = (array)Configure::read('Weather') + $this->_defaultConfig;
+		parent::__construct($View, $settings + $this->_defaultConfig);
 	}
 	}
 
 
 	/**
 	/**
@@ -38,13 +38,13 @@ class WeatherHelper extends AppHelper {
 	 *
 	 *
 	 * @return array
 	 * @return array
 	 */
 	 */
-	public function get($location, $cOptions = array()) {
+	public function get($location, $options = array()) {
 		$Weather = new WeatherLib();
 		$Weather = new WeatherLib();
 
 
-		$options = array(
+		$defaults = array(
 			'cache' => '+1 hour'
 			'cache' => '+1 hour'
 		);
 		);
-		$options = array_merge($options, $cOptions);
+		$options += $defaults;
 		return $Weather->get($location, $options);
 		return $Weather->get($location, $options);
 	}
 	}