Commit 80304590 authored by Gabriel Caruso's avatar Gabriel Caruso

Use Null Coalesce Operator

parent e3ab1276
...@@ -138,11 +138,8 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -138,11 +138,8 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
public function fetchColumn($columnIndex = 0) public function fetchColumn($columnIndex = 0)
{ {
$row = $this->fetch(PDO::FETCH_NUM); $row = $this->fetch(PDO::FETCH_NUM);
if (!isset($row[$columnIndex])) {
// TODO: verify this is correct behavior
return false;
}
return $row[$columnIndex]; // TODO: verify this is correct behavior
return $row[$columnIndex] ?? false;
} }
} }
...@@ -195,12 +195,9 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -195,12 +195,9 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
public function fetchColumn($columnIndex = 0) public function fetchColumn($columnIndex = 0)
{ {
$row = $this->fetch(PDO::FETCH_NUM); $row = $this->fetch(PDO::FETCH_NUM);
if (!isset($row[$columnIndex])) {
// TODO: verify this is correct behavior
return false;
}
return $row[$columnIndex]; // TODO: verify this is correct behavior
return $row[$columnIndex] ?? false;
} }
/** /**
......
...@@ -109,11 +109,7 @@ class Configuration ...@@ -109,11 +109,7 @@ class Configuration
*/ */
public function getFilterSchemaAssetsExpression() public function getFilterSchemaAssetsExpression()
{ {
if (isset($this->_attributes['filterSchemaAssetsExpression'])) { return $this->_attributes['filterSchemaAssetsExpression'] ?? null;
return $this->_attributes['filterSchemaAssetsExpression'];
}
return null;
} }
/** /**
...@@ -141,10 +137,6 @@ class Configuration ...@@ -141,10 +137,6 @@ class Configuration
*/ */
public function getAutoCommit() public function getAutoCommit()
{ {
if (isset($this->_attributes['autoCommit'])) { return $this->_attributes['autoCommit'] ?? true;
return $this->_attributes['autoCommit'];
}
return true;
} }
} }
...@@ -800,9 +800,7 @@ class Connection implements DriverConnection ...@@ -800,9 +800,7 @@ class Connection implements DriverConnection
$typeValues = []; $typeValues = [];
foreach ($columnList as $columnIndex => $columnName) { foreach ($columnList as $columnIndex => $columnName) {
$typeValues[] = isset($types[$columnName]) $typeValues[] = $types[$columnName] ?? \PDO::PARAM_STR;
? $types[$columnName]
: \PDO::PARAM_STR;
} }
return $typeValues; return $typeValues;
......
...@@ -201,11 +201,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -201,11 +201,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
{ {
$params = $conn->getParams(); $params = $conn->getParams();
if (isset($params['dbname'])) { return $params['dbname'] ?? $conn->query('SELECT DATABASE()')->fetchColumn();
return $params['dbname'];
}
return $conn->query('SELECT DATABASE()')->fetchColumn();
} }
/** /**
......
...@@ -134,9 +134,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri ...@@ -134,9 +134,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return (isset($params['dbname'])) return $params['dbname'] ?? $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
? $params['dbname']
: $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
} }
/** /**
......
...@@ -124,11 +124,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -124,11 +124,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
{ {
$params = $conn->getParams(); $params = $conn->getParams();
if (isset($params['dbname'])) { return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn();
return $params['dbname'];
}
return $conn->query('SELECT DB_NAME()')->fetchColumn();
} }
/** /**
......
...@@ -78,11 +78,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -78,11 +78,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
{ {
$params = $conn->getParams(); $params = $conn->getParams();
if (isset($params['dbname'])) { return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn();
return $params['dbname'];
}
return $conn->query('SELECT DB_NAME()')->fetchColumn();
} }
/** /**
......
...@@ -284,7 +284,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -284,7 +284,7 @@ class DB2Statement implements \IteratorAggregate, Statement
return false; return false;
} }
return isset($row[$columnIndex]) ? $row[$columnIndex] : null; return $row[$columnIndex] ?? null;
} }
/** /**
......
...@@ -342,7 +342,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -342,7 +342,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
return false; return false;
} }
return isset($row[$columnIndex]) ? $row[$columnIndex] : null; return $row[$columnIndex] ?? null;
} }
/** /**
......
...@@ -214,7 +214,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -214,7 +214,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
if (func_num_args() >= 2) { if (func_num_args() >= 2) {
$args = func_get_args(); $args = func_get_args();
$className = $args[1]; $className = $args[1];
$ctorArgs = isset($args[2]) ? $args[2] : []; $ctorArgs = $args[2] ?? [];
} }
$result = sasql_fetch_object($this->result); $result = sasql_fetch_object($this->result);
...@@ -271,7 +271,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -271,7 +271,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
return false; return false;
} }
return isset($row[$columnIndex]) ? $row[$columnIndex] : null; return $row[$columnIndex] ?? null;
} }
/** /**
......
...@@ -325,7 +325,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -325,7 +325,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
if (count($args) >= 2) { if (count($args) >= 2) {
$className = $args[1]; $className = $args[1];
$ctorArgs = isset($args[2]) ? $args[2] : []; $ctorArgs = $args[2] ?? [];
} }
return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false; return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false;
...@@ -372,7 +372,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -372,7 +372,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
return false; return false;
} }
return isset($row[$columnIndex]) ? $row[$columnIndex] : null; return $row[$columnIndex] ?? null;
} }
/** /**
......
...@@ -152,11 +152,8 @@ final class DriverManager ...@@ -152,11 +152,8 @@ final class DriverManager
} else { } else {
self::_checkParams($params); self::_checkParams($params);
} }
if (isset($params['driverClass'])) {
$className = $params['driverClass']; $className = $params['driverClass'] ?? $className = self::$_driverMap[$params['driver']];
} else {
$className = self::$_driverMap[$params['driver']];
}
$driver = new $className(); $driver = new $className();
...@@ -398,11 +395,9 @@ final class DriverManager ...@@ -398,11 +395,9 @@ final class DriverManager
// The requested driver from the URL scheme takes precedence // The requested driver from the URL scheme takes precedence
// over the default driver from the connection parameters (if any). // over the default driver from the connection parameters (if any).
$params['driver'] = isset(self::$driverSchemeAliases[$driver]) $params['driver'] = self::$driverSchemeAliases[$driver] ?? $driver;
// use alias like "postgres", else we just let checkParams decide later // use alias like "postgres", else we just let checkParams decide later
// if the driver exists (for literal "pdo-pgsql" etc) // if the driver exists (for literal "pdo-pgsql" etc)
? self::$driverSchemeAliases[$driver]
: $driver;
return $params; return $params;
} }
......
...@@ -263,7 +263,7 @@ abstract class AbstractPlatform ...@@ -263,7 +263,7 @@ abstract class AbstractPlatform
$field['length'] = $this->getVarcharDefaultLength(); $field['length'] = $this->getVarcharDefaultLength();
} }
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false; $fixed = $field['fixed'] ?? false;
if ($field['length'] > $this->getVarcharMaxLength()) { if ($field['length'] > $this->getVarcharMaxLength()) {
return $this->getClobTypeDeclarationSQL($field); return $this->getClobTypeDeclarationSQL($field);
...@@ -285,7 +285,7 @@ abstract class AbstractPlatform ...@@ -285,7 +285,7 @@ abstract class AbstractPlatform
$field['length'] = $this->getBinaryDefaultLength(); $field['length'] = $this->getBinaryDefaultLength();
} }
$fixed = isset($field['fixed']) ? $field['fixed'] : false; $fixed = $field['fixed'] ?? false;
if ($field['length'] > $this->getBinaryMaxLength()) { if ($field['length'] > $this->getBinaryMaxLength()) {
return $this->getBlobTypeDeclarationSQL($field); return $this->getBlobTypeDeclarationSQL($field);
......
...@@ -386,7 +386,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -386,7 +386,7 @@ class OraclePlatform extends AbstractPlatform
*/ */
protected function _getCreateTableSQL($table, array $columns, array $options = []) protected function _getCreateTableSQL($table, array $columns, array $options = [])
{ {
$indexes = isset($options['indexes']) ? $options['indexes'] : []; $indexes = $options['indexes'] ?? [];
$options['indexes'] = []; $options['indexes'] = [];
$sql = parent::_getCreateTableSQL($table, $columns, $options); $sql = parent::_getCreateTableSQL($table, $columns, $options);
......
...@@ -862,7 +862,7 @@ abstract class AbstractSchemaManager ...@@ -862,7 +862,7 @@ abstract class AbstractSchemaManager
'columns' => [$tableIndex['column_name']], 'columns' => [$tableIndex['column_name']],
'unique' => $tableIndex['non_unique'] ? false : true, 'unique' => $tableIndex['non_unique'] ? false : true,
'primary' => $tableIndex['primary'], 'primary' => $tableIndex['primary'],
'flags' => isset($tableIndex['flags']) ? $tableIndex['flags'] : [], 'flags' => $tableIndex['flags'] ?? [],
'options' => isset($tableIndex['where']) ? ['where' => $tableIndex['where']] : [], 'options' => isset($tableIndex['where']) ? ['where' => $tableIndex['where']] : [],
]; ];
} else { } else {
......
...@@ -109,11 +109,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -109,11 +109,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['type']); $dbType = strtolower($tableColumn['type']);
$dbType = strtok($dbType, '(), '); $dbType = strtok($dbType, '(), ');
if (isset($tableColumn['length'])) { $length = $tableColumn['length'] ?? strtok('(), ');
$length = $tableColumn['length'];
} else {
$length = strtok('(), ');
}
$fixed = null; $fixed = null;
......
...@@ -327,7 +327,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -327,7 +327,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$tableColumn['default'] = null; $tableColumn['default'] = null;
} }
$length = (isset($tableColumn['length'])) ? $tableColumn['length'] : null; $length = $tableColumn['length'] ?? null;
if ($length == '-1' && isset($tableColumn['atttypmod'])) { if ($length == '-1' && isset($tableColumn['atttypmod'])) {
$length = $tableColumn['atttypmod'] - 4; $length = $tableColumn['atttypmod'] - 4;
} }
......
...@@ -253,7 +253,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -253,7 +253,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
// inspect column collation and comments // inspect column collation and comments
$createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'"); $createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'");
$createSql = isset($createSql[0]['sql']) ? $createSql[0]['sql'] : ''; $createSql = $createSql[0]['sql'] ?? '';
foreach ($list as $columnName => $column) { foreach ($list as $columnName => $column) {
$type = $column->getType(); $type = $column->getType();
...@@ -293,7 +293,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -293,7 +293,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
} }
$dbType = strtolower($tableColumn['type']); $dbType = strtolower($tableColumn['type']);
$length = isset($tableColumn['length']) ? $tableColumn['length'] : null; $length = $tableColumn['length'] ?? null;
$unsigned = false; $unsigned = false;
if (strpos($dbType, ' unsigned') !== false) { if (strpos($dbType, ' unsigned') !== false) {
......
...@@ -86,7 +86,7 @@ class SQLAzureShardManager implements ShardManager ...@@ -86,7 +86,7 @@ class SQLAzureShardManager implements ShardManager
$this->federationName = $params['sharding']['federationName']; $this->federationName = $params['sharding']['federationName'];
$this->distributionKey = $params['sharding']['distributionKey']; $this->distributionKey = $params['sharding']['distributionKey'];
$this->distributionType = $params['sharding']['distributionType']; $this->distributionType = $params['sharding']['distributionType'];
$this->filteringEnabled = (isset($params['sharding']['filteringEnabled'])) ? (bool) $params['sharding']['filteringEnabled'] : false; $this->filteringEnabled = (bool) ($params['sharding']['filteringEnabled'] ?? false);
} }
/** /**
......
...@@ -873,10 +873,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -873,10 +873,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
*/ */
protected function createTestTable($name = 'test_table', $data = array()) protected function createTestTable($name = 'test_table', $data = array())
{ {
$options = array(); $options = $data['options'] ?? array();
if (isset($data['options'])) {
$options = $data['options'];
}
$table = $this->getTestTable($name, $options); $table = $this->getTestTable($name, $options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment