Skip to content

Commit

Permalink
used PHP 5.4 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 21, 2015
1 parent 62d6c08 commit 9ff0956
Show file tree
Hide file tree
Showing 86 changed files with 966 additions and 966 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ matrix:

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

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

# Create databases.ini
- cp ./tests/Database/databases.sample.ini ./tests/Database/databases.ini
Expand Down
22 changes: 11 additions & 11 deletions src/Bridges/DatabaseDI/DatabaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class DatabaseExtension extends Nette\DI\CompilerExtension
{
public $databaseDefaults = array(
public $databaseDefaults = [
'dsn' => NULL,
'user' => NULL,
'password' => NULL,
Expand All @@ -28,7 +28,7 @@ class DatabaseExtension extends Nette\DI\CompilerExtension
'reflection' => NULL, // BC
'conventions' => 'discovered', // Nette\Database\Conventions\DiscoveredConventions
'autowired' => NULL,
);
];

/** @var bool */
private $debugMode;
Expand All @@ -44,7 +44,7 @@ public function loadConfiguration()
{
$configs = $this->getConfig();
if (isset($configs['dsn'])) {
$configs = array('default' => $configs);
$configs = ['default' => $configs];
}

$defaults = $this->databaseDefaults;
Expand Down Expand Up @@ -72,12 +72,12 @@ private function setupDatabase($config, $name)
}

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

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

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

} else {
$tmp = Nette\DI\Compiler::filterArguments(array($config['conventions']));
$tmp = Nette\DI\Compiler::filterArguments([$config['conventions']]);
$conventions = reset($tmp);
}

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

