Commit d797e346 authored by Gabriel Caruso's avatar Gabriel Caruso

Use Null Coalesce Operator

parent a4d7acdf
...@@ -264,7 +264,7 @@ class Connection implements DriverConnection ...@@ -264,7 +264,7 @@ class Connection implements DriverConnection
*/ */
public function getHost() public function getHost()
{ {
return isset($this->_params['host']) ? $this->_params['host'] : null; return $this->_params['host'] ?? null;
} }
/** /**
...@@ -274,7 +274,7 @@ class Connection implements DriverConnection ...@@ -274,7 +274,7 @@ class Connection implements DriverConnection
*/ */
public function getPort() public function getPort()
{ {
return isset($this->_params['port']) ? $this->_params['port'] : null; return $this->_params['port'] ?? null;
} }
/** /**
...@@ -284,7 +284,7 @@ class Connection implements DriverConnection ...@@ -284,7 +284,7 @@ class Connection implements DriverConnection
*/ */
public function getUsername() public function getUsername()
{ {
return isset($this->_params['user']) ? $this->_params['user'] : null; return $this->_params['user'] ?? null;
} }
/** /**
...@@ -294,7 +294,7 @@ class Connection implements DriverConnection ...@@ -294,7 +294,7 @@ class Connection implements DriverConnection
*/ */
public function getPassword() public function getPassword()
{ {
return isset($this->_params['password']) ? $this->_params['password'] : null; return $this->_params['password'] ?? null;
} }
/** /**
...@@ -365,11 +365,9 @@ class Connection implements DriverConnection ...@@ -365,11 +365,9 @@ class Connection implements DriverConnection
return false; return false;
} }
$driverOptions = isset($this->_params['driverOptions']) ? $driverOptions = $this->_params['driverOptions'] ?? [];
$this->_params['driverOptions'] : []; $user = $this->_params['user'] ?? null;
$user = isset($this->_params['user']) ? $this->_params['user'] : null; $password = $this->_params['password'] ?? null;
$password = isset($this->_params['password']) ?
$this->_params['password'] : null;
$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
$this->_isConnected = true; $this->_isConnected = true;
......
...@@ -121,7 +121,7 @@ class MasterSlaveConnection extends Connection ...@@ -121,7 +121,7 @@ class MasterSlaveConnection extends Connection
$params['slaves'][$slaveKey]['driver'] = $params['driver']; $params['slaves'][$slaveKey]['driver'] = $params['driver'];
} }
$this->keepSlave = isset($params['keepSlave']) ? (bool) $params['keepSlave'] : false; $this->keepSlave = (bool) ($params['keepSlave'] ?? false);
parent::__construct($params, $driver, $config, $eventManager); parent::__construct($params, $driver, $config, $eventManager);
} }
...@@ -202,12 +202,12 @@ class MasterSlaveConnection extends Connection ...@@ -202,12 +202,12 @@ class MasterSlaveConnection extends Connection
{ {
$params = $this->getParams(); $params = $this->getParams();
$driverOptions = isset($params['driverOptions']) ? $params['driverOptions'] : []; $driverOptions = $params['driverOptions'] ?? [];
$connectionParams = $this->chooseConnectionConfiguration($connectionName, $params); $connectionParams = $this->chooseConnectionConfiguration($connectionName, $params);
$user = isset($connectionParams['user']) ? $connectionParams['user'] : null; $user = $connectionParams['user'] ?? null;
$password = isset($connectionParams['password']) ? $connectionParams['password'] : null; $password = $connectionParams['password'] ?? null;
return $this->_driver->connect($connectionParams, $user, $password, $driverOptions); return $this->_driver->connect($connectionParams, $user, $password, $driverOptions);
} }
......
...@@ -150,6 +150,6 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver ...@@ -150,6 +150,6 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
} }
return isset($params['dbname']) ? $params['dbname'] : ''; return $params['dbname'] ?? '';
} }
} }
...@@ -100,9 +100,9 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -100,9 +100,9 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
} }
$majorVersion = $versionParts['major']; $majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0; $minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0; $patchVersion = $versionParts['patch'] ?? 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0; $buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) { switch(true) {
......
...@@ -54,9 +54,9 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -54,9 +54,9 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
} }
$majorVersion = $versionParts['major']; $majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0; $minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0; $patchVersion = $versionParts['patch'] ?? 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0; $buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) { switch(true) {
......
...@@ -96,7 +96,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver ...@@ -96,7 +96,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return isset($params['path']) ? $params['path'] : null; return $params['path'] ?? null;
} }
/** /**
......
...@@ -227,7 +227,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -227,7 +227,7 @@ class DB2Statement 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 = db2_fetch_object($this->_stmt); $result = db2_fetch_object($this->_stmt);
......
...@@ -49,17 +49,17 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -49,17 +49,17 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/ */
public function __construct(array $params, $username, $password, array $driverOptions = []) public function __construct(array $params, $username, $password, array $driverOptions = [])
{ {
$port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port'); $port = $params['port'] ?? ini_get('mysqli.default_port');
// Fallback to default MySQL port if not given. // Fallback to default MySQL port if not given.
if ( ! $port) { if ( ! $port) {
$port = 3306; $port = 3306;
} }
$socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket'); $socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket');
$dbname = isset($params['dbname']) ? $params['dbname'] : null; $dbname = $params['dbname'] ?? null;
$flags = isset($driverOptions[static::OPTION_FLAGS]) ? $driverOptions[static::OPTION_FLAGS] : null; $flags = $driverOptions[static::OPTION_FLAGS] ?? null;
$this->_conn = mysqli_init(); $this->_conn = mysqli_init();
......
...@@ -40,9 +40,9 @@ class Driver extends AbstractOracleDriver ...@@ -40,9 +40,9 @@ class Driver extends AbstractOracleDriver
$username, $username,
$password, $password,
$this->_constructDsn($params), $this->_constructDsn($params),
isset($params['charset']) ? $params['charset'] : null, $params['charset'] ?? null,
isset($params['sessionMode']) ? $params['sessionMode'] : OCI_DEFAULT, $params['sessionMode'] ?? OCI_DEFAULT,
isset($params['persistent']) ? $params['persistent'] : false $params['persistent'] ?? false
); );
} catch (OCI8Exception $e) { } catch (OCI8Exception $e) {
throw DBALException::driverException($this, $e); throw DBALException::driverException($this, $e);
......
...@@ -264,7 +264,7 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -264,7 +264,7 @@ class OCI8Statement implements IteratorAggregate, Statement
*/ */
public function bindParam($column, &$variable, $type = null, $length = null) public function bindParam($column, &$variable, $type = null, $length = null)
{ {
$column = isset($this->_paramMap[$column]) ? $this->_paramMap[$column] : $column; $column = $this->_paramMap[$column] ?? $column;
if ($type == \PDO::PARAM_LOB) { if ($type == \PDO::PARAM_LOB) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
...@@ -466,7 +466,7 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -466,7 +466,7 @@ class OCI8Statement implements IteratorAggregate, Statement
return false; return false;
} }
return isset($row[$columnIndex]) ? $row[$columnIndex] : null; return $row[$columnIndex] ?? null;
} }
/** /**
......
...@@ -53,8 +53,8 @@ class PDOException extends \PDOException implements DriverException ...@@ -53,8 +53,8 @@ class PDOException extends \PDOException implements DriverException
$this->code = $exception->getCode(); $this->code = $exception->getCode();
$this->errorInfo = $exception->errorInfo; $this->errorInfo = $exception->errorInfo;
$this->errorCode = isset($exception->errorInfo[1]) ? $exception->errorInfo[1] : $exception->getCode(); $this->errorCode = $exception->errorInfo[1] ?? $exception->getCode();
$this->sqlState = isset($exception->errorInfo[0]) ? $exception->errorInfo[0] : $exception->getCode(); $this->sqlState = $exception->errorInfo[0] ?? $exception->getCode();
} }
/** /**
......
...@@ -41,15 +41,15 @@ class Driver extends AbstractSQLAnywhereDriver ...@@ -41,15 +41,15 @@ class Driver extends AbstractSQLAnywhereDriver
try { try {
return new SQLAnywhereConnection( return new SQLAnywhereConnection(
$this->buildDsn( $this->buildDsn(
isset($params['host']) ? $params['host'] : null, $params['host'] ?? null,
isset($params['port']) ? $params['port'] : null, $params['port'] ?? null,
isset($params['server']) ? $params['server'] : null, $params['server'] ?? null,
isset($params['dbname']) ? $params['dbname'] : null, $params['dbname'] ?? null,
$username, $username,
$password, $password,
$driverOptions $driverOptions
), ),
isset($params['persistent']) ? $params['persistent'] : false $params['persistent'] ?? false
); );
} catch (SQLAnywhereException $e) { } catch (SQLAnywhereException $e) {
throw DBALException::driverException($this, $e); throw DBALException::driverException($this, $e);
......
...@@ -42,7 +42,7 @@ class DrizzleSchemaManager extends AbstractSchemaManager ...@@ -42,7 +42,7 @@ class DrizzleSchemaManager extends AbstractSchemaManager
$options = [ $options = [
'notnull' => !(bool) $tableColumn['IS_NULLABLE'], 'notnull' => !(bool) $tableColumn['IS_NULLABLE'],
'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'], 'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'],
'default' => isset($tableColumn['COLUMN_DEFAULT']) ? $tableColumn['COLUMN_DEFAULT'] : null, 'default' => $tableColumn['COLUMN_DEFAULT'] ?? null,
'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'], 'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'],
'scale' => (int) $tableColumn['NUMERIC_SCALE'], 'scale' => (int) $tableColumn['NUMERIC_SCALE'],
'precision' => (int) $tableColumn['NUMERIC_PRECISION'], 'precision' => (int) $tableColumn['NUMERIC_PRECISION'],
......
...@@ -118,7 +118,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -118,7 +118,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
if ( ! empty($tableForeignKeys)) { if ( ! empty($tableForeignKeys)) {
$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'] ?? '';
if (preg_match_all('# if (preg_match_all('#
(?:CONSTRAINT\s+([^\s]+)\s+)? (?:CONSTRAINT\s+([^\s]+)\s+)?
......
...@@ -236,12 +236,12 @@ class PoolingShardConnection extends Connection ...@@ -236,12 +236,12 @@ class PoolingShardConnection extends Connection
{ {
$params = $this->getParams(); $params = $this->getParams();
$driverOptions = isset($params['driverOptions']) ? $params['driverOptions'] : []; $driverOptions = $params['driverOptions'] ?? [];
$connectionParams = $this->connections[$shardId]; $connectionParams = $this->connections[$shardId];
$user = isset($connectionParams['user']) ? $connectionParams['user'] : null; $user = $connectionParams['user'] ?? null;
$password = isset($connectionParams['password']) ? $connectionParams['password'] : null; $password = $connectionParams['password'] ?? null;
return $this->_driver->connect($connectionParams, $user, $password, $driverOptions); return $this->_driver->connect($connectionParams, $user, $password, $driverOptions);
} }
......
...@@ -47,7 +47,7 @@ class DriverTest extends AbstractDriverTest ...@@ -47,7 +47,7 @@ class DriverTest extends AbstractDriverTest
public function getDatabaseParameter() public function getDatabaseParameter()
{ {
$params = TestUtil::getConnection()->getParams(); $params = TestUtil::getConnection()->getParams();
$realDatabaseName = isset($params['dbname']) ? $params['dbname'] : ''; $realDatabaseName = $params['dbname'] ?? '';
$dummyDatabaseName = $realDatabaseName . 'a'; $dummyDatabaseName = $realDatabaseName . 'a';
return array( return array(
...@@ -67,8 +67,8 @@ class DriverTest extends AbstractDriverTest ...@@ -67,8 +67,8 @@ class DriverTest extends AbstractDriverTest
$parameters = $this->_conn->getParams(); $parameters = $this->_conn->getParams();
$parameters['application_name'] = 'doctrine'; $parameters['application_name'] = 'doctrine';
$user = isset($parameters['user']) ? $parameters['user'] : null; $user = $parameters['user'] ?? null;
$password = isset($parameters['password']) ? $parameters['password'] : null; $password = $parameters['password'] ?? null;
$connection = $this->driver->connect($parameters, $user, $password); $connection = $this->driver->connect($parameters, $user, $password);
......
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