Skip to content

Commit

Permalink
style(*): start using short array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinsh committed Dec 23, 2018
1 parent 7a6b3b4 commit 0bf42a9
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 144 deletions.
18 changes: 9 additions & 9 deletions application/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
* @link http://kohanaframework.org/guide/using.autoloading
* @link http://www.php.net/manual/function.spl-autoload-register
*/
spl_autoload_register(array('Kohana', 'auto_load'));
spl_autoload_register(['Kohana', 'auto_load']);

/**
* Optionally, you can enable a compatibility auto-loader for use with
* older modules that have not been updated for PSR-0.
*
* It is recommended to not enable this unless absolutely necessary.
*/
//spl_autoload_register(array('Kohana', 'auto_load_lowercase'));
//spl_autoload_register(['Kohana', 'auto_load_lowercase']);

/**
* Enable the Kohana auto-loader for unserialization.
Expand Down Expand Up @@ -98,9 +98,9 @@
* - boolean caching enable or disable internal caching FALSE
* - boolean expose set the X-Powered-By header FALSE
*/
Kohana::init(array(
Kohana::init([
'base_url' => '/kohana/',
));
]);

/**
* Attach the file write to logging. Multiple writers are supported.
Expand All @@ -115,7 +115,7 @@
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array(
Kohana::modules([
// 'auth' => MODPATH.'auth', // Basic authentication
// 'cache' => MODPATH.'cache', // Caching with multiple backends
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
Expand All @@ -125,12 +125,12 @@
// 'orm' => MODPATH.'orm', // Object Relationship Mapping
// 'unittest' => MODPATH.'unittest', // Unit testing
// 'userguide' => MODPATH.'userguide', // User guide and API documentation
));
]);

/**
* Cookie Salt
* @see http://kohanaframework.org/3.3/guide/kohana/cookies
*
*
* If you have not defined a cookie salt in your Cookie class then
* uncomment the line below and define a preferrably long salt.
*/
Expand All @@ -141,7 +141,7 @@
* defaults for the URI.
*/
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
->defaults([
'controller' => 'welcome',
'action' => 'index',
));
]);
5 changes: 2 additions & 3 deletions modules/codebench/classes/Bench/MDDoBaseURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class Bench_MDDoBaseURL extends Codebench
public $description = 'Optimization for the <code>doBaseURL()</code> method of <code>Kohana_Kodoc_Markdown</code>
for the Kohana Userguide.';
public $loops = 10000;
public $subjects = array
(
public $subjects = [
// Valid matches
'[filesystem](about.filesystem)',
'[filesystem](about.filesystem "Optional title")',
Expand All @@ -22,7 +21,7 @@ class Bench_MDDoBaseURL extends Codebench
// Invalid matches
'![this is image syntax](about.filesystem)',
'[filesystem](about.filesystem',
);
];

