8000 Use Null Coalesce Operator by carusogabriel · Pull Request #2934 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use Null Coalesce Operator #2934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function getDatabase()
*/
public function getHost()
{
return isset($this->_params['host']) ? $this->_params['host'] : null;
return $this->_params['host'] ?? null;
}

/**
Expand All @@ -274,7 +274,7 @@ public function getHost()
*/
public function getPort()
{
return isset($this->_params['port']) ? $this->_params['port'] : null;
return $this->_params['port'] ?? null;
}

/**
Expand All @@ -284,7 +284,7 @@ public function getPort()
*/
public function getUsername()
{
return isset($this->_params['user']) ? $this->_params['user'] : null;
return $this->_params['user'] ?? null;
}

/**
Expand All @@ -294,7 +294,7 @@ public function getUsername()
*/
public function getPassword()
{
return isset($this->_params['password']) ? $this->_params['password'] : null;
return $this->_params['password'] ?? null;
}

/**
Expand Down Expand Up @@ -365,11 +365,9 @@ public function connect()
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;
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function __construct(array $params, Driver $driver, Configuration $config
$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);
}
Expand Down Expand Up @@ -202,12 +202,12 @@ protected function connectTo($connectionName)
{
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ protected function getEasyConnectString(array $params)

}

return isset($params['dbname']) ? $params['dbname'] : '';
return $params['dbname'] ?? '';
}
}
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public function createDatabasePlatformForVersion($version)
}

$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) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function createDatabasePlatformForVersion($version)
}

$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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();

return isset($params['path']) ? $params['path'] : null;
return $params['path'] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
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);
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Driver/OCI8/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function connect(array $params, $username = null, $password = null, array
$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);
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function bindValue($param, $value, $type = 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) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
Expand Down Expand Up @@ -466,7 +466,7 @@ public function fetchColumn($columnIndex = 0)
return false;
}

return isset($row[$columnIndex]) ? $row[$columnIndex] : null;
return $row[$columnIndex] ?? null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOException.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function __construct(\PDOException $exception)

$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();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public function connect(array $params, $username = null, $password = null, array
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$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'],
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function listTableForeignKeys($table, $database = null)

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+)?
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function __construct(array $params, Driver $driver, Configuration $config

/**
* Get active shard id.
*
*
* @return integer
*/
public function getActiveShardId()
Expand Down Expand Up @@ -236,12 +236,12 @@ protected function connectTo($shardId)
{
$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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $exp
public function getDatabaseParameter()
{
$params = TestUtil::getConnection()->getParams();
$realDatabaseName = isset($params['dbname']) ? $params['dbname'] : '';
$realDatabaseName = $params['dbname'] ?? '';
$dummyDatabaseName = $realDatabaseName . 'a';

return array(
Expand All @@ -67,8 +67,8 @@ public function testConnectsWithApplicationNameParameter()
$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);

Expand Down
0