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
public function fetchColumn($columnIndex = 0)
{
$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
public function fetchColumn($columnIndex = 0)
{
$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
*/
public function getFilterSchemaAssetsExpression()
{
if (isset($this->_attributes['filterSchemaAssetsExpression'])) {
return $this->_attributes['filterSchemaAssetsExpression'];
}
return null;
return $this->_attributes['filterSchemaAssetsExpression'] ?? null;
}
/**
......@@ -141,10 +137,6 @@ class Configuration
*/
public function getAutoCommit()
{
if (isset($this->_attributes['autoCommit'])) {
return $this->_attributes['autoCommit'];
}
return true;
return $this->_attributes['autoCommit'] ?? true;
}
}
......@@ -800,9 +800,7 @@ class Connection implements DriverConnection
$typeValues = [];
foreach ($columnList as $columnIndex => $columnName) {
$typeValues[] = isset($types[$columnName])
? $types[$columnName]
: \PDO::PARAM_STR;
$typeValues[] = $types[$columnName] ?? \PDO::PARAM_STR;
}
return $typeValues;
......
......@@ -201,11 +201,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DATABASE()')->fetchColumn();
return $params['dbname'] ?? $conn->query('SELECT DATABASE()')->fetchColumn();
}
/**
......
......@@ -134,9 +134,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
{
$params = $conn->getParams();
return (isset($params['dbname']))
? $params['dbname']
: $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
return $params['dbname'] ?? $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
}
/**
......
......@@ -124,11 +124,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DB_NAME()')->fetchColumn();
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn();
}
/**
......
......@@ -78,11 +78,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
{
$params = $conn->getParams();
if (isset($params['dbname'])) {
return $params['dbname'];
}
return $conn->query('SELECT DB_NAME()')->fetchColumn();
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn();
}
/**
......
......@@ -284,7 +284,7 @@ class DB2Statement implements \IteratorAggregate, Statement
return false;
}
return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
return $row[$columnIndex] ?? null;
}
/**
......
......@@ -342,7 +342,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
return false;
}
return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
return $row[$columnIndex] ?? null;
}
/**
......
......@@ -214,7 +214,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
if (func_num_args() >= 2) {
$args = func_get_args();
$className = $args[1];
$ctorArgs = isset($args[2]) ? $args[2] : [];
$ctorArgs = $args[2] ?? [];
}
$result = sasql_fetch_object($this->result);
......@@ -271,7 +271,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
return false;
}
return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
return $row[$columnIndex] ?? null;
}
/**
......
......@@ -325,7 +325,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
if (count($args) >= 2) {
$className = $args[1];
$ctorArgs = isset($args[2]) ? $args[2] : [];
$ctorArgs = $args[2] ?? [];
}
return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false;
......@@ -372,7 +372,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
return false;
}
return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
return $row[$columnIndex] ?? null;
}
/**
......
......@@ -152,11 +152,8 @@ final class DriverManager
} else {
self::_checkParams($params);
}
if (isset($params['driverClass'])) {
$className = $params['driverClass'];
} else {
$className = self::$_driverMap[$params['driver']];
}
$className = $params['driverClass'] ?? $className = self::$_driverMap[$params['driver']];
$driver = new $className();
......@@ -398,11 +395,9 @@ final class DriverManager
// The requested driver from the URL scheme takes precedence
// over the default driver from the connection parameters (if any).
$params['driver'] = isset(self::$driverSchemeAliases[$driver])
// use alias like "postgres", else we just let checkParams decide later
// if the driver exists (for literal "pdo-pgsql" etc)
? self::$driverSchemeAliases[$driver]
: $driver;
$params['driver'] = self::$driverSchemeAliases[$driver] ?? $driver;
// use alias like "postgres", else we just let checkParams decide later
// if the driver exists (for literal "pdo-pgsql" etc)
return $params;
}
......
......@@ -263,7 +263,7 @@ abstract class AbstractPlatform
$field['length'] = $this->getVarcharDefaultLength();
}
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
$fixed = $field['fixed'] ?? false;
if ($field['length'] > $this->getVarcharMaxLength()) {
return $this->getClobTypeDeclarationSQL($field);
......@@ -285,7 +285,7 @@ abstract class AbstractPlatform
$field['length'] = $this->getBinaryDefaultLength();
}
$fixed = isset($field['fixed']) ? $field['fixed'] : false;
$fixed = $field['fixed'] ?? false;
if ($field['length'] > $this->getBinaryMaxLength()) {
return $this->getBlobTypeDeclarationSQL($field);
......
......@@ -386,7 +386,7 @@ class OraclePlatform extends AbstractPlatform
*/
protected function _getCreateTableSQL($table, array $columns, array $options = [])
{
$indexes = isset($options['indexes']) ? $options['indexes'] : [];
$indexes = $options['indexes'] ?? [];
$options['indexes'] = [];
$sql = parent::_getCreateTableSQL($table, $columns, $options);
......
......@@ -862,7 +862,7 @@ abstract class AbstractSchemaManager
'columns' => [$tableIndex['column_name']],
'unique' => $tableIndex['non_unique'] ? false : true,
'primary' => $tableIndex['primary'],
'flags' => isset($tableIndex['flags']) ? $tableIndex['flags'] : [],
'flags' => $tableIndex['flags'] ?? [],
'options' => isset($tableIndex['where']) ? ['where' => $tableIndex['where']] : [],
];
} else {
......
......@@ -109,11 +109,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['type']);
$dbType = strtok($dbType, '(), ');
if (isset($tableColumn['length'])) {
$length = $tableColumn['length'];
} else {
$length = strtok('(), ');
}
$length = $tableColumn['length'] ?? strtok('(), ');
$fixed = null;
......
......@@ -327,7 +327,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$tableColumn['default'] = null;
}
$length = (isset($tableColumn['length'])) ? $tableColumn['length'] : null;
$length = $tableColumn['length'] ?? null;
if ($length == '-1' && isset($tableColumn['atttypmod'])) {
$length = $tableColumn['atttypmod'] - 4;
}
......
......@@ -253,7 +253,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
// 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 = isset($createSql[0]['sql']) ? $createSql[0]['sql'] : '';
$createSql = $createSql[0]['sql'] ?? '';
foreach ($list as $columnName => $column) {
$type = $column->getType();
......@@ -293,7 +293,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
}
$dbType = strtolower($tableColumn['type']);
$length = isset($tableColumn['length']) ? $tableColumn['length'] : null;
$length = $tableColumn['length'] ?? null;
$unsigned = false;
if (strpos($dbType, ' unsigned') !== false) {
......
......@@ -86,7 +86,7 @@ class SQLAzureShardManager implements ShardManager
$this->federationName = $params['sharding']['federationName'];
$this->distributionKey = $params['sharding']['distributionKey'];
$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
*/
protected function createTestTable($name = 'test_table', $data = array())
{
$options = array();
if (isset($data['options'])) {
$options = $data['options'];
}
$options = $data['options'] ?? array();
$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