Skip to content

Commit 9ff0956

Browse files
committed
used PHP 5.4 syntax
1 parent 62d6c08 commit 9ff0956

File tree

86 files changed

+966
-966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+966
-966
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ matrix:
1313

1414
script:
1515
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
16-
- php code-checker/src/code-checker.php
16+
- php temp/code-checker/src/code-checker.php --short-arrays
1717

1818
after_failure:
1919
# Print *.actual content
@@ -22,7 +22,7 @@ after_failure:
2222
before_script:
2323
# Install Nette Tester & Code Checker
2424
- composer install --no-interaction --prefer-source
25-
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
25+
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source
2626

2727
# Create databases.ini
2828
- cp ./tests/Database/databases.sample.ini ./tests/Database/databases.ini

src/Bridges/DatabaseDI/DatabaseExtension.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class DatabaseExtension extends Nette\DI\CompilerExtension
2020
{
21-
public $databaseDefaults = array(
21+
public $databaseDefaults = [
2222
'dsn' => NULL,
2323
'user' => NULL,
2424
'password' => NULL,
@@ -28,7 +28,7 @@ class DatabaseExtension extends Nette\DI\CompilerExtension
2828
'reflection' => NULL, // BC
2929
'conventions' => 'discovered', // Nette\Database\Conventions\DiscoveredConventions
3030
'autowired' => NULL,
31-
);
31+
];
3232

3333
/** @var bool */
3434
private $debugMode;
@@ -44,7 +44,7 @@ public function loadConfiguration()
4444
{
4545
$configs = $this->getConfig();
4646
if (isset($configs['dsn'])) {
47-
$configs = array('default' => $configs);
47+
$configs = ['default' => $configs];
4848
}
4949

5050
$defaults = $this->databaseDefaults;
@@ -72,12 +72,12 @@ private function setupDatabase($config, $name)
7272
}
7373

7474
$connection = $container->addDefinition($this->prefix("$name.connection"))
75-
->setClass('Nette\Database\Connection', array($config['dsn'], $config['user'], $config['password'], $config['options']))
75+
->setClass('Nette\Database\Connection', [$config['dsn'], $config['user'], $config['password'], $config['options']])
7676
->setAutowired($config['autowired']);
7777

7878
$structure = $container->addDefinition($this->prefix("$name.structure"))
7979
->setClass('Nette\Database\Structure')
80-
->setArguments(array($connection))
80+
->setArguments([$connection])
8181
->setAutowired($config['autowired']);
8282

8383
if (!empty($config['reflection'])) {
@@ -98,24 +98,24 @@ private function setupDatabase($config, $name)
9898
->setClass(preg_match('#^[a-z]+\z#i', $config['conventions'])
9999
? 'Nette\Database\Conventions\\' . ucfirst($config['conventions']) . 'Conventions'
100100
: $config['conventions'])
101-
->setArguments(strtolower($config['conventions']) === 'discovered' ? array($structure) : array())
101+
->setArguments(strtolower($config['conventions']) === 'discovered' ? [$structure] : [])
102102
->setAutowired($config['autowired']);
103103

104104
} else {
105-
$tmp = Nette\DI\Compiler::filterArguments(array($config['conventions']));
105+
$tmp = Nette\DI\Compiler::filterArguments([$config['conventions']]);
106106
$conventions = reset($tmp);
107107
}
108108

109109
$container->addDefinition($this->prefix("$name.context"))
110-
->setClass('Nette\Database\Context', array($connection, $structure, $conventions))
110+
->setClass('Nette\Database\Context', [$connection, $structure, $conventions])
111111
->setAutowired($config['autowired']);
112112

113113
if ($config['debugger']) {
114-
$connection->addSetup('@Tracy\BlueScreen::addPanel', array(
114+
$connection->addSetup('@Tracy\BlueScreen::addPanel', [
115115
'Nette\Bridges\DatabaseTracy\ConnectionPanel::renderException'
116-
));
116+
]);
117117
if ($this->debugMode) {
118-
$connection->addSetup('Nette\Database\Helpers::createDebugPanel', array($connection, !empty($config['explain']), $name));
118+
$connection->addSetup('Nette\Database\Helpers::createDebugPanel', [$connection, !empty($config['explain']), $name]);
119119
}
120120
}
121121

src/Bridges/DatabaseTracy/ConnectionPanel.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ConnectionPanel extends Nette\Object implements Tracy\IBarPanel
2929
private $count = 0;
3030

3131
/** @var array */
32-
private $queries = array();
32+
private $queries = [];
3333

3434
/** @var string */
3535
public $name;
@@ -43,7 +43,7 @@ class ConnectionPanel extends Nette\Object implements Tracy\IBarPanel
4343

4444
public function __construct(Nette\Database\Connection $connection)
4545
{
46-
$connection->onQuery[] = array($this, 'logQuery');
46+
$connection->onQuery[] = [$this, 'logQuery'];
4747
}
4848

4949

@@ -63,18 +63,18 @@ public function logQuery(Nette\Database\Connection $connection, $result)
6363
) {
6464
continue;
6565
}
66-
$source = array($row['file'], (int) $row['line']);
66+
$source = [$row['file'], (int) $row['line']];
6767
break;
6868
}
6969
}
7070
if ($result instanceof Nette\Database\ResultSet) {
7171
$this->totalTime += $result->getTime();
7272
if ($this->count < $this->maxQueries) {
73-
$this->queries[] = array($connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL);
73+
$this->queries[] = [$connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL];
7474
}
7575

7676
} elseif ($result instanceof \PDOException && $this->count < $this->maxQueries) {
77-
$this->queries[] = array($connection, $result->queryString, NULL, $source, NULL, NULL, $result->getMessage());
77+
$this->queries[] = [$connection, $result->queryString, NULL, $source, NULL, NULL, $result->getMessage()];
7878
}
7979
}
8080

