Refactor leftover old-style arrays into new-style arrays.

This commit is contained in:
Aaron van Geffen 2019-09-29 14:47:56 +02:00
parent 3694819d13
commit c48ba786c1
5 changed files with 56 additions and 59 deletions

View File

@ -25,7 +25,7 @@ class Download extends HTMLController
throw new UnexpectedValueException('Specified tag does not correspond to an album');
//Yes TOCTOU but it does not need to be perfect.
$lock_file = join('/', array(sys_get_temp_dir(), 'pics-export.lock'));
$lock_file = join('/', [sys_get_temp_dir(), 'pics-export.lock']);
if(!file_exists($lock_file))
{
try
@ -34,12 +34,12 @@ class Download extends HTMLController
if(!$fp)
throw new UnexpectedValueException('Could not open lock-file');
$this->exportAlbum($album);
}
finally
{
fclose($fp);
fclose($fp);
unlink($lock_file);
}
}
@ -51,26 +51,26 @@ class Download extends HTMLController
private function exportAlbum($album)
{
$files = array();
$files = [];
$album_ids = array_merge(array($album->id_tag), $this->getChildAlbumIds($album->id_tag));
$album_ids = array_merge([$album->id_tag], $this->getChildAlbumIds($album->id_tag));
foreach($album_ids as $album_id)
{
$iterator = AssetIterator::getByOptions(
array(
[
'id_tag' => $album_id
)
]
);
while($asset = $iterator->Next())
{
$files[] = join(DIRECTORY_SEPARATOR, array('.', $asset->getSubdir(), $asset->getFilename()));
$files[] = join(DIRECTORY_SEPARATOR, ['.', $asset->getSubdir(), $asset->getFilename()]);
}
}
$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
);
$descriptorspec = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
];
$command = 'tar --null -cf - -T -';
@ -108,7 +108,7 @@ class Download extends HTMLController
private function getChildAlbumIds($parent_id)
{
$ids = array();
$ids = [];
$albums = Tag::getAlbums($parent_id, 0, PHP_INT_MAX, 'object');
foreach($albums as $album)

View File

@ -53,7 +53,7 @@ class ProvideAutoSuggest extends JSONController
// It better not already exist!
if (Tag::exactMatch($_REQUEST['tag']))
{
$this->payload = ['error' => true, 'msg' => "Tag already exists!"];
$this->payload = ['error' => true, 'msg' => 'Tag already exists!'];
return;
}
@ -68,7 +68,7 @@ class ProvideAutoSuggest extends JSONController
// Did we succeed?
if (!$tag)
{
$this->payload = ['error' => true, 'msg' => "Could not create tag."];
$this->payload = ['error' => true, 'msg' => 'Could not create tag.'];
return;
}

View File

@ -37,7 +37,7 @@ class Database
exit;
}
$this->query('SET NAMES {string:utf8}', array('utf8' => 'utf8'));
$this->query('SET NAMES {string:utf8}', ['utf8' => 'utf8']);
}
public function getQueryCount()
@ -256,7 +256,7 @@ class Database
case 'identifier':
// Backticks inside identifiers are supported as of MySQL 4.1. We don't need them here.
return '`' . strtr($replacement, array('`' => '', '.' => '')) . '`';
return '`' . strtr($replacement, ['`' => '', '.' => '']) . '`';
break;
case 'raw':
@ -278,7 +278,7 @@ class Database
/**
* Escapes and quotes a string using values passed, and executes the query.
*/
public function query($db_string, $db_values = array())
public function query($db_string, $db_values = [])
{
// One more query....
$this->query_count ++;
@ -293,10 +293,10 @@ class Database
if (!$security_override && !empty($db_values))
{
// Set some values for use in the callback function.
$this->db_callback = array($db_values, $this->connection);
$this->db_callback = [$db_values, $this->connection];
// Insert the values passed to this function.
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', array(&$this, 'replacement_callback'), $db_string);
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', [&$this, 'replacement_callback'], $db_string);
// Save some memory.
$this->db_callback = [];
@ -320,20 +320,20 @@ class Database
* Escapes and quotes a string just like db_query, but does not execute the query.
* Useful for debugging purposes.
*/
public function quote($db_string, $db_values = array())
public function quote($db_string, $db_values = [])
{
// Please, just use new style queries.
if (strpos($db_string, '\'') !== false)
trigger_error('Hack attempt!', 'Illegal character (\') used in query.', E_USER_ERROR);
// Save some values for use in the callback function.
$this->db_callback = array($db_values, $this->connection);
$this->db_callback = [$db_values, $this->connection];
// Insert the values passed to this function.
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', array(&$this, 'replacement_callback'), $db_string);
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', [&$this, 'replacement_callback'], $db_string);
// Save some memory.
$this->db_callback = array();
$this->db_callback = [];
return $db_string;
}
@ -341,12 +341,12 @@ class Database
/**
* Executes a query, returning an array of all the rows it returns.
*/
public function queryRow($db_string, $db_values = array())
public function queryRow($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$row = $this->fetch_row($res);
$this->free_result($res);
@ -357,14 +357,14 @@ class Database
/**
* Executes a query, returning an array of all the rows it returns.
*/
public function queryRows($db_string, $db_values = array())
public function queryRows($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$rows = array();
$rows = [];
while ($row = $this->fetch_row($res))
$rows[] = $row;
@ -376,14 +376,14 @@ class Database
/**
* Executes a query, returning an array of all the rows it returns.
*/
public function queryPair($db_string, $db_values = array())
public function queryPair($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$rows = array();
$rows = [];
while ($row = $this->fetch_row($res))
$rows[$row[0]] = $row[1];
@ -395,14 +395,14 @@ class Database
/**
* Executes a query, returning an array of all the rows it returns.
*/
public function queryPairs($db_string, $db_values = array())
public function queryPairs($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$rows = array();
$rows = [];
while ($row = $this->fetch_assoc($res))
{
$key_value = reset($row);
@ -417,12 +417,12 @@ class Database
/**
* Executes a query, returning an associative array of all the rows it returns.
*/
public function queryAssoc($db_string, $db_values = array())
public function queryAssoc($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$row = $this->fetch_assoc($res);
$this->free_result($res);
@ -433,14 +433,14 @@ class Database
/**
* Executes a query, returning an associative array of all the rows it returns.
*/
public function queryAssocs($db_string, $db_values = array(), $connection = null)
public function queryAssocs($db_string, $db_values = [], $connection = null)
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$rows = array();
$rows = [];
while ($row = $this->fetch_assoc($res))
$rows[] = $row;
@ -452,7 +452,7 @@ class Database
/**
* Executes a query, returning the first value of the first row.
*/
public function queryValue($db_string, $db_values = array())
public function queryValue($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
@ -469,14 +469,14 @@ class Database
/**
* Executes a query, returning an array of the first value of each row.
*/
public function queryValues($db_string, $db_values = array())
public function queryValues($db_string, $db_values = [])
{
$res = $this->query($db_string, $db_values);
if (!$res || $this->num_rows($res) == 0)
return array();
return [];
$rows = array();
$rows = [];
while ($row = $this->fetch_row($res))
$rows[] = $row[0];
@ -496,7 +496,7 @@ class Database
// Inserting data as a single row can be done as a single array.
if (!is_array($data[array_rand($data)]))
$data = array($data);
$data = [$data];
// Create the mold for a single row insert.
$insertData = '(';
@ -514,7 +514,7 @@ class Database
$indexed_columns = array_keys($columns);
// Here's where the variables are injected to the query.
$insertRows = array();
$insertRows = [];
foreach ($data as $dataRow)
$insertRows[] = $this->quote($insertData, array_combine($indexed_columns, $dataRow));
@ -527,9 +527,6 @@ class Database
VALUES
' . implode(',
', $insertRows),
array(
'security_override' => true,
)
);
['security_override' => true]);
}
}

View File

@ -30,14 +30,14 @@ class GenericTable extends PageIndex
$options['sort_order'] = '';
// Order in which direction?
if (!empty($options['sort_direction']) && !in_array($options['sort_direction'], array('up', 'down')))
if (!empty($options['sort_direction']) && !in_array($options['sort_direction'], ['up', 'down']))
$options['sort_direction'] = 'up';
// Make sure we know whether we can actually sort on something.
$this->tableIsSortable = !empty($options['base_url']);
// How much stuff do we have?
$this->recordCount = call_user_func_array($options['get_count'], !empty($options['get_count_params']) ? $options['get_count_params'] : array());
$this->recordCount = call_user_func_array($options['get_count'], !empty($options['get_count_params']) ? $options['get_count_params'] : []);
// Should we create a page index?
$this->items_per_page = !empty($options['items_per_page']) ? $options['items_per_page'] : 30;
@ -55,7 +55,7 @@ class GenericTable extends PageIndex
$options['no_items_label'] = '';
// Gather parameters for the data gather function first.
$parameters = array($this->start, $this->items_per_page, $options['sort_order'], $options['sort_direction']);
$parameters = [$this->start, $this->items_per_page, $options['sort_order'], $options['sort_direction']];
if (!empty($options['get_data_params']) && is_array($options['get_data_params']))
$parameters = array_merge($parameters, $options['get_data_params']);
@ -98,7 +98,7 @@ class GenericTable extends PageIndex
if (empty($column['header']))
continue;
$header = array(
$header = [
'class' => isset($column['class']) ? $column['class'] : '',
'colspan' => !empty($column['header_colspan']) ? $column['header_colspan'] : 1,
'href' => !$this->tableIsSortable || empty($column['is_sortable']) ? '' : $this->getLink($this->start, $key, $key == $this->sort_order && $this->sort_direction == 'up' ? 'down' : 'up'),
@ -106,7 +106,7 @@ class GenericTable extends PageIndex
'scope' => 'col',
'sort_mode' => $key == $this->sort_order ? $this->sort_direction : null,
'width' => !empty($column['header_width']) && is_int($column['header_width']) ? $column['header_width'] : null,
);
];
$this->header[] = $header;
}
@ -147,7 +147,7 @@ class GenericTable extends PageIndex
// sprintf: filling the gaps!
case 'sprintf':
$parameters = array($column['parse']['data']['pattern']);
$parameters = [$column['parse']['data']['pattern']];
foreach ($column['parse']['data']['arguments'] as $identifier)
$parameters[] = $row[$identifier];
$value = call_user_func_array('sprintf', $parameters);
@ -196,10 +196,10 @@ class GenericTable extends PageIndex
$value = $row[$column['value']];
// Append the cell to the row.
$newRow['cells'][] = array(
$newRow['cells'][] = [
'width' => !empty($column['cell_width']) && is_int($column['cell_width']) ? $column['cell_width'] : null,
'value' => $value,
);
];
}
// Append the new row in the body.

View File

@ -8,7 +8,7 @@
abstract class Template
{
protected $_subtemplates = array();
protected $_subtemplates = [];
abstract public function html_main();