Skip to content

Commit

Permalink
Simplify string key based option array merges to + operator for consi…
Browse files Browse the repository at this point in the history
…stency and micro-opt. Also removed dead code.
  • Loading branch information
euromark committed Jun 10, 2014
1 parent 3d40307 commit 513f97b
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Component.php
Expand Up @@ -119,7 +119,7 @@ public function __construct(ComponentRegistry $registry, array $config = []) {
*/
public function __get($name) {
if (isset($this->_componentMap[$name]) && !isset($this->{$name})) {
$config = array_merge((array)$this->_componentMap[$name]['config'], array('enabled' => false));
$config = array('enabled' => false) + (array)$this->_componentMap[$name]['config'];
$this->{$name} = $this->_registry->load($this->_componentMap[$name]['class'], $config);
}
if (isset($this->{$name})) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/AuthComponent.php
Expand Up @@ -504,7 +504,7 @@ public function constructAuthorize() {
if (!method_exists($className, 'authorize')) {
throw new Error\Exception('Authorization objects must implement an authorize() method.');
}
$config = array_merge($global, (array)$config);
$config = (array)$config + $global;
$this->_authorizeObjects[] = new $className($this->_registry, $config);
}
return $this->_authorizeObjects;
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Email/Email.php
Expand Up @@ -1214,7 +1214,7 @@ public function send($content = null) {
if (!is_array($this->_profile['log'])) {
$this->_profile['log'] = ['level' => $this->_profile['log']];
}
$config = array_merge($config, $this->_profile['log']);
$config = $this->_profile['log'] + $config;
}
Log::write(
$config['level'],
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/TableRegistry.php
Expand Up @@ -157,7 +157,7 @@ public static function get($name, array $options = []) {
$options['className'] = $className ?: 'Cake\ORM\Table';

if (isset(static::$_config[$alias])) {
$options = array_merge(static::$_config[$alias], $options);
$options += static::$_config[$alias];
}
if (empty($options['connection'])) {
$connectionName = $options['className']::defaultConnectionName();
Expand Down
5 changes: 1 addition & 4 deletions src/Routing/RequestActionTrait.php
Expand Up @@ -105,10 +105,7 @@ public function requestAction($url, array $extra = array()) {
$extra['autoRender'] = 1;
unset($extra[$index]);
}
$extra = array_merge(
['autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1],
$extra
);
$extra += ['autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1];

$baseUrl = Configure::read('App.fullBaseUrl');
if (is_string($url) && strpos($url, $baseUrl) === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/Routing/Router.php
Expand Up @@ -435,10 +435,10 @@ public static function redirect($route, $url, $options = []) {
* @return array Array of mapped resources
*/
public static function mapResources($controller, $options = []) {
$options = array_merge(array(
$options += array(
'connectOptions' => [],
'id' => static::ID . '|' . static::UUID
), $options);
);

$connectOptions = $options['connectOptions'];
unset($options['connectOptions']);
Expand Down
8 changes: 4 additions & 4 deletions src/Utility/String.php
Expand Up @@ -269,11 +269,11 @@ public static function cleanInsert($str, array $options) {
}
switch ($clean['method']) {
case 'html':
$clean = array_merge(array(
$clean += array(
'word' => '[\w,.]+',
'andText' => true,
'replacement' => '',
), $clean);
);
$kleenex = sprintf(
'/[\s]*[a-z]+=(")(%s%s%s[\s]*)+\\1/i',
preg_quote($options['before'], '/'),
Expand All @@ -287,11 +287,11 @@ public static function cleanInsert($str, array $options) {
}
break;
case 'text':
$clean = array_merge(array(
$clean += array(
'word' => '[\w,.]+',
'gap' => '[\s]*(?:(?:and|or)[\s]*)?',
'replacement' => '',
), $clean);
);

$kleenex = sprintf(
'/(%s%s%s%s|%s%s%s%s)/',
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Time.php
Expand Up @@ -246,7 +246,7 @@ public function timeAgoInWords(array $options = []) {

if (isset($options['accuracy'])) {
if (is_array($options['accuracy'])) {
$accuracy = array_merge($accuracy, $options['accuracy']);
$accuracy = $options['accuracy'] + $accuracy;
} else {
foreach ($accuracy as $key => $level) {
$accuracy[$key] = $options['accuracy'];
Expand Down
1 change: 0 additions & 1 deletion src/View/Helper.php
Expand Up @@ -175,7 +175,6 @@ public function __call($method, $params) {
*/
public function __get($name) {
if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {
$settings = array_merge((array)$this->_helperMap[$name]['config'], array('enabled' => false));
$this->{$name} = $this->_View->addHelper($this->_helperMap[$name]['class'], $this->_config);
}
if (isset($this->{$name})) {
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -339,7 +339,7 @@ public function create($model = null, $options = []) {
}
unset($options['type'], $options['encoding']);

$htmlAttributes = array_merge($options, $htmlAttributes);
$htmlAttributes += $options;

$this->fields = array();
if ($this->requestType !== 'get') {
Expand Down
3 changes: 2 additions & 1 deletion src/View/Helper/HtmlHelper.php
Expand Up @@ -467,7 +467,8 @@ public function css($path, array $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::script
*/
public function script($url, array $options = array()) {
$options = array_merge(array('block' => null, 'once' => true), $options);
$defaults = array('block' => null, 'once' => true);
$options += $defaults;

if (is_array($url)) {
$out = '';
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/PaginatorHelper.php
Expand Up @@ -270,7 +270,7 @@ public function prev($title = '<< Previous', array $options = []) {
'disabledTitle' => $title,
'escape' => true,
];
$options = array_merge($defaults, (array)$options);
$options += $defaults;
$options['step'] = -1;

$enabled = $this->hasPrev($options['model']);
Expand Down Expand Up @@ -305,7 +305,7 @@ public function next($title = 'Next >>', array $options = []) {
'disabledTitle' => $title,
'escape' => true,
];
$options = array_merge($defaults, (array)$options);
$options += $defaults;
$options['step'] = 1;

$enabled = $this->hasNext($options['model']);
Expand Down
2 changes: 1 addition & 1 deletion src/View/View.php
Expand Up @@ -1082,7 +1082,7 @@ protected function _elementCache($name, $data, $options) {
'config' => $this->elementCache,
'key' => $this->elementCacheSettings['key']
);
$this->elementCacheSettings = array_merge($defaults, $options['cache']);
$this->elementCacheSettings = $options['cache'] + $defaults;
}
$this->elementCacheSettings['key'] = 'element_' . $this->elementCacheSettings['key'];
return Cache::read($this->elementCacheSettings['key'], $this->elementCacheSettings['config']);
Expand Down

0 comments on commit 513f97b

Please sign in to comment.