Swapped all array() for the shorthand []

Also finished up coverage on the Cache class.
This commit is contained in:
Joshua Sherman 2014-01-15 14:09:54 -05:00
parent aecdd0981f
commit 200988eecf
17 changed files with 115 additions and 97 deletions

View file

@ -34,7 +34,8 @@ class API_Google_Profanity
{ {
$response = json_decode(file_get_contents($endpoint . $word), true); $response = json_decode(file_get_contents($endpoint . $word), true);
if ($response == null || !isset($response['response']) || !in_array($response['response'], array('true', 'false'))) if ($response == null || !isset($response['response'])
|| !in_array($response['response'], ['true', 'false']))
{ {
throw new Exception('Invalid response from API.'); throw new Exception('Invalid response from API.');
} }

View file

@ -63,11 +63,12 @@ class API_Gravatar
{ {
throw new Exception('Invalid size parameter, expecting an integer between 1 and 2048.'); throw new Exception('Invalid size parameter, expecting an integer between 1 and 2048.');
} }
elseif (!in_array($default, array('gravatar', '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank')) && !filter_var($default, FILTER_VALIDATE_URL)) elseif (!in_array($default, ['gravatar', '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'])
&& !filter_var($default, FILTER_VALIDATE_URL))
{ {
throw new Exception('Invalid default parameter, expecting gravatar, 404, mm, identicon, monsterid, wavatar, retro, blank or a valid URL.'); throw new Exception('Invalid default parameter, expecting gravatar, 404, mm, identicon, monsterid, wavatar, retro, blank or a valid URL.');
} }
elseif (!in_array($rating, array('g', 'pg', 'r', 'x'))) elseif (!in_array($rating, ['g', 'pg', 'r', 'x']))
{ {
throw new Exception('Invalid rating parameter, expecting g, pg, r or x.'); throw new Exception('Invalid rating parameter, expecting g, pg, r or x.');
} }

View file

@ -31,7 +31,7 @@ class Browser extends Object
* @access private * @access private
* @var array * @var array
*/ */
private $attributes = array(); private $attributes = [];
/** /**
* Get instance of the object * Get instance of the object

View file

@ -75,13 +75,11 @@ class Cache extends Object
// @todo Shouldn't need the isset() but Travis is failing some tests // @todo Shouldn't need the isset() but Travis is failing some tests
if (isset($this->config->pickles['cache']) && $this->config->pickles['cache']) if (isset($this->config->pickles['cache']) && $this->config->pickles['cache'])
{ {
if (!is_array($this->config->pickles['cache'])) $datasources = $this->config->pickles['cache'];
if (!is_array($datasources))
{ {
$datasources = array($this->config->pickles['cache']); $datasources = [$datasources];
}
else
{
$datasources = $this->config->pickles['cache'];
} }
$this->connection = new Memcache(); $this->connection = new Memcache();
@ -195,7 +193,7 @@ class Cache extends Object
{ {
if (!is_array($keys)) if (!is_array($keys))
{ {
$keys = array($keys); $keys = [$keys];
} }
// Memcache() doesn't let you pass an array to delete all records the same way you can with get() // Memcache() doesn't let you pass an array to delete all records the same way you can with get()

View file

@ -34,7 +34,7 @@ class Config extends Object
* *
* @var array * @var array
*/ */
public $data = array(); public $data = [];
/** /**
* Constructor * Constructor
@ -83,7 +83,7 @@ class Config extends Object
{ {
if (!is_array($hosts)) if (!is_array($hosts))
{ {
$hosts = array($hosts); $hosts = [$hosts];
} }
// Tries to determine the environment name // Tries to determine the environment name
@ -161,7 +161,7 @@ class Config extends Object
} }
// Defaults expected PICKLES options to false // Defaults expected PICKLES options to false
foreach (array('cache', 'logging', 'minify') as $variable) foreach (['cache', 'logging', 'minify'] as $variable)
{ {
if (!isset($this->data['pickles'][$variable])) if (!isset($this->data['pickles'][$variable]))
{ {

View file

@ -33,13 +33,13 @@ class Convert
* that an array's format isn't quite the same as well-formed XML. * that an array's format isn't quite the same as well-formed XML.
* *
* Input Array = * Input Array =
* array('children' => array( * ['children' => [
* 'child' => array( * 'child' => [
* array('name' => 'Wendy Darling'), * ['name' => 'Wendy Darling'],
* array('name' => 'John Darling'), * ['name' => 'John Darling'],
* array('name' => 'Michael Darling') * ['name' => 'Michael Darling'],
* ) * ],
* )) * ]]
* *
* Output XML = * Output XML =
* <children> * <children>
@ -68,7 +68,7 @@ class Convert
if (is_array($value2)) if (is_array($value2))
{ {
// Nest the value if the node is an integer // Nest the value if the node is an integer
$new_value = (is_int($node2) ? $value2 : array($node2 => $value2)); $new_value = (is_int($node2) ? $value2 : [$node2 => $value2]);
$xml .= ($format ? str_repeat("\t", $level) : ''); $xml .= ($format ? str_repeat("\t", $level) : '');
$xml .= '<' . $node . '>' . ($format ? "\n" : ''); $xml .= '<' . $node . '>' . ($format ? "\n" : '');

View file

@ -179,7 +179,11 @@ class Dynamic extends Object
{ {
// Minifies CSS with a few basic character replacements. // Minifies CSS with a few basic character replacements.
$stylesheet = file_get_contents($original_filename); $stylesheet = file_get_contents($original_filename);
$stylesheet = str_replace(array("\t", "\n", ', ', ' {', ': ', ';}', '{ ', '; '), array('', '', ',', '{', ':', '}', '{', ';'), $stylesheet); $stylesheet = str_replace(
["\t", "\n", ', ', ' {', ': ', ';}', '{ ', '; '],
['', '', ',', '{', ':', '}', '{', ';'],
$stylesheet
);
$stylesheet = preg_replace('/\/\*.+?\*\//', '', $stylesheet); $stylesheet = preg_replace('/\/\*.+?\*\//', '', $stylesheet);
file_put_contents($minified_filename, $stylesheet); file_put_contents($minified_filename, $stylesheet);

View file

@ -49,7 +49,7 @@ class File
// Loop through said files, check for directories, and unlink files // Loop through said files, check for directories, and unlink files
foreach ($files as $file) foreach ($files as $file)
{ {
if (!in_array($file, array('.', '..'))) if (!in_array($file, ['.', '..']))
{ {
if (is_dir($directory . $file)) if (is_dir($directory . $file))
{ {

View file

@ -64,7 +64,7 @@ class Form extends Object
$additional = ' ' . $additional; $additional = ' ' . $additional;
} }
if (in_array($type, array('checkbox', 'radio')) && $checked == true) if (in_array($type, ['checkbox', 'radio']) && $checked == true)
{ {
$additional .= ' checked="checked"'; $additional .= ' checked="checked"';
} }
@ -414,7 +414,7 @@ class Form extends Object
*/ */
public function stateSelect($name = 'state', $selected = null, $classes = null, $additional = null) public function stateSelect($name = 'state', $selected = null, $classes = null, $additional = null)
{ {
$options = array( $options = [
null => '-- Select State --', null => '-- Select State --',
'AK' => 'Alaska', 'AK' => 'Alaska',
'AL' => 'Alabama', 'AL' => 'Alabama',
@ -480,7 +480,7 @@ class Form extends Object
'AE' => 'Armed Forces Europe', 'AE' => 'Armed Forces Europe',
'AE' => 'Armed Forces Middle East', 'AE' => 'Armed Forces Middle East',
'AP' => 'Armed Forces Pacific' 'AP' => 'Armed Forces Pacific'
); ];
return $this->select($name, $options, $selected, $classes, $additional); return $this->select($name, $options, $selected, $classes, $additional);
} }
@ -517,7 +517,7 @@ class Form extends Object
list($selected_year, $selected_month, $selected_day) = explode('-', $selected); list($selected_year, $selected_month, $selected_day) = explode('-', $selected);
} }
$month_options = array( $month_options = [
null => 'Month', null => 'Month',
'01' => 'January', '01' => 'January',
'02' => 'February', '02' => 'February',
@ -531,10 +531,10 @@ class Form extends Object
'10' => 'October', '10' => 'October',
'11' => 'November', '11' => 'November',
'12' => 'December', '12' => 'December',
); ];
$day_options = array(null => 'Day'); $day_options = [null => 'Day'];
$year_options = array(null => 'Year'); $year_options = [null => 'Year'];
// Generates the list of days // Generates the list of days
for ($i = 1; $i <= 31; ++$i) for ($i = 1; $i <= 31; ++$i)
@ -553,7 +553,7 @@ class Form extends Object
} }
// Loops through and generates the selects // Loops through and generates the selects
foreach (array('month', 'day', 'year') as $part) foreach (['month', 'day', 'year'] as $part)
{ {
$options = $part . '_options'; $options = $part . '_options';
$selected = 'selected_' . $part; $selected = 'selected_' . $part;
@ -599,7 +599,7 @@ class Form extends Object
*/ */
public function polarSelect($name = 'decision', $selected = 0, $classes = null, $additional = null) public function polarSelect($name = 'decision', $selected = 0, $classes = null, $additional = null)
{ {
$options = array(1 => 'Yes', 0 => 'No'); $options = [1 => 'Yes', 0 => 'No'];
return $this->select($name, $options, $selected, $classes, $additional); return $this->select($name, $options, $selected, $classes, $additional);
} }
@ -621,27 +621,27 @@ class Form extends Object
{ {
if ($value == null) if ($value == null)
{ {
$value = array( $value = [
'area_code' => '', 'area_code' => '',
'prefix' => '', 'prefix' => '',
'line_number' => '' 'line_number' => ''
); ];
} }
else else
{ {
$value = str_replace('-', '', $value); $value = str_replace('-', '', $value);
$value = array( $value = [
'area_code' => substr($value, 0, 3), 'area_code' => substr($value, 0, 3),
'prefix' => substr($value, 3, 3), 'prefix' => substr($value, 3, 3),
'line_number' => substr($value, 6) 'line_number' => substr($value, 6)
); ];
} }
$parts = array( $parts = [
'area_code' => 3, 'area_code' => 3,
'prefix' => 3, 'prefix' => 3,
'line_number' => 4 'line_number' => 4
); ];
if ($additional) if ($additional)
{ {

View file

@ -58,7 +58,7 @@ class Model extends Object
* @access private * @access private
* @var array * @var array
*/ */
private $sql = array(); private $sql = [];
/** /**
* Input Parameters Array * Input Parameters Array
@ -66,7 +66,7 @@ class Model extends Object
* @access private * @access private
* @var array * @var array
*/ */
private $input_parameters = array(); private $input_parameters = [];
/** /**
* Insert Priority * Insert Priority
@ -258,7 +258,7 @@ class Model extends Object
* @access private * @access private
* @var array * @var array
*/ */
private $snapshot = array(); private $snapshot = [];
/** /**
* MySQL? * MySQL?
@ -322,7 +322,7 @@ class Model extends Object
$this->model = get_class($this); $this->model = get_class($this);
// Default column mapping // Default column mapping
$columns = array( $columns = [
'id' => 'id', 'id' => 'id',
'created_at' => 'created_at', 'created_at' => 'created_at',
'created_id' => 'created_id', 'created_id' => 'created_id',
@ -331,7 +331,7 @@ class Model extends Object
'deleted_at' => 'deleted_at', 'deleted_at' => 'deleted_at',
'deleted_id' => 'deleted_id', 'deleted_id' => 'deleted_id',
'is_deleted' => 'is_deleted', 'is_deleted' => 'is_deleted',
); ];
// Grabs the config columns if no columns are set // Grabs the config columns if no columns are set
if ($this->columns === null && isset($this->db->columns)) if ($this->columns === null && isset($this->db->columns))
@ -364,7 +364,7 @@ class Model extends Object
// Takes a snapshot of the [non-object] object properties // Takes a snapshot of the [non-object] object properties
foreach ($this as $variable => $value) foreach ($this as $variable => $value)
{ {
if (!in_array($variable, array('db', 'cache', 'config', 'snapshot'))) if (!in_array($variable, ['db', 'cache', 'config', 'snapshot']))
{ {
$this->snapshot[$variable] = $value; $this->snapshot[$variable] = $value;
} }
@ -411,12 +411,12 @@ class Model extends Object
&& count($type_or_parameters) == 1 && count($type_or_parameters) == 1
&& count($type_or_parameters['conditions']) == 1) && count($type_or_parameters['conditions']) == 1)
{ {
$cache_keys = array(); $cache_keys = [];
$sorted_records = array(); $sorted_records = [];
if (!is_array($type_or_parameters['conditions'][$this->columns['id']])) if (!is_array($type_or_parameters['conditions'][$this->columns['id']]))
{ {
$type_or_parameters['conditions'][$this->columns['id']] = array($type_or_parameters['conditions'][$this->columns['id']]); $type_or_parameters['conditions'][$this->columns['id']] = [$type_or_parameters['conditions'][$this->columns['id']]];
} }
foreach ($type_or_parameters['conditions'][$this->columns['id']] as $id) foreach ($type_or_parameters['conditions'][$this->columns['id']] as $id)
@ -426,7 +426,7 @@ class Model extends Object
} }
$cached = $this->cache->get($cache_keys); $cached = $this->cache->get($cache_keys);
$partial_cache = array(); $partial_cache = [];
if ($cached !== false) if ($cached !== false)
{ {
@ -469,8 +469,8 @@ class Model extends Object
&& count($parameters_or_key) == 1 && count($parameters_or_key) == 1
&& count($parameters_or_key['conditions']) == 1) && count($parameters_or_key['conditions']) == 1)
{ {
$cache_keys = array(); $cache_keys = [];
$sorted_records = array(); $sorted_records = [];
foreach ($parameters_or_key['conditions'][$this->columns['id']] as $id) foreach ($parameters_or_key['conditions'][$this->columns['id']] as $id)
{ {
@ -479,7 +479,7 @@ class Model extends Object
} }
$cached = $this->cache->get($cache_keys); $cached = $this->cache->get($cache_keys);
$partial_cache = array(); $partial_cache = [];
if ($cached !== false) if ($cached !== false)
{ {
@ -516,7 +516,7 @@ class Model extends Object
elseif (ctype_digit((string)$type_or_parameters)) elseif (ctype_digit((string)$type_or_parameters))
{ {
$cache_key = strtoupper($this->model) . '-' . $type_or_parameters; $cache_key = strtoupper($this->model) . '-' . $type_or_parameters;
$parameters_or_key = array($this->columns['id'] => $type_or_parameters); $parameters_or_key = [$this->columns['id'] => $type_or_parameters];
if ($this->columns['is_deleted']) if ($this->columns['is_deleted'])
{ {
@ -528,7 +528,7 @@ class Model extends Object
elseif (ctype_digit((string)$parameters_or_key)) elseif (ctype_digit((string)$parameters_or_key))
{ {
$cache_key = strtoupper($this->model) . '-' . $parameters_or_key; $cache_key = strtoupper($this->model) . '-' . $parameters_or_key;
$parameters_or_key = array($this->columns['id'] => $parameters_or_key); $parameters_or_key = [$this->columns['id'] => $parameters_or_key];
if ($this->columns['is_deleted']) if ($this->columns['is_deleted'])
{ {
@ -539,7 +539,7 @@ class Model extends Object
} }
elseif ($this->columns['is_deleted']) elseif ($this->columns['is_deleted'])
{ {
$this->loadParameters(array($this->columns['is_deleted'] => '0')); $this->loadParameters([$this->columns['is_deleted'] => '0']);
} }
if (is_string($parameters_or_key)) if (is_string($parameters_or_key))
@ -553,10 +553,10 @@ class Model extends Object
} }
// Starts with a basic SELECT ... FROM // Starts with a basic SELECT ... FROM
$this->sql = array( $this->sql = [
'SELECT ' . (is_array($this->fields) ? implode(', ', $this->fields) : $this->fields), 'SELECT ' . (is_array($this->fields) ? implode(', ', $this->fields) : $this->fields),
'FROM ' . $this->table, 'FROM ' . $this->table,
); ];
switch ($type_or_parameters) switch ($type_or_parameters)
{ {
@ -645,12 +645,12 @@ class Model extends Object
} }
} }
$index_records = in_array($type_or_parameters, array('list', 'indexed')); $index_records = in_array($type_or_parameters, ['list', 'indexed']);
// Flattens the data into a list // Flattens the data into a list
if ($index_records == true) if ($index_records == true)
{ {
$list = array(); $list = [];
foreach ($this->records as $record) foreach ($this->records as $record)
{ {
@ -713,7 +713,7 @@ class Model extends Object
{ {
foreach ($this->joins as $join => $tables) foreach ($this->joins as $join => $tables)
{ {
$join_pieces = array((stripos('JOIN ', $join) === false ? 'JOIN' : strtoupper($join))); $join_pieces = [(stripos('JOIN ', $join) === false ? 'JOIN' : strtoupper($join))];
if (is_array($tables)) if (is_array($tables))
{ {
@ -793,7 +793,7 @@ class Model extends Object
if ($use_id) if ($use_id)
{ {
$this->conditions = array($this->columns['id'] => $this->conditions); $this->conditions = [$this->columns['id'] => $this->conditions];
} }
$this->sql[] = 'WHERE ' . (is_array($this->conditions) ? $this->generateConditions($this->conditions) : $this->conditions); $this->sql[] = 'WHERE ' . (is_array($this->conditions) ? $this->generateConditions($this->conditions) : $this->conditions);
@ -1237,7 +1237,7 @@ class Model extends Object
if ($this->commit_type == 'queue') if ($this->commit_type == 'queue')
{ {
$update = false; $update = false;
$cache_keys = array(); $cache_keys = [];
/** /**
* @todo I outta loop through twice to determine if it's an INSERT * @todo I outta loop through twice to determine if it's an INSERT
@ -1256,10 +1256,10 @@ class Model extends Object
if (!isset($sql)) if (!isset($sql))
{ {
$sql = ''; $sql = '';
$input_parameters = array(); $input_parameters = [];
} }
$update_fields = array(); $update_fields = [];
foreach ($record as $field => $value) foreach ($record as $field => $value)
{ {
@ -1326,7 +1326,7 @@ class Model extends Object
} }
$values = '(' . implode(', ', array_fill(0, $field_count, '?')) . ')'; $values = '(' . implode(', ', array_fill(0, $field_count, '?')) . ')';
$input_parameters = array(); $input_parameters = [];
// INSERT INTO ... // INSERT INTO ...
$sql = 'INSERT INTO ' . $this->table . ' (' . implode(', ', $insert_fields) . ') VALUES ' . $values; $sql = 'INSERT INTO ' . $this->table . ' (' . implode(', ', $insert_fields) . ') VALUES ' . $values;
@ -1409,7 +1409,8 @@ class Model extends Object
// PRIORITY syntax takes priority over DELAYED // PRIORITY syntax takes priority over DELAYED
if ($this->mysql) if ($this->mysql)
{ {
if ($this->priority !== false && in_array(strtoupper($this->priority), array('LOW', 'HIGH'))) if ($this->priority !== false
&& in_array(strtoupper($this->priority), ['LOW', 'HIGH']))
{ {
$sql .= ' ' . strtoupper($this->priority) . '_PRIORITY'; $sql .= ' ' . strtoupper($this->priority) . '_PRIORITY';
} }
@ -1433,12 +1434,15 @@ class Model extends Object
$input_parameters = null; $input_parameters = null;
// Limits the columns being updated // Limits the columns being updated
$record = ($update ? array_diff_assoc($this->record, isset($this->original[$this->index]) ? $this->original[$this->index] : array()) : $this->record); $record = ($update ? array_diff_assoc(
$this->record,
isset($this->original[$this->index]) ? $this->original[$this->index] : []
) : $this->record);
// Makes sure there's something to INSERT or UPDATE // Makes sure there's something to INSERT or UPDATE
if (count($record) > 0) if (count($record) > 0)
{ {
$insert_fields = array(); $insert_fields = [];
// Loops through all the columns and assembles the query // Loops through all the columns and assembles the query
foreach ($record as $column => $value) foreach ($record as $column => $value)
@ -1454,7 +1458,7 @@ class Model extends Object
$sql .= $column . ' = '; $sql .= $column . ' = ';
if (in_array($value, array('++', '--'))) if (in_array($value, ['++', '--']))
{ {
$sql .= $column . ' ' . substr($value, 0, 1) . ' ?'; $sql .= $column . ' ' . substr($value, 0, 1) . ' ?';
$value = 1; $value = 1;
@ -1566,7 +1570,7 @@ class Model extends Object
if ($this->columns['is_deleted']) if ($this->columns['is_deleted'])
{ {
$sql = 'UPDATE ' . $this->table . ' SET ' . $this->columns['is_deleted'] . ' = ?'; $sql = 'UPDATE ' . $this->table . ' SET ' . $this->columns['is_deleted'] . ' = ?';
$input_parameters = array('1'); $input_parameters = ['1'];
if ($this->columns['deleted_at']) if ($this->columns['deleted_at'])
{ {
@ -1631,7 +1635,7 @@ class Model extends Object
if ($all_integers) if ($all_integers)
{ {
$parameters = array('conditions' => array($this->columns['id'] => $parameters)); $parameters = ['conditions' => [$this->columns['id'] => $parameters]];
} }
} }
@ -1657,7 +1661,7 @@ class Model extends Object
$key = trim(strtolower($key)); $key = trim(strtolower($key));
// Assigns valid keys to the appropriate class property // Assigns valid keys to the appropriate class property
if (in_array($key, array('fields', 'table', 'joins', 'hints', 'conditions', 'group', 'having', 'order', 'limit', 'offset'))) if (in_array($key, ['fields', 'table', 'joins', 'hints', 'conditions', 'group', 'having', 'order', 'limit', 'offset']))
{ {
$this->$key = $value; $this->$key = $value;
$conditions = false; $conditions = false;
@ -1706,7 +1710,7 @@ class Model extends Object
*/ */
public function fieldValues($field) public function fieldValues($field)
{ {
$values = array(); $values = [];
foreach ($this->records as $record) foreach ($this->records as $record)
{ {

View file

@ -146,7 +146,7 @@ class Module extends Object
* @todo Move to public scope and rename __return so it's kinda obscured * @todo Move to public scope and rename __return so it's kinda obscured
* @todo Will need to update leaderbin and sndcrd to use new variable * @todo Will need to update leaderbin and sndcrd to use new variable
*/ */
protected $return = array(); protected $return = [];
/** /**
* Output * Output
@ -264,7 +264,7 @@ class Module extends Object
*/ */
public function __validate() public function __validate()
{ {
$errors = array(); $errors = [];
if ($this->validate !== false) if ($this->validate !== false)
{ {
@ -307,7 +307,7 @@ class Module extends Object
} }
} }
return $errors == array() ? false : $errors; return $errors == [] ? false : $errors;
} }
} }

View file

@ -37,7 +37,7 @@ class Number
*/ */
public static function ordinalIndicator($number, $superscript = false) public static function ordinalIndicator($number, $superscript = false)
{ {
if (!in_array(($number % 100), array(11, 12, 13))) if (!in_array(($number % 100), [11, 12, 13]))
{ {
switch ($number % 10) switch ($number % 10)
{ {

View file

@ -35,7 +35,7 @@ class Security
* @access private * @access private
* @var array * @var array
*/ */
private static $cache = array(); private static $cache = [];
/** /**
* Generate Hash * Generate Hash
@ -60,14 +60,14 @@ class Security
} }
else else
{ {
$salts = array('P1ck73', 'Ju1C3'); $salts = ['P1ck73', 'Ju1C3'];
} }
} }
// Forces the variable to be an array // Forces the variable to be an array
if (!is_array($salts)) if (!is_array($salts))
{ {
$salts = array($salts); $salts = [$salts];
} }
// Loops through the salts, applies them and calculates the hash // Loops through the salts, applies them and calculates the hash
@ -163,12 +163,12 @@ class Security
{ {
$token = sha1(microtime()); $token = sha1(microtime());
$_SESSION['__pickles']['security'] = array( $_SESSION['__pickles']['security'] = [
'token' => $token, 'token' => $token,
'user_id' => (int)$user_id, 'user_id' => (int)$user_id,
'level' => $level, 'level' => $level,
'role' => $role, 'role' => $role,
); ];
setcookie('pickles_security_token', $token); setcookie('pickles_security_token', $token);
@ -240,14 +240,19 @@ class Security
if ($config->security === false) if ($config->security === false)
{ {
$config = array(); $config = [];
} }
else else
{ {
$config = $config->security; $config = $config->security;
} }
$defaults = array('login' => 'login', 'model' => 'User', 'column' => 'level'); $defaults = [
'login' => 'login',
'model' => 'User',
'column' => 'level',
];
foreach ($defaults as $variable => $value) foreach ($defaults as $variable => $value)
{ {
if (!isset($config[$variable])) if (!isset($config[$variable]))
@ -258,7 +263,12 @@ class Security
// Uses the model to pull the user's access level // Uses the model to pull the user's access level
$class = $config['model']; $class = $config['model'];
$model = new $class(array('fields' => $config['column'], 'conditions' => array('id' => (int)$_SESSION['__pickles']['security']['user_id']))); $model = new $class([
'fields' => $config['column'],
'conditions' => [
'id' => (int)$_SESSION['__pickles']['security']['user_id'],
],
]);
if ($model->count() == 0) if ($model->count() == 0)
{ {

View file

@ -19,11 +19,10 @@
* Session Class * Session Class
* *
* Provides session handling via database instead of the file based session * Provides session handling via database instead of the file based session
* handling built into PHP. Using this class requires an array to be * handling built into PHP. Using this class requires an array to be defined
* defined in place of the boolean true/false (on/off). If simply array(), * in place of the boolean true/false (on/off). If simply an empty array, the
* the datasource will default to the value in * datasource will default to the value in $config['pickles']['datasource'] and
* $config['pickles']['datasource'] and if the table will default to * if the table will default to "sessions". The format is as follows:
* "sessions". The format is as follows:
*/ */
class Session extends Object class Session extends Object
{ {

View file

@ -38,7 +38,7 @@ class String
public static function formatPhoneNumber($number, $replacement = '$1-$2-$3') public static function formatPhoneNumber($number, $replacement = '$1-$2-$3')
{ {
// Strips characters we don't need // Strips characters we don't need
$number = str_replace(array('(', ')', ' ', '-', '.', '_'), '', $number); $number = str_replace(['(', ')', ' ', '-', '.', '_'], '', $number);
// Formats the number // Formats the number
return preg_replace('/^(\d{3})(\d{3})(.+)$/', $replacement, $number); return preg_replace('/^(\d{3})(\d{3})(.+)$/', $replacement, $number);
@ -162,7 +162,7 @@ class String
*/ */
public static function random($length = 8, $alpha = true, $numeric = true, $similar = true) public static function random($length = 8, $alpha = true, $numeric = true, $similar = true)
{ {
$characters = array(); $characters = [];
$string = ''; $string = '';
// Adds alpha characters to the list // Adds alpha characters to the list

View file

@ -35,7 +35,7 @@ class Validate
*/ */
public static function isValid($value, $rules) public static function isValid($value, $rules)
{ {
$errors = array(); $errors = [];
if (is_array($rules)) if (is_array($rules))
{ {

View file

@ -10,9 +10,10 @@ class CacheTest extends PHPUnit_Framework_TestCase
$this->config = Config::getInstance(); $this->config = Config::getInstance();
$this->config->data['pickles']['cache'] = 'mc'; $this->config->data['pickles']['cache'] = 'mc';
$this->config->data['datasources']['mc'] = [ $this->config->data['datasources']['mc'] = [
'type' => 'memcache', 'type' => 'memcache',
'hostname' => 'localhost', 'hostname' => 'localhost',
'port' => 11211, 'port' => 11211,
'namespace' => 'ns',
]; ];
$this->cache = Cache::getInstance(); $this->cache = Cache::getInstance();
@ -46,7 +47,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
foreach ($keys as $key => $key_name) foreach ($keys as $key => $key_name)
{ {
$value = $values[$key]; $value = $values[$key];
$expected[strtoupper($key_name)] = $value; $expected['NS-' . strtoupper($key_name)] = $value;
$this->cache->set($key_name, $value); $this->cache->set($key_name, $value);
} }