Use short array declaration

This commit is contained in:
Romain Neutron
2013-11-18 11:58:12 +01:00
parent 2898b317c4
commit 56b373ee6e
723 changed files with 8350 additions and 8352 deletions

View File

@@ -190,7 +190,7 @@ abstract class base implements cache_cacheableInterface
{
$appbox = $this->get_base_type() == self::APPLICATION_BOX ? $this : $this->get_appbox();
if ($option === appbox::CACHE_LIST_BASES) {
$keys = array($this->get_cache_key(appbox::CACHE_LIST_BASES));
$keys = [$this->get_cache_key(appbox::CACHE_LIST_BASES)];
phrasea::reset_sbasDatas($appbox);
phrasea::reset_baseDatas($appbox);
phrasea::clear_sbas_params($this->app);
@@ -244,9 +244,9 @@ abstract class base implements cache_cacheableInterface
protected function upgradeDb($apply_patches, Setup_Upgrade $upgrader, Application $app)
{
$recommends = array();
$recommends = [];
$allTables = array();
$allTables = [];
$schema = $this->get_schema();
@@ -262,7 +262,7 @@ abstract class base implements cache_cacheableInterface
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$ORMTables = array(
$ORMTables = [
'AuthFailures',
'AggregateTokens',
'BasketElements',
@@ -296,7 +296,7 @@ abstract class base implements cache_cacheableInterface
'UserSettings',
'Users',
'UserNotificationSettings',
);
];
foreach ($rs as $row) {
$tname = $row["Name"];
@@ -306,17 +306,17 @@ abstract class base implements cache_cacheableInterface
$engine = strtolower(trim($allTables[$tname]->engine));
$ref_engine = strtolower($row['Engine']);
if ($engine != $ref_engine && in_array($engine, array('innodb', 'myisam'))) {
if ($engine != $ref_engine && in_array($engine, ['innodb', 'myisam'])) {
$sql = 'ALTER TABLE `' . $tname . '` ENGINE = ' . $engine;
try {
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
$recommends[] = array(
$recommends[] = [
'message' => sprintf(_('Erreur lors de la tentative ; errreur : %s'), $e->getMessage()),
'sql' => $sql
);
];
}
}
@@ -325,10 +325,10 @@ abstract class base implements cache_cacheableInterface
unset($allTables[$tname]);
$upgrader->add_steps_complete(1);
} elseif ( ! in_array($tname, $ORMTables)) {
$recommends[] = array(
$recommends[] = [
'message' => 'Une table pourrait etre supprime',
'sql' => 'DROP TABLE ' . $this->dbname . '.`' . $tname . '`;'
);
];
}
}
@@ -361,7 +361,7 @@ abstract class base implements cache_cacheableInterface
}
if ($sql !== '') {
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute(array(':version' => $version->getNumber()));
$stmt->execute([':version' => $version->getNumber()]);
$stmt->closeCursor();
$this->version = $version->getNumber();
@@ -423,7 +423,7 @@ abstract class base implements cache_cacheableInterface
*/
protected function createTable(SimpleXMLElement $table)
{
$field_stmt = $defaults_stmt = array();
$field_stmt = $defaults_stmt = [];
$create_stmt = "CREATE TABLE `" . $table['name'] . "` (";
@@ -438,9 +438,9 @@ abstract class base implements cache_cacheableInterface
$is_default = '';
$character_set = '';
if (in_array(strtolower((string) $field->type), array('text', 'longtext', 'mediumtext', 'tinytext'))
if (in_array(strtolower((string) $field->type), ['text', 'longtext', 'mediumtext', 'tinytext'])
|| substr(strtolower((string) $field->type), 0, 7) == 'varchar'
|| in_array(substr(strtolower((string) $field->type), 0, 4), array('char', 'enum'))) {
|| in_array(substr(strtolower((string) $field->type), 0, 4), ['char', 'enum'])) {
$collation = trim((string) $field->collation) != '' ? trim((string) $field->collation) : 'utf8_unicode_ci';
@@ -459,7 +459,7 @@ abstract class base implements cache_cacheableInterface
foreach ($table->indexes->index as $index) {
switch ($index->type) {
case "PRIMARY":
$primary_fields = array();
$primary_fields = [];
foreach ($index->fields->field as $field) {
$primary_fields[] = "`" . $field . "`";
@@ -468,7 +468,7 @@ abstract class base implements cache_cacheableInterface
$field_stmt[] = 'PRIMARY KEY (' . implode(',', $primary_fields) . ')';
break;
case "UNIQUE":
$unique_fields = array();
$unique_fields = [];
foreach ($index->fields->field as $field) {
$unique_fields[] = "`" . $field . "`";
@@ -477,7 +477,7 @@ abstract class base implements cache_cacheableInterface
$field_stmt[] = 'UNIQUE KEY `' . $index->name . '` (' . implode(',', $unique_fields) . ')';
break;
case "INDEX":
$index_fields = array();
$index_fields = [];
foreach ($index->fields->field as $field) {
$index_fields[] = "`" . $field . "`";
@@ -490,7 +490,7 @@ abstract class base implements cache_cacheableInterface
}
if ($table->defaults) {
foreach ($table->defaults->default as $default) {
$k = $v = $params = $dates_values = array();
$k = $v = $params = $dates_values = [];
$nonce = random::generatePassword(16);
foreach ($default->data as $data) {
$k = trim($data['key']);
@@ -498,7 +498,7 @@ abstract class base implements cache_cacheableInterface
$data = $this->app['auth.password-encoder']->encodePassword($data, $nonce);
if ($k === 'nonce')
$data = $nonce;
$v = trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $data));
$v = trim(str_replace(["\r\n", "\r", "\n", "\t"], '', $data));
if (trim(mb_strtolower($v)) == 'now()')
$dates_values [$k] = 'NOW()';
@@ -508,19 +508,19 @@ abstract class base implements cache_cacheableInterface
$separator = ((count($params) > 0 && count($dates_values) > 0) ? ', ' : '');
$defaults_stmt[] = array(
$defaults_stmt[] = [
'sql' =>
'INSERT INTO `' . $table['name'] . '` (' . implode(', ', array_keys($params))
. $separator . implode(', ', array_keys($dates_values)) . ')
VALUES (:' . implode(', :', array_keys($params))
. $separator . implode(', ', array_values($dates_values)) . ') '
, 'params' => $params
);
];
}
}
$engine = mb_strtolower(trim($table->engine));
$engine = in_array($engine, array('innodb', 'myisam')) ? $engine : 'innodb';
$engine = in_array($engine, ['innodb', 'myisam']) ? $engine : 'innodb';
$create_stmt .= implode(',', $field_stmt);
$create_stmt .= ") ENGINE=" . $engine . " CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
@@ -535,10 +535,10 @@ abstract class base implements cache_cacheableInterface
$stmt->execute($def['params']);
$stmt->closeCursor();
} catch (Exception $e) {
$recommends[] = array(
$recommends[] = [
'message' => sprintf(_('Erreur lors de la tentative ; errreur : %s'), $e->getMessage()),
'sql' => $def['sql']
);
];
}
}
@@ -547,8 +547,8 @@ abstract class base implements cache_cacheableInterface
protected function upgradeTable(SimpleXMLElement $table)
{
$correct_table = array('fields' => array(), 'indexes' => array(), 'collation' => array());
$alter = $alter_pre = $return = array();
$correct_table = ['fields' => [], 'indexes' => [], 'collation' => []];
$alter = $alter_pre = $return = [];
foreach ($table->fields->field as $field) {
$expr = trim((string) $field->type);
@@ -559,9 +559,9 @@ abstract class base implements cache_cacheableInterface
$collation = trim((string) $field->collation) != '' ? trim((string) $field->collation) : 'utf8_unicode_ci';
if (in_array(strtolower((string) $field->type), array('text', 'longtext', 'mediumtext', 'tinytext'))
if (in_array(strtolower((string) $field->type), ['text', 'longtext', 'mediumtext', 'tinytext'])
|| substr(strtolower((string) $field->type), 0, 7) == 'varchar'
|| in_array(substr(strtolower((string) $field->type), 0, 4), array('char', 'enum'))) {
|| in_array(substr(strtolower((string) $field->type), 0, 4), ['char', 'enum'])) {
$collations = array_reverse(explode('_', $collation));
$code = array_pop($collations);
@@ -587,7 +587,7 @@ abstract class base implements cache_cacheableInterface
if ($table->indexes) {
foreach ($table->indexes->index as $index) {
$i_name = (string) $index->name;
$expr = array();
$expr = [];
foreach ($index->fields->field as $field)
$expr[] = '`' . trim((string) $field) . '`';
@@ -682,10 +682,10 @@ abstract class base implements cache_cacheableInterface
}
unset($correct_table['fields'][$f_name]);
} else {
$return[] = array(
$return[] = [
'message' => 'Un champ pourrait etre supprime',
'sql' => "ALTER TABLE " . $this->dbname . ".`" . $table['name'] . "` DROP `$f_name`;"
);
];
}
}
@@ -693,7 +693,7 @@ abstract class base implements cache_cacheableInterface
$alter[] = "ALTER TABLE `" . $table['name'] . "` ADD `$f_name` " . $correct_table['fields'][$f_name];
}
$tIndex = array();
$tIndex = [];
$sql = "SHOW INDEXES FROM `" . $table['name'] . "`";
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute();
@@ -702,12 +702,12 @@ abstract class base implements cache_cacheableInterface
foreach ($rs2 as $row2) {
if ( ! isset($tIndex[$row2['Key_name']]))
$tIndex[$row2['Key_name']] = array('unique' => ((int) ($row2['Non_unique']) == 0), 'columns' => array());
$tIndex[$row2['Key_name']] = ['unique' => ((int) ($row2['Non_unique']) == 0), 'columns' => []];
$tIndex[$row2['Key_name']]['columns'][(int) ($row2['Seq_in_index'])] = $row2['Column_name'];
}
foreach ($tIndex as $kIndex => $vIndex) {
$strColumns = array();
$strColumns = [];
foreach ($vIndex['columns'] as $column)
$strColumns[] = '`' . $column . '`';
@@ -733,10 +733,10 @@ abstract class base implements cache_cacheableInterface
unset($correct_table['indexes'][$kIndex]);
} else {
$return[] = array(
$return[] = [
'message' => 'Un index pourrait etre supprime',
'sql' => 'ALTER TABLE ' . $this->dbname . '.`' . $table['name'] . '` DROP ' . $full_name_index . ';'
);
];
}
}
@@ -749,10 +749,10 @@ abstract class base implements cache_cacheableInterface
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
$return[] = array(
$return[] = [
'message' => sprintf(_('Erreur lors de la tentative ; errreur : %s'), $e->getMessage()),
'sql' => $a
);
];
}
}
@@ -762,10 +762,10 @@ abstract class base implements cache_cacheableInterface
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
$return[] = array(
$return[] = [
'message' => sprintf(_('Erreur lors de la tentative ; errreur : %s'), $e->getMessage()),
'sql' => $a
);
];
}
}
@@ -778,7 +778,7 @@ abstract class base implements cache_cacheableInterface
return true;
}
$list_patches = array();
$list_patches = [];
$upgrader->add_steps(1)->set_current_message(_('Looking for patches'));