if ($config['debugger']) {
$connection->addSetup('@Tracy\BlueScreen::addPanel', array(
$connection->addSetup('@Tracy\BlueScreen::addPanel', [
'Nette\Bridges\DatabaseTracy\ConnectionPanel::renderException'
));
]);
if ($this->debugMode) {
$connection->addSetup('Nette\Database\Helpers::createDebugPanel', array($connection, !empty($config['explain']), $name));
$connection->addSetup('Nette\Database\Helpers::createDebugPanel', [$connection, !empty($config['explain']), $name]);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Bridges/DatabaseTracy/ConnectionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConnectionPanel extends Nette\Object implements Tracy\IBarPanel
private $count = 0;

/** @var array */
private $queries = array();
private $queries = [];

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

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


Expand All @@ -63,18 +63,18 @@ public function logQuery(Nette\Database\Connection $connection, $result)
) {
continue;
}
$source = array($row['file'], (int) $row['line']);
$source = [$row['file'], (int) $row['line']];
break;
}
}
if ($result instanceof Nette\Database\ResultSet) {
$this->totalTime += $result->getTime();
if ($this->count < $this->maxQueries) {
$this->queries[] = array($connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL);
$this->queries[] = [$connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL];
}

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

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


Expand All @@ -118,7 +118,7 @@ public function getPanel()
$name = $this->name;
$count = $this->count;
$totalTime = $this->totalTime;
$queries = array();
$queries = [];
foreach ($this->queries as $query) {
list($connection, $sql, $params, $source, $time, $rows, $error) = $query;
$explain = NULL;
Expand Down
12 changes: 6 additions & 6 deletions src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Nette,
#tracy-debug .nette-DbConnectionPanel-source { color: #BBB !important }
</style>

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

<div class="tracy-inner nette-DbConnectionPanel">
Expand All @@ -25,32 +25,32 @@ use Nette,
<tr>
<td>
<?php if ($error): ?>
<span title="<?php echo htmlSpecialChars($error, ENT_IGNORE | ENT_QUOTES, 'UTF-8') ?>">ERROR</span>
<span title="<?= htmlSpecialChars($error, ENT_IGNORE | ENT_QUOTES, 'UTF-8') ?>">ERROR</span>
<?php elseif ($time !== NULL): echo sprintf('%0.3f', $time * 1000); endif ?>
<?php if ($explain): ?>
<br /><a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .nette-DbConnectionPanel-explain">explain</a>
<?php endif ?>
</td>
<td class="nette-DbConnectionPanel-sql"><?php echo Helpers::dumpSql($sql, $params, $connection) ?>
<td class="nette-DbConnectionPanel-sql"><?= Helpers::dumpSql($sql, $params, $connection) ?>
<?php if ($explain): ?>
<table class="tracy-collapsed nette-DbConnectionPanel-explain">
<tr>
<?php foreach ($explain[0] as $col => $foo): ?>
<th><?php echo htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></th>
<th><?= htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></th>
<?php endforeach ?>
</tr>
<?php foreach ($explain as $row): ?>
<tr>
<?php foreach ($row as $col): ?>
<td><?php echo htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></td>
<td><?= htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>
<?php if ($source) echo substr_replace(Tracy\Helpers::editorLink($source[0], $source[1]), ' class="nette-DbConnectionPanel-source"', 2, 0); ?>
</td>
<td><?php echo $rows ?></td>
<td><?= $rows ?></td>
</tr>
<?php endforeach ?>
</table>
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nette\Bridges\DatabaseTracy;
use Nette;

?>
<span title="Nette\Database <?php echo htmlSpecialChars($name, ENT_QUOTES, 'UTF-8') ?>">
<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"/>
</svg><span class="tracy-label"><?php echo ($totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : '') . $count ?></span>
<span title="Nette\Database <?= htmlSpecialChars($name, ENT_QUOTES, 'UTF-8') ?>">
<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"/>
</svg><span class="tracy-label"><?= ($totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : '') . $count ?></span>
</span>
6 changes: 3 additions & 3 deletions src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct($dsn, $user = NULL, $password = NULL, array $options
if (func_num_args() > 4) { // compatibility
$options['driverClass'] = func_get_arg(4);
}
$this->params = array($dsn, $user, $password);
$this->params = [$dsn, $user, $password];
$this->options = (array) $options;

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

try {
$result = new ResultSet($this, $statement, $params);
Expand Down Expand Up @@ -216,7 +216,7 @@ public function preprocess($statement)
$this->connect();
return func_num_args() > 1
? $this->preprocessor->process(func_get_args())
: array($statement, array());
: [$statement, []];
}


Expand Down
8 changes: 4 additions & 4 deletions src/Database/Conventions/DiscoveredConventions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getPrimary($table)

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

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

foreach ($targetColumns as $targetColumn) {
if (stripos($targetColumn, $table) !== FALSE) {
$columnCandidates[] = $candidate = array($targetNsTable, $targetColumn);
$columnCandidates[] = $candidate = [$targetNsTable, $targetColumn];
if (strcmp($targetTable, $key) === 0 || strcmp($targetNsTable, $key) === 0) {
return $candidate;
}
}

$candidates[] = array($targetTable, array($targetNsTable, $targetColumn));
$candidates[] = [$targetTable, [$targetNsTable, $targetColumn]];
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public function getBelongsToReference($table, $key)

foreach ($tableColumns as $column => $targetTable) {
if (stripos($column, $key) !== FALSE) {
return array($targetTable, $column);
return [$targetTable, $column];
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Database/Conventions/StaticConventions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ public function getPrimary($table)
public function getHasManyReference($table, $key)
{
$table = $this->getColumnFromTable($table);
return array(
return [
sprintf($this->table, $key, $table),
sprintf($this->foreign, $table, $key),
);
];
}


public function getBelongsToReference($table, $key)
{
$table = $this->getColumnFromTable($table);
return array(
return [
sprintf($this->table, $key, $table),
sprintf($this->foreign, $key, $table),
);
];
}


Expand Down
4 changes: 2 additions & 2 deletions src/Database/Drivers/MsSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function convertException(\PDOException $e)
public function delimite($name)
{
// @see http://msdn.microsoft.com/en-us/library/ms176027.aspx
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $name) . ']';
return '[' . str_replace(['[', ']'], ['[[', ']]'], $name) . ']';
}


Expand Down Expand Up @@ -69,7 +69,7 @@ public function formatDateInterval(\DateInterval $value)
*/
public function formatLike($value, $pos)
{
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
}

Expand Down
24 changes: 12 additions & 12 deletions src/Database/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public function __construct(Nette\Database\Connection $connection, array $option
public function convertException(\PDOException $e)
{
$code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
if (in_array($code, array(1216, 1217, 1451, 1452, 1701), TRUE)) {
if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) {
return Nette\Database\ForeignKeyConstraintViolationException::from($e);

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

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

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

} else {
Expand Down Expand Up @@ -149,12 +149,12 @@ public function normalizeRow($row)
*/
public function getTables()
{
$tables = array();
$tables = [];
foreach ($this->connection->query('SHOW FULL TABLES') as $row) {
$tables[] = array(
$tables[] = [
'name' => $row[0],
'view' => isset($row[1]) && $row[1] === 'VIEW',
);
];
}
return $tables;
}
Expand All @@ -165,10 +165,10 @@ public function getTables()
*/
public function getColumns($table)
{
$columns = array();
$columns = [];
foreach ($this->connection->query('SHOW FULL COLUMNS FROM ' . $this->delimite($table)) as $row) {
$type = explode('(', $row['Type']);
$columns[] = array(
$columns[] = [
'name' => $row['Field'],
'table' => $table,
'nativetype' => strtoupper($type[0]),
Expand All @@ -179,7 +179,7 @@ public function getColumns($table)
'autoincrement' => $row['Extra'] === 'auto_increment',
'primary' => $row['Key'] === 'PRI',
'vendor' => (array) $row,
);
];
}
return $columns;
}
Expand All @@ -190,7 +190,7 @@ public function getColumns($table)
*/
public function getIndexes($table)
{
$indexes = array();
$indexes = [];
foreach ($this->connection->query('SHOW INDEX FROM ' . $this->delimite($table)) as $row) {
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
Expand All @@ -206,7 +206,7 @@ public function getIndexes($table)
*/
public function getForeignKeys($table)
{
$keys = array();
$keys = [];
$query = 'SELECT CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE '
. 'WHERE TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->connection->quote($table);

Expand All @@ -226,7 +226,7 @@ public function getForeignKeys($table)
*/
public function getColumnTypes(\PDOStatement $statement)
{
$types = array();
$types = [];
$count = $statement->columnCount();
for ($col = 0; $col < $count; $col++) {
$meta = $statement->getColumnMeta($col);
Expand Down
Loading

0 comments on commit 9ff0956

Please sign in to comment.