Skip to content

Commit 6b7e059

Browse files
committed
used PHP 7.1 features
1 parent c3a45e9 commit 6b7e059

File tree

15 files changed

+78
-79
lines changed

15 files changed

+78
-79
lines changed

src/Bridges/DatabaseTracy/ConnectionPanel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function logQuery(Nette\Database\Connection $connection, $result)
5858
$trace = $result instanceof \PDOException ? $result->getTrace() : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
5959
foreach ($trace as $row) {
6060
if (isset($row['file']) && is_file($row['file']) && !Tracy\Debugger::getBluescreen()->isCollapsed($row['file'])) {
61-
if ((isset($row['function']) && strpos($row['function'], 'call_user_func') === 0)
62-
|| (isset($row['class']) && is_subclass_of($row['class'], '\\Nette\\Database\\Connection'))
61+
if ((strpos($row['function'] ?? '', 'call_user_func') === 0)
62+
|| (is_subclass_of($row['class'] ?? '', '\\Nette\\Database\\Connection'))
6363
) {
6464
continue;
6565
}
@@ -120,7 +120,7 @@ public function getPanel()
120120
$totalTime = $this->totalTime;
121121
$queries = [];
122122
foreach ($this->queries as $query) {
123-
list($connection, $sql, $params, $source, $time, $rows, $error) = $query;
123+
[$connection, $sql, $params, $source, $time, $rows, $error] = $query;
124124
$explain = NULL;
125125
if (!$error && $this->explain && preg_match('#\s*\(?\s*SELECT\s#iA', $sql)) {
126126
try {

src/Database/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function rollBack()
171171
*/
172172
public function query($sql, ...$params)
173173
{
174-
list($sql, $params) = $this->preprocess($sql, ...$params);
174+
[$sql, $params] = $this->preprocess($sql, ...$params);
175175
try {
176176
$result = new ResultSet($this, $sql, $params);
177177
} catch (PDOException $e) {

src/Database/DriverException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function from(\PDOException $src)
4040
*/
4141
public function getDriverCode()
4242
{
43-
return isset($this->errorInfo[1]) ? $this->errorInfo[1] : NULL;
43+
return $this->errorInfo[1] ?? NULL;
4444
}
4545

4646

@@ -49,7 +49,7 @@ public function getDriverCode()
4949
*/
5050
public function getSqlState()
5151
{
52-
return isset($this->errorInfo[0]) ? $this->errorInfo[0] : NULL;
52+
return $this->errorInfo[0] ?? NULL;
5353
}
5454

5555

src/Database/Drivers/MySqlDriver.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class MySqlDriver implements Nette\Database\ISupplementalDriver
3333
public function __construct(Nette\Database\Connection $connection, array $options)
3434
{
3535
$this->connection = $connection;
36-
$charset = isset($options['charset'])
37-
? $options['charset']
38-
: (version_compare($connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.5.3', '>=') ? 'utf8mb4' : 'utf8');
36+
$charset = $options['charset']
37+
?? (version_compare($connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.5.3', '>=') ? 'utf8mb4' : 'utf8');
3938
if ($charset) {
4039
$connection->query("SET NAMES '$charset'");
4140
}
@@ -50,7 +49,7 @@ public function __construct(Nette\Database\Connection $connection, array $option
5049
*/
5150
public function convertException(\PDOException $e)
5251
{
53-
$code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
52+
$code = $e->errorInfo[1] ?? NULL;
5453
if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) {
5554
return Nette\Database\ForeignKeyConstraintViolationException::from($e);
5655

@@ -157,7 +156,7 @@ public function getTables()
157156
foreach ($this->connection->query('SHOW FULL TABLES') as $row) {
158157
$tables[] = [
159158
'name' => $row[0],
160-
'view' => isset($row[1]) && $row[1] === 'VIEW',
159+
'view' => ($row[1] ?? NULL) === 'VIEW',
161160
];
162161
}
163162
return $tables;

src/Database/Drivers/OciDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class OciDriver implements Nette\Database\ISupplementalDriver
2727
public function __construct(Nette\Database\Connection $connection, array $options)
2828
{
2929
$this->connection = $connection;
30-
$this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
30+
$this->fmtDateTime = $options['formatDateTime'] ?? 'U';
3131
}
3232

3333

3434
public function convertException(\PDOException $e)
3535
{
36-
$code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
36+
$code = $e->errorInfo[1] ?? NULL;
3737
if (in_array($code, [1, 2299, 38911], TRUE)) {
3838
return Nette\Database\UniqueConstraintViolationException::from($e);
3939

src/Database/Drivers/PgSqlDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(Nette\Database\Connection $connection, array $option
2929

3030
public function convertException(\PDOException $e)
3131
{
32-
$code = isset($e->errorInfo[0]) ? $e->errorInfo[0] : NULL;
32+
$code = $e->errorInfo[0] ?? NULL;
3333
if ($code === '0A000' && strpos($e->getMessage(), 'truncate') !== FALSE) {
3434
return Nette\Database\ForeignKeyConstraintViolationException::from($e);
3535

src/Database/Drivers/SqliteDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class SqliteDriver implements Nette\Database\ISupplementalDriver
2727
public function __construct(Nette\Database\Connection $connection, array $options)
2828
{
2929
$this->connection = $connection;
30-
$this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U';
30+
$this->fmtDateTime = $options['formatDateTime'] ?? 'U';
3131
}
3232

3333

3434
public function convertException(\PDOException $e)
3535
{
36-
$code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
36+
$code = $e->errorInfo[1] ?? NULL;
3737
$msg = $e->getMessage();
3838
if ($code !== 19) {
3939
return Nette\Database\DriverException::from($e);

src/Database/Helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ public static function toPairs(array $rows, $key = NULL, $value = NULL)
246246

247247
} elseif ($key === NULL && $value === NULL) {
248248
if (count($keys) === 1) {
249-
list($value) = $keys;
249+
[$value] = $keys;
250250
} else {
251-
list($key, $value) = $keys;
251+
[$key, $value] = $keys;
252252
}
253253
}
254254

@@ -277,7 +277,7 @@ public static function findDuplicates(\PDOStatement $statement)
277277
$cols = [];
278278
for ($i = 0; $i < $statement->columnCount(); $i++) {
279279
$meta = $statement->getColumnMeta($i);
280-
$cols[$meta['name']][] = isset($meta['table']) ? $meta['table'] : '';
280+
$cols[$meta['name']][] = $meta['table'] ?? '';
281281
}
282282
$duplicates = [];
283283
foreach ($cols as $name => $tables) {

src/Database/ResultSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct(Connection $connection, $queryString, array $params)
6666
$this->pdoStatement = $connection->getPdo()->prepare($queryString);
6767
foreach ($params as $key => $value) {
6868
$type = gettype($value);
69-
$this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR);
69+
$this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, $types[$type] ?? PDO::PARAM_STR);
7070
}
7171
$this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
7272
$this->pdoStatement->execute();

src/Database/SqlPreprocessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private function formatValue($value, $mode = NULL)
139139

140140
} elseif ($value instanceof SqlLiteral) {
141141
$prep = clone $this;
142-
list($res, $params) = $prep->process(array_merge([$value->__toString()], $value->getParameters()));
142+
[$res, $params] = $prep->process(array_merge([$value->__toString()], $value->getParameters()));
143143
$this->remaining = array_merge($this->remaining, $params);
144144
return $res;
145145

@@ -217,7 +217,7 @@ private function formatValue($value, $mode = NULL)
217217
$vx[] = $this->formatValue($v);
218218
continue;
219219
}
220-
list($k, $operator) = explode(' ', $k . ' ');
220+
[$k, $operator] = explode(' ', $k . ' ');
221221
$k = $this->delimite($k);
222222
if (is_array($v)) {
223223
if ($v) {

0 commit comments

Comments
 (0)