Skip to content

Commit

Permalink
utilization of operator ??
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 15, 2017
1 parent 1af09b8 commit e95a595
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Bridges/DatabaseTracy/ConnectionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/DriverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -49,7 +49,7 @@ public function getDriverCode()
*/
public function getSqlState()
{
return isset($this->errorInfo[0]) ? $this->errorInfo[0] : NULL;
return $this->errorInfo[0] ?? NULL;
}


Expand Down
9 changes: 4 additions & 5 deletions src/Database/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
}
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Drivers/OciDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/PgSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Database/Drivers/SqliteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/SqlsrvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function getColumnTypes(\PDOStatement $statement)
$count = $statement->columnCount();
for ($col = 0; $col < $count; $col++) {
$meta = $statement->getColumnMeta($col);
if (isset($meta['sqlsrv:decl_type']) && $meta['sqlsrv:decl_type'] !== 'timestamp') { // timestamp does not mean time in sqlsrv
if (($meta['sqlsrv:decl_type'] ?? NULL) !== 'timestamp') { // timestamp does not mean time in sqlsrv
$types[$meta['name']] = Nette\Database\Helpers::detectType($meta['sqlsrv:decl_type']);
} elseif (isset($meta['native_type'])) {
$types[$meta['name']] = Nette\Database\Helpers::detectType($meta['native_type']);
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Database/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/GroupedSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ public function getReferencedTable(ActiveRow $row, $table, $column = NULL)
}
}

return isset($selection[$checkPrimaryKey]) ? $selection[$checkPrimaryKey] : NULL;
return $selection[$checkPrimaryKey] ?? NULL;
}


Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/SqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down

0 comments on commit e95a595

Please sign in to comment.