From 0b4d2e5bcf3fa393a23a8e29b47861cfc1ef9ce2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 15 Jan 2017 07:29:16 +0100 Subject: [PATCH] utilization of operator ?? --- src/Bridges/DatabaseTracy/ConnectionPanel.php | 4 ++-- src/Database/DriverException.php | 4 ++-- src/Database/Drivers/MySqlDriver.php | 9 ++++----- src/Database/Drivers/OciDriver.php | 4 ++-- src/Database/Drivers/PgSqlDriver.php | 2 +- src/Database/Drivers/SqliteDriver.php | 4 ++-- src/Database/Helpers.php | 2 +- src/Database/ResultSet.php | 2 +- src/Database/Structure.php | 2 +- src/Database/Table/GroupedSelection.php | 2 +- src/Database/Table/Selection.php | 2 +- src/Database/Table/SqlBuilder.php | 2 +- 12 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Bridges/DatabaseTracy/ConnectionPanel.php b/src/Bridges/DatabaseTracy/ConnectionPanel.php index 83a2b2493..d753d44af 100644 --- a/src/Bridges/DatabaseTracy/ConnectionPanel.php +++ b/src/Bridges/DatabaseTracy/ConnectionPanel.php @@ -58,8 +58,8 @@ public function logQuery(Nette\Database\Connection $connection, $result) $trace = $result instanceof \PDOException ? $result->getTrace() : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); foreach ($trace as $row) { if (isset($row['file']) && is_file($row['file']) && !Tracy\Debugger::getBluescreen()->isCollapsed($row['file'])) { - if ((isset($row['function']) && strpos($row['function'], 'call_user_func') === 0) - || (isset($row['class']) && is_subclass_of($row['class'], '\\Nette\\Database\\Connection')) + if ((strpos($row['function'] ?? '', 'call_user_func') === 0) + || (is_subclass_of($row['class'] ?? '', '\\Nette\\Database\\Connection')) ) { continue; } diff --git a/src/Database/DriverException.php b/src/Database/DriverException.php index 7665df465..5748f211f 100644 --- a/src/Database/DriverException.php +++ b/src/Database/DriverException.php @@ -40,7 +40,7 @@ public static function from(\PDOException $src) */ public function getDriverCode() { - return isset($this->errorInfo[1]) ? $this->errorInfo[1] : NULL; + return $this->errorInfo[1] ?? NULL; } @@ -49,7 +49,7 @@ public function getDriverCode() */ public function getSqlState() { - return isset($this->errorInfo[0]) ? $this->errorInfo[0] : NULL; + return $this->errorInfo[0] ?? NULL; } diff --git a/src/Database/Drivers/MySqlDriver.php b/src/Database/Drivers/MySqlDriver.php index 2647f9cc6..541a1211d 100644 --- a/src/Database/Drivers/MySqlDriver.php +++ b/src/Database/Drivers/MySqlDriver.php @@ -33,9 +33,8 @@ class MySqlDriver implements Nette\Database\ISupplementalDriver public function __construct(Nette\Database\Connection $connection, array $options) { $this->connection = $connection; - $charset = isset($options['charset']) - ? $options['charset'] - : (version_compare($connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.5.3', '>=') ? 'utf8mb4' : 'utf8'); + $charset = $options['charset'] + ?? (version_compare($connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.5.3', '>=') ? 'utf8mb4' : 'utf8'); if ($charset) { $connection->query("SET NAMES '$charset'"); } @@ -50,7 +49,7 @@ public function __construct(Nette\Database\Connection $connection, array $option */ public function convertException(\PDOException $e) { - $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL; + $code = $e->errorInfo[1] ?? NULL; if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) { return Nette\Database\ForeignKeyConstraintViolationException::from($e); @@ -157,7 +156,7 @@ public function getTables() foreach ($this->connection->query('SHOW FULL TABLES') as $row) { $tables[] = [ 'name' => $row[0], - 'view' => isset($row[1]) && $row[1] === 'VIEW', + 'view' => ($row[1] ?? NULL) === 'VIEW', ]; } return $tables; diff --git a/src/Database/Drivers/OciDriver.php b/src/Database/Drivers/OciDriver.php index 61ff54948..4aec5c5b7 100644 --- a/src/Database/Drivers/OciDriver.php +++ b/src/Database/Drivers/OciDriver.php @@ -27,13 +27,13 @@ class OciDriver implements Nette\Database\ISupplementalDriver public function __construct(Nette\Database\Connection $connection, array $options) { $this->connection = $connection; - $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U'; + $this->fmtDateTime = $options['formatDateTime'] ?? 'U'; } public function convertException(\PDOException $e) { - $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL; + $code = $e->errorInfo[1] ?? NULL; if (in_array($code, [1, 2299, 38911], TRUE)) { return Nette\Database\UniqueConstraintViolationException::from($e); diff --git a/src/Database/Drivers/PgSqlDriver.php b/src/Database/Drivers/PgSqlDriver.php index 11e34f6ab..b2cc2aa38 100644 --- a/src/Database/Drivers/PgSqlDriver.php +++ b/src/Database/Drivers/PgSqlDriver.php @@ -29,7 +29,7 @@ public function __construct(Nette\Database\Connection $connection, array $option public function convertException(\PDOException $e) { - $code = isset($e->errorInfo[0]) ? $e->errorInfo[0] : NULL; + $code = $e->errorInfo[0] ?? NULL; if ($code === '0A000' && strpos($e->getMessage(), 'truncate') !== FALSE) { return Nette\Database\ForeignKeyConstraintViolationException::from($e); diff --git a/src/Database/Drivers/SqliteDriver.php b/src/Database/Drivers/SqliteDriver.php index 3ae2f5a16..b1a392a24 100644 --- a/src/Database/Drivers/SqliteDriver.php +++ b/src/Database/Drivers/SqliteDriver.php @@ -27,13 +27,13 @@ class SqliteDriver implements Nette\Database\ISupplementalDriver public function __construct(Nette\Database\Connection $connection, array $options) { $this->connection = $connection; - $this->fmtDateTime = isset($options['formatDateTime']) ? $options['formatDateTime'] : 'U'; + $this->fmtDateTime = $options['formatDateTime'] ?? 'U'; } public function convertException(\PDOException $e) { - $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL; + $code = $e->errorInfo[1] ?? NULL; $msg = $e->getMessage(); if ($code !== 19) { return Nette\Database\DriverException::from($e); diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 532a8e2d6..9196e4df4 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -277,7 +277,7 @@ public static function findDuplicates(\PDOStatement $statement) $cols = []; for ($i = 0; $i < $statement->columnCount(); $i++) { $meta = $statement->getColumnMeta($i); - $cols[$meta['name']][] = isset($meta['table']) ? $meta['table'] : ''; + $cols[$meta['name']][] = $meta['table'] ?? ''; } $duplicates = []; foreach ($cols as $name => $tables) { diff --git a/src/Database/ResultSet.php b/src/Database/ResultSet.php index 579c010b1..f3911a3b8 100644 --- a/src/Database/ResultSet.php +++ b/src/Database/ResultSet.php @@ -66,7 +66,7 @@ public function __construct(Connection $connection, $queryString, array $params) $this->pdoStatement = $connection->getPdo()->prepare($queryString); foreach ($params as $key => $value) { $type = gettype($value); - $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR); + $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, $types[$type] ?? PDO::PARAM_STR); } $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC); $this->pdoStatement->execute(); diff --git a/src/Database/Structure.php b/src/Database/Structure.php index a80f95afc..64cace3b0 100644 --- a/src/Database/Structure.php +++ b/src/Database/Structure.php @@ -82,7 +82,7 @@ public function getPrimaryKeySequence($table) foreach ($this->structure['columns'][$table] as $columnMeta) { if ($columnMeta['name'] === $primary) { - return isset($columnMeta['vendor']['sequence']) ? $columnMeta['vendor']['sequence'] : NULL; + return $columnMeta['vendor']['sequence'] ?? NULL; } } diff --git a/src/Database/Table/GroupedSelection.php b/src/Database/Table/GroupedSelection.php index 2f9db2230..3c6782cd7 100644 --- a/src/Database/Table/GroupedSelection.php +++ b/src/Database/Table/GroupedSelection.php @@ -114,7 +114,7 @@ public function aggregation($function) public function count($column = NULL) { $return = parent::count($column); - return isset($return) ? $return : 0; + return $return ?? 0; } diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 1d10e6d97..7d849974a 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -944,7 +944,7 @@ public function getReferencedTable(ActiveRow $row, $table, $column = NULL) } } - return isset($selection[$checkPrimaryKey]) ? $selection[$checkPrimaryKey] : NULL; + return $selection[$checkPrimaryKey] ?? NULL; } diff --git a/src/Database/Table/SqlBuilder.php b/src/Database/Table/SqlBuilder.php index 5b82c69ac..67f29115c 100644 --- a/src/Database/Table/SqlBuilder.php +++ b/src/Database/Table/SqlBuilder.php @@ -795,7 +795,7 @@ private function getCachedTableList() { if (!$this->cacheTableList) { $this->cacheTableList = array_flip(array_map(function ($pair) { - return isset($pair['fullName']) ? $pair['fullName'] : $pair['name']; + return $pair['fullName'] ?? $pair['name']; }, $this->structure->getTables())); }