Unverified Commit 2742cd1d authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #2934 from carusogabriel/php-7

Use Null Coalesce Operator
parents 6565790f d797e346
......@@ -264,7 +264,7 @@ class Connection implements DriverConnection
*/
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
*/
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
*/
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
*/
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
return false;
}
$driverOptions = isset($this->_params['driverOptions']) ?
$this->_params['driverOptions'] : [];
$user = isset($this->_params['user']) ? $this->_params['user'] : null;
$password = isset($this->_params['password']) ?
$this->_params['password'] : null;
$driverOptions = $this->_params['driverOptions'] ?? [];
$user = $this->_params['user'] ?? null;
$password = $this->_params['password'] ?? null;
$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
$this->_isConnected = true;
......
......@@ -121,7 +121,7 @@ class MasterSlaveConnection extends Connection
$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);
}
......@@ -202,12 +202,12 @@ class MasterSlaveConnection extends Connection
{
$params = $this->getParams();
$driverOptions = isset($params['driverOptions']) ? $params['driverOptions'] : [];
$driverOptions = $params['driverOptions'] ?? [];
$connectionParams = $this->chooseConnectionConfiguration($connectionName, $params);
$user = isset($connectionParams['user']) ? $connectionParams['user'] : null;
$password = isset($connectionParams['password']) ? $connectionParams['password'] : null;
$user = $connectionParams['user'] ?? null;
$password = $connectionParams['password'] ?? null;
return $this->_driver->connect($connectionParams, $user, $password, $driverOptions);
}
......
......@@ -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
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? 0;
$buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) {
......
......@@ -54,9 +54,9 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0;
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? 0;
$buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) {
......
......@@ -96,7 +96,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
{
$params = $conn->getParams();
return isset($params['path']) ? $params['path'] : null;
return $params['path'] ?? null;
}
/**
......
......@@ -227,7 +227,7 @@ class DB2Statement 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 = db2_fetch_object($this->_stmt);
......
......@@ -49,17 +49,17 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/
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.
if ( ! $port) {
$port = 3306;
}
$socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
$dbname = isset($params['dbname']) ? $params['dbname'] : null;
$socket = $params['unix_socket'] ?? ini_get('mysqli.default_socket');
$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();
......
......@@ -40,9 +40,9 @@ class Driver extends AbstractOracleDriver
$username,
$password,
$this->_constructDsn($params),
isset($params['charset']) ? $params['charset'] : null,
isset($params['sessionMode']) ? $params['sessionMode'] : OCI_DEFAULT,
isset($params['persistent']) ? $params['persistent'] : false
$params['charset'] ?? null,
$params['sessionMode'] ?? OCI_DEFAULT,
$params['persistent'] ?? false
);
} catch (OCI8Exception $e) {
throw DBALException::driverException($this, $e);
......
......@@ -264,7 +264,7 @@ class OCI8Statement implements IteratorAggregate, Statement
*/
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) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
......@@ -466,7 +466,7 @@ class OCI8Statement implements IteratorAggregate, Statement
return false;
}
return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
return $row[$columnIndex] ?? null;
}
/**
......
......@@ -53,8 +53,8 @@ class PDOException extends \PDOException implements DriverException
$this->code = $exception->getCode();
$this->errorInfo = $exception->errorInfo;
$this->errorCode = isset($exception->errorInfo[1]) ? $exception->errorInfo[1] : $exception->getCode();
$this->sqlState = isset($exception->errorInfo[0]) ? $exception->errorInfo[0] : $exception->getCode();
$this->errorCode = $exception->errorInfo[1] ?? $exception->getCode();
$this->sqlState = $exception->errorInfo[0] ?? $exception->getCode();
}
/**
......
......@@ -41,15 +41,15 @@ class Driver extends AbstractSQLAnywhereDriver
try {
return new SQLAnywhereConnection(
$this->buildDsn(
isset($params['host']) ? $params['host'] : null,
isset($params['port']) ? $params['port'] : null,
isset($params['server']) ? $params['server'] : null,
isset($params['dbname']) ? $params['dbname'] : null,
$params['host'] ?? null,
$params['port'] ?? null,
$params['server'] ?? null,
$params['dbname'] ?? null,
$username,
$password,
$driverOptions
),
isset($params['persistent']) ? $params['persistent'] : false
$params['persistent'] ?? false
);
} catch (SQLAnywhereException $e) {
throw DBALException::driverException($this, $e);
......
......@@ -42,7 +42,7 @@ class DrizzleSchemaManager extends AbstractSchemaManager
$options = [
'notnull' => !(bool) $tableColumn['IS_NULLABLE'],
'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'],
'scale' => (int) $tableColumn['NUMERIC_SCALE'],
'precision' => (int) $tableColumn['NUMERIC_PRECISION'],
......
......@@ -118,7 +118,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
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 = isset($createSql[0]['sql']) ? $createSql[0]['sql'] : '';
$createSql = $createSql[0]['sql'] ?? '';
if (preg_match_all('#
(?:CONSTRAINT\s+([^\s]+)\s+)?
......
......@@ -236,12 +236,12 @@ class PoolingShardConnection extends Connection
{
$params = $this->getParams();
$driverOptions = isset($params['driverOptions']) ? $params['driverOptions'] : [];
$driverOptions = $params['driverOptions'] ?? [];
$connectionParams = $this->connections[$shardId];
$user = isset($connectionParams['user']) ? $connectionParams['user'] : null;
$password = isset($connectionParams['password']) ? $connectionParams['password'] : null;
$user = $connectionParams['user'] ?? null;
$password = $connectionParams['password'] ?? null;
return $this->_driver->connect($connectionParams, $user, $password, $driverOptions);
}
......
......@@ -47,7 +47,7 @@ class DriverTest extends AbstractDriverTest
public function getDatabaseParameter()
{
$params = TestUtil::getConnection()->getParams();
$realDatabaseName = isset($params['dbname']) ? $params['dbname'] : '';
$realDatabaseName = $params['dbname'] ?? '';
$dummyDatabaseName = $realDatabaseName . 'a';
return array(
......@@ -67,8 +67,8 @@ class DriverTest extends AbstractDriverTest
$parameters = $this->_conn->getParams();
$parameters['application_name'] = 'doctrine';
$user = isset($parameters['user']) ? $parameters['user'] : null;
$password = isset($parameters['password']) ? $parameters['password'] : null;
$user = $parameters['user'] ?? null;
$password = $parameters['password'] ?? null;
$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