public function bench_original($subject)
{
Expand Down
5 changes: 2 additions & 3 deletions modules/codebench/classes/Bench/MDDoImageURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class Bench_MDDoImageURL extends Codebench
public $description = 'Optimization for the <code>doImageURL()</code> method of <code>Kohana_Kodoc_Markdown</code>
for the Kohana Userguide.';
public $loops = 10000;
public $subjects = array
(
public $subjects = [
// Valid matches
'![Alt text](http://img.skitch.com/20091019-rud5mmqbf776jwua6hx9nm1n.png)',
'![Alt text](https://img.skitch.com/20091019-rud5mmqbf776jwua6hx9nm1n.png)',
Expand All @@ -23,7 +22,7 @@ class Bench_MDDoImageURL extends Codebench
'![Empty src]()',
// Invalid matches
'![Alt text](img/install.png "No closing parenthesis"',
);
];

public function bench_original($subject)
{
Expand Down
20 changes: 8 additions & 12 deletions modules/codebench/classes/Kohana/Codebench.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ abstract class Kohana_Codebench
/**
* @var array Grade letters with their maximum scores. Used to color the graphs.
*/
public $grades = array
(
public $grades = [
125 => 'A',
150 => 'B',
200 => 'C',
300 => 'D',
500 => 'E',
'default' => 'F',
);
];

/**
* Constructor.
Expand Down Expand Up @@ -70,18 +69,16 @@ public function run()
}

// Initialize benchmark output
$codebench = array
(
$codebench = [
'class' => get_class($this),
'description' => $this->description,
'loops' => array
(
'loops' => [
'base' => (int) $this->loops,
'total' => (int) $this->loops * count($this->subjects) * count($methods),
),
],
'subjects' => $this->subjects,
'benchmarks' => [],
);
];

// Benchmark each method
foreach ($methods as $method) {
Expand Down Expand Up @@ -111,12 +108,11 @@ public function run()
$benchmark = Profiler::total($token);

// Benchmark output specific to the current method and subject
$codebench['benchmarks'][$method]['subjects'][$subject_key] = array
(
$codebench['benchmarks'][$method]['subjects'][$subject_key] = [
'return' => $return,
'time' => $benchmark[0],
'memory' => $benchmark[1],
);
];

// Update method totals
$codebench['benchmarks'][$method]['time'] += $benchmark[0];
Expand Down
5 changes: 2 additions & 3 deletions modules/image/classes/Kohana/Image/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ protected function _do_sharpen($amount)
$amount = round(abs(-18 + ($amount * 0.08)), 2);

// Gaussian blur matrix
$matrix = array
(
$matrix = [
[-1, -1, -1],
[-1, $amount, -1],
[-1, -1, -1],
);
];

// Perform the sharpen
if (imageconvolution($this->_image, $matrix, $amount - 8, 0)) {
Expand Down
5 changes: 2 additions & 3 deletions modules/orm/classes/Kohana/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,10 @@ protected function run_filter($field, $value)
$filters = empty($filters[$field]) ? $wildcards : array_merge($wildcards, $filters[$field]);

// Bind the field name and model so they can be used in the filter method
$_bound = array
(
$_bound = [
':field' => $field,
':model' => $this,
);
];

foreach ($filters as $array) {
// Value needs to be bound inside the loop so we are always using the
Expand Down
14 changes: 6 additions & 8 deletions modules/orm/classes/Kohana/ORM/Validation/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ public function __construct($alias, Validation $object, $message = 'Failed to va
* // inside the exception for a user model.
* $e->add_object('profile', $validation);
* // The errors array will now look something like this
* // array
* // (
* // 'username' => 'This field is required',
* // 'profile' => array
* // (
* // 'first_name' => 'This field is required',
* // ),
* // );
* // [
* // 'username' => 'This field is required'
* // 'profile' => [
* // 'first_name' => 'This field is required'
* // ]
* // ];
*
* @param string $alias The relationship alias from the model
* @param Validation $object The Validation object to merge
Expand Down
26 changes: 13 additions & 13 deletions modules/orm/classes/Model/Auth/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
class Model_Auth_Role extends ORM
{
// Relationships
protected $_has_many = array(
'users' => array('model' => 'User', 'through' => 'roles_users'),
);
protected $_has_many = [
'users' => ['model' => 'User', 'through' => 'roles_users'],
];

public function rules()
{
return array(
'name' => array(
array('not_empty'),
array('min_length', array(':value', 4)),
array('max_length', array(':value', 32)),
),
'description' => array(
array('max_length', array(':value', 255)),
)
);
return [
'name' => [
['not_empty'],
['min_length', [':value', 4]],
['max_length', [':value', 32]],
],
'description' => [
['max_length', [':value', 255]],
]
];
}

}
Expand Down
85 changes: 44 additions & 41 deletions modules/orm/classes/Model/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class Model_Auth_User extends ORM
*
* @var array Relationhips
*/
protected $_has_many = array(
'user_tokens' => array('model' => 'User_Token'),
'roles' => array('model' => 'Role', 'through' => 'roles_users'),
);
protected $_has_many = [
'user_tokens' => ['model' => 'User_Token'],
'roles' => ['model' => 'Role', 'through' => 'roles_users'],
];

/**
* Rules for the user model. Because the password is _always_ a hash
Expand All @@ -32,21 +32,21 @@ class Model_Auth_User extends ORM
*/
public function rules()
{
return array(
'username' => array(
array('not_empty'),
array('max_length', array(':value', 32)),
array(array($this, 'unique'), array('username', ':value')),
),
'password' => array(
array('not_empty'),
),
'email' => array(
array('not_empty'),
array('email'),
array(array($this, 'unique'), array('email', ':value')),
),
);
return [
'username' => [
['not_empty'],
['max_length', [':value', 32]],
[[$this, 'unique'], ['username', ':value']],
],
'password' => [
['not_empty'],
],
'email' => [
['not_empty'],
['email'],
[[$this, 'unique'], ['email', ':value']],
],
];
}

/**
Expand All @@ -57,11 +57,11 @@ public function rules()
*/
public function filters()
{
return array(
'password' => array(
array(array(Auth::instance(), 'hash'))
)
);
return [
'password' => [
[[Auth::instance(), 'hash']]
]
];
}

/**
Expand All @@ -71,11 +71,11 @@ public function filters()
*/
public function labels()
{
return array(
return [
'username' => 'username',
'email' => 'email address',
'password' => 'password',
);
];
}

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ public function unique_key_exists($value, $field = NULL)
$field = $this->unique_key($value);
}

return (bool) DB::select(array(DB::expr('COUNT(*)'), 'total_count'))
return (bool) DB::select([DB::expr('COUNT(*)'), 'total_count'])
->from($this->_table_name)
->where($field, '=', $value)
->where($this->_primary_key, '!=', $this->pk())
Expand Down Expand Up @@ -139,20 +139,23 @@ public function unique_key($value)
public static function get_password_validation($values)
{
return Validation::factory($values)
->rule('password', 'min_length', array(':value', 8))
->rule('password_confirm', 'matches', array(':validation', ':field', 'password'));
->rule('password', 'min_length', [':value', 8])
->rule('password_confirm', 'matches', [
':validation',
':field', 'password'
]);
}

/**
* Create a new user
*
* Example usage:
* ~~~
* $user = ORM::factory('User')->create_user($_POST, array(
* 'username',
* 'password',
* 'email',
* );
* $user = ORM::factory('User')->create_user($_POST, [
* 'username',
* 'password',
* 'email',
* ]);
* ~~~
*
* @param array $values
Expand All @@ -176,13 +179,13 @@ public function create_user($values, $expected)
* Example usage:
* ~~~
* $user = ORM::factory('User')
* ->where('username', '=', 'kiall')
* ->find()
* ->update_user($_POST, array(
* 'username',
* 'password',
* 'email',
* );
* ->where('username', '=', 'kiall')
* ->find()
* ->update_user($_POST, [
* 'username',
* 'password',
* 'email',
* ]);
* ~~~
*
* @param array $values
Expand Down
Loading

0 comments on commit 0bf42a9

Please sign in to comment.