@@ -90,10 +90,10 @@ public static function renderException($e)
9090
} elseif ($item = Tracy\Helpers::findTrace($e->getTrace(), 'PDO::prepare')) {
9191
$sql = $item['args'][0];
9292
}
93-
return isset($sql) ? array(
93+
return isset($sql) ? [
9494
'tab' => 'SQL',
9595
'panel' => Helpers::dumpSql($sql),
96-
) : NULL;
96+
] : NULL;
9797
}
9898

9999

@@ -118,7 +118,7 @@ public function getPanel()
118118
$name = $this->name;
119119
$count = $this->count;
120120
$totalTime = $this->totalTime;
121-
$queries = array();
121+
$queries = [];
122122
foreach ($this->queries as $query) {
123123
list($connection, $sql, $params, $source, $time, $rows, $error) = $query;
124124
$explain = NULL;

src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use Nette,
1212
#tracy-debug .nette-DbConnectionPanel-source { color: #BBB !important }
1313
</style>
1414

15-
<h1 title="<?php echo htmlSpecialChars($connection->getDsn(), ENT_QUOTES, 'UTF-8') ?>">Queries: <?php
15+
<h1 title="<?= htmlSpecialChars($connection->getDsn(), ENT_QUOTES, 'UTF-8') ?>">Queries: <?php
1616
echo $count, ($totalTime ? sprintf(', time: %0.3f ms', $totalTime * 1000) : ''), ', ', htmlSpecialChars($name, ENT_NOQUOTES, 'UTF-8') ?></h1>
1717

1818
<div class="tracy-inner nette-DbConnectionPanel">
@@ -25,32 +25,32 @@ use Nette,
2525
<tr>
2626
<td>
2727
<?php if ($error): ?>
28-
<span title="<?php echo htmlSpecialChars($error, ENT_IGNORE | ENT_QUOTES, 'UTF-8') ?>">ERROR</span>
28+
<span title="<?= htmlSpecialChars($error, ENT_IGNORE | ENT_QUOTES, 'UTF-8') ?>">ERROR</span>
2929
<?php elseif ($time !== NULL): echo sprintf('%0.3f', $time * 1000); endif ?>
3030
<?php if ($explain): ?>
3131
<br /><a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .nette-DbConnectionPanel-explain">explain</a>
3232
<?php endif ?>
3333
</td>
34-
<td class="nette-DbConnectionPanel-sql"><?php echo Helpers::dumpSql($sql, $params, $connection) ?>
34+
<td class="nette-DbConnectionPanel-sql"><?= Helpers::dumpSql($sql, $params, $connection) ?>
3535
<?php if ($explain): ?>
3636
<table class="tracy-collapsed nette-DbConnectionPanel-explain">
3737
<tr>
3838
<?php foreach ($explain[0] as $col => $foo): ?>
39-
<th><?php echo htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></th>
39+
<th><?= htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></th>
4040
<?php endforeach ?>
4141
</tr>
4242
<?php foreach ($explain as $row): ?>
4343
<tr>
4444
<?php foreach ($row as $col): ?>
45-
<td><?php echo htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></td>
45+
<td><?= htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></td>
4646
<?php endforeach ?>
4747
</tr>
4848
<?php endforeach ?>
4949
</table>
5050
<?php endif ?>
5151
<?php if ($source) echo substr_replace(Tracy\Helpers::editorLink($source[0], $source[1]), ' class="nette-DbConnectionPanel-source"', 2, 0); ?>
5252
</td>
53-
<td><?php echo $rows ?></td>
53+
<td><?= $rows ?></td>
5454
</tr>
5555
<?php endforeach ?>
5656
</table>

src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Nette\Bridges\DatabaseTracy;
55
use Nette;
66

77
?>
8-
<span title="Nette\Database <?php echo htmlSpecialChars($name, ENT_QUOTES, 'UTF-8') ?>">
9-
<svg viewBox="0 0 2048 2048"><path fill="<?php echo $count ? '#b079d6' : '#aaa' ?>" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/>
10-
</svg><span class="tracy-label"><?php echo ($totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : '') . $count ?></span>
8+
<span title="Nette\Database <?= htmlSpecialChars($name, ENT_QUOTES, 'UTF-8') ?>">
9+
<svg viewBox="0 0 2048 2048"><path fill="<?= $count ? '#b079d6' : '#aaa' ?>" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/>
10+
</svg><span class="tracy-label"><?= ($totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : '') . $count ?></span>
1111
</span>

src/Database/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct($dsn, $user = NULL, $password = NULL, array $options
5050
if (func_num_args() > 4) { // compatibility
5151
$options['driverClass'] = func_get_arg(4);
5252
}
53-
$this->params = array($dsn, $user, $password);
53+
$this->params = [$dsn, $user, $password];
5454
$this->options = (array) $options;
5555

5656
if (empty($options['lazy'])) {
@@ -183,7 +183,7 @@ public function query($statement)
183183
$args = is_array($statement) ? $statement : func_get_args(); // accepts arrays only internally
184184
list($statement, $params) = count($args) > 1
185185
? $this->preprocessor->process($args)
186-
: array($args[0], array());
186+
: [$args[0], []];
187187

188188
try {
189189
$result = new ResultSet($this, $statement, $params);
@@ -216,7 +216,7 @@ public function preprocess($statement)
216216
$this->connect();
217217
return func_num_args() > 1
218218
? $this->preprocessor->process(func_get_args())
219-
: array($statement, array());
219+
: [$statement, []];
220220
}
221221

222222

src/Database/Conventions/DiscoveredConventions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getPrimary($table)
3636

3737
public function getHasManyReference($nsTable, $key)
3838
{
39-
$candidates = $columnCandidates = array();
39+
$candidates = $columnCandidates = [];
4040
$targets = $this->structure->getHasManyReference($nsTable);
4141
$table = preg_replace('#^(.*\.)?(.*)$#', '$2', $nsTable);
4242

@@ -48,13 +48,13 @@ public function getHasManyReference($nsTable, $key)
4848

4949
foreach ($targetColumns as $targetColumn) {
5050
if (stripos($targetColumn, $table) !== FALSE) {
51-
$columnCandidates[] = $candidate = array($targetNsTable, $targetColumn);
51+
$columnCandidates[] = $candidate = [$targetNsTable, $targetColumn];
5252
if (strcmp($targetTable, $key) === 0 || strcmp($targetNsTable, $key) === 0) {
5353
return $candidate;
5454
}
5555
}
5656

57-
$candidates[] = array($targetTable, array($targetNsTable, $targetColumn));
57+
$candidates[] = [$targetTable, [$targetNsTable, $targetColumn]];
5858
}
5959
}
6060

@@ -89,7 +89,7 @@ public function getBelongsToReference($table, $key)
8989

9090
foreach ($tableColumns as $column => $targetTable) {
9191
if (stripos($column, $key) !== FALSE) {
92-
return array($targetTable, $column);
92+
return [$targetTable, $column];
9393
}
9494
}
9595

src/Database/Conventions/StaticConventions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ public function getPrimary($table)
5252
public function getHasManyReference($table, $key)
5353
{
5454
$table = $this->getColumnFromTable($table);
55-
return array(
55+
return [
5656
sprintf($this->table, $key, $table),
5757
sprintf($this->foreign, $table, $key),
58-
);
58+
];
5959
}
6060

6161

6262
public function getBelongsToReference($table, $key)
6363
{
6464
$table = $this->getColumnFromTable($table);
65-
return array(
65+
return [
6666
sprintf($this->table, $key, $table),
6767
sprintf($this->foreign, $key, $table),
68-
);
68+
];
6969
}
7070

7171

src/Database/Drivers/MsSqlDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function convertException(\PDOException $e)
3333
public function delimite($name)
3434
{
3535
// @see http://msdn.microsoft.com/en-us/library/ms176027.aspx
36-
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $name) . ']';
36+
return '[' . str_replace(['[', ']'], ['[[', ']]'], $name) . ']';
3737
}
3838

3939

@@ -69,7 +69,7 @@ public function formatDateInterval(\DateInterval $value)
6969
*/
7070
public function formatLike($value, $pos)
7171
{
72-
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
72+
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
7373
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
7474
}
7575

src/Database/Drivers/MySqlDriver.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ public function __construct(Nette\Database\Connection $connection, array $option
5151
public function convertException(\PDOException $e)
5252
{
5353
$code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
54-
if (in_array($code, array(1216, 1217, 1451, 1452, 1701), TRUE)) {
54+
if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) {
5555
return Nette\Database\ForeignKeyConstraintViolationException::from($e);
5656

57-
} elseif (in_array($code, array(1062, 1557, 1569, 1586), TRUE)) {
57+
} elseif (in_array($code, [1062, 1557, 1569, 1586], TRUE)) {
5858
return Nette\Database\UniqueConstraintViolationException::from($e);
5959

6060
} elseif ($code >= 2001 && $code <= 2028) {
6161
return Nette\Database\ConnectionException::from($e);
6262

63-
} elseif (in_array($code, array(1048, 1121, 1138, 1171, 1252, 1263, 1566), TRUE)) {
63+
} elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], TRUE)) {
6464
return Nette\Database\NotNullConstraintViolationException::from($e);
6565

6666
} else {
@@ -149,12 +149,12 @@ public function normalizeRow($row)
149149
*/
150150
public function getTables()
151151
{
152-
$tables = array();
152+
$tables = [];
153153
foreach ($this->connection->query('SHOW FULL TABLES') as $row) {
154-
$tables[] = array(
154+
$tables[] = [
155155
'name' => $row[0],
156156
'view' => isset($row[1]) && $row[1] === 'VIEW',
157-
);
157+
];
158158
}
159159
return $tables;
160160
}
@@ -165,10 +165,10 @@ public function getTables()
165165
*/
166166
public function getColumns($table)
167167
{
168-
$columns = array();
168+
$columns = [];
169169
foreach ($this->connection->query('SHOW FULL COLUMNS FROM ' . $this->delimite($table)) as $row) {
170170
$type = explode('(', $row['Type']);
171-
$columns[] = array(
171+
$columns[] = [
172172
'name' => $row['Field'],
173173
'table' => $table,
174174
'nativetype' => strtoupper($type[0]),
@@ -179,7 +179,7 @@ public function getColumns($table)
179179
'autoincrement' => $row['Extra'] === 'auto_increment',
180180
'primary' => $row['Key'] === 'PRI',
181181
'vendor' => (array) $row,
182-
);
182+
];
183183
}
184184
return $columns;
185185
}
@@ -190,7 +190,7 @@ public function getColumns($table)
190190
*/
191191
public function getIndexes($table)
192192
{
193-
$indexes = array();
193+
$indexes = [];
194194
foreach ($this->connection->query('SHOW INDEX FROM ' . $this->delimite($table)) as $row) {
195195
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
196196
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
@@ -206,7 +206,7 @@ public function getIndexes($table)
206206
*/
207207
public function getForeignKeys($table)
208208
{
209-
$keys = array();
209+
$keys = [];
210210
$query = 'SELECT CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE '
211211
. 'WHERE TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->connection->quote($table);
212212

@@ -226,7 +226,7 @@ public function getForeignKeys($table)
226226
*/
227227
public function getColumnTypes(\PDOStatement $statement)
228228
{
229-
$types = array();
229+
$types = [];
230230
$count = $statement->columnCount();
231231
for ($col = 0; $col < $count; $col++) {
232232
$meta = $statement->getColumnMeta($col);

0 commit comments

Comments
 (0)