Avoid implicit conversion to boolean

parent 6c4401f4
......@@ -88,5 +88,14 @@ parameters:
- %currentWorkingDirectory%/src/Driver/AbstractOracleDriver/EasyConnectString.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php
# In some namespaces, we use array<string,mixed>, some elements of which are actually boolean
-
message: '~^Only booleans are allowed in .*, mixed given~'
paths:
- %currentWorkingDirectory%/src/Driver/*/Driver.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Query/QueryBuilder.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
......@@ -32,7 +32,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
public function __construct(array $data)
{
$this->data = $data;
if (! count($data)) {
if (count($data) === 0) {
return;
}
......
......@@ -82,7 +82,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
}
$data = $this->resultCache->fetch($this->cacheKey);
if (! $data) {
if ($data === false) {
$data = [];
}
$data[$this->realKey] = $this->data;
......@@ -132,7 +132,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
$row = $this->statement->fetch(FetchMode::ASSOCIATIVE);
if ($row) {
if ($row !== false) {
$this->data[] = $row;
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
......
......@@ -72,14 +72,14 @@ class Configuration
*
* @deprecated Use Configuration::setSchemaAssetsFilter() instead
*
* @param string $filterExpression
* @param string|null $filterExpression
*
* @return void
*/
public function setFilterSchemaAssetsExpression($filterExpression)
{
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
if ($filterExpression !== null) {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression);
} else {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = null;
......
......@@ -197,11 +197,11 @@ class Connection implements DriverConnection
}
// Create default config and event manager if none given
if (! $config) {
if ($config === null) {
$config = new Configuration();
}
if (! $eventManager) {
if ($eventManager === null) {
$eventManager = new EventManager();
}
......@@ -884,16 +884,16 @@ class Connection implements DriverConnection
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
if ($logger) {
if ($logger !== null) {
$logger->startQuery($query, $params, $types);
}
try {
if ($params) {
if (count($params) > 0) {
[$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types);
$stmt = $connection->prepare($query);
if ($types) {
if (count($types) > 0) {
$this->_bindTypedValues($stmt, $params, $types);
$stmt->execute();
} else {
......@@ -908,7 +908,7 @@ class Connection implements DriverConnection
$stmt->setFetchMode($this->defaultFetchMode);
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
......@@ -993,7 +993,7 @@ class Connection implements DriverConnection
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
if ($logger) {
if ($logger !== null) {
$logger->startQuery($sql);
}
......@@ -1005,7 +1005,7 @@ class Connection implements DriverConnection
$statement->setFetchMode($this->defaultFetchMode);
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
......@@ -1029,17 +1029,17 @@ class Connection implements DriverConnection
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
if ($logger) {
if ($logger !== null) {
$logger->startQuery($query, $params, $types);
}
try {
if ($params) {
if (count($params) > 0) {
[$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types);
$stmt = $connection->prepare($query);
if ($types) {
if (count($types) > 0) {
$this->_bindTypedValues($stmt, $params, $types);
$stmt->execute();
} else {
......@@ -1053,7 +1053,7 @@ class Connection implements DriverConnection
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types));
}
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
......@@ -1068,7 +1068,7 @@ class Connection implements DriverConnection
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
if ($logger) {
if ($logger !== null) {
$logger->startQuery($statement);
}
......@@ -1078,7 +1078,7 @@ class Connection implements DriverConnection
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
}
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
......@@ -1217,21 +1217,21 @@ class Connection implements DriverConnection
$logger = $this->_config->getSQLLogger();
if ($this->transactionNestingLevel === 1) {
if ($logger) {
if ($logger !== null) {
$logger->startQuery('"START TRANSACTION"');
}
$connection->beginTransaction();
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
} elseif ($this->nestTransactionsWithSavepoints) {
if ($logger) {
if ($logger !== null) {
$logger->startQuery('"SAVEPOINT"');
}
$this->createSavepoint($this->_getNestedTransactionSavePointName());
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
}
......@@ -1261,21 +1261,21 @@ class Connection implements DriverConnection
$logger = $this->_config->getSQLLogger();
if ($this->transactionNestingLevel === 1) {
if ($logger) {
if ($logger !== null) {
$logger->startQuery('"COMMIT"');
}
$result = $connection->commit();
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
} elseif ($this->nestTransactionsWithSavepoints) {
if ($logger) {
if ($logger !== null) {
$logger->startQuery('"RELEASE SAVEPOINT"');
}
$this->releaseSavepoint($this->_getNestedTransactionSavePointName());
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
}
......@@ -1327,13 +1327,13 @@ class Connection implements DriverConnection
$logger = $this->_config->getSQLLogger();
if ($this->transactionNestingLevel === 1) {
if ($logger) {
if ($logger !== null) {
$logger->startQuery('"ROLLBACK"');
}
$this->transactionNestingLevel = 0;
$connection->rollBack();
$this->isRollbackOnly = false;
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
......@@ -1341,12 +1341,12 @@ class Connection implements DriverConnection
$this->beginTransaction();
}
} elseif ($this->nestTransactionsWithSavepoints) {
if ($logger) {
if ($logger !== null) {
$logger->startQuery('"ROLLBACK TO SAVEPOINT"');
}
$this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
--$this->transactionNestingLevel;
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
} else {
......
......@@ -351,7 +351,7 @@ class MasterSlaveConnection extends Connection
assert($this->_conn instanceof DriverConnection);
$logger = $this->getConfiguration()->getSQLLogger();
if ($logger) {
if ($logger !== null) {
$logger->startQuery($sql);
}
......@@ -359,7 +359,7 @@ class MasterSlaveConnection extends Connection
$statement->setFetchMode($this->defaultFetchMode);
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
......
......@@ -11,6 +11,7 @@ use Exception;
use Throwable;
use function array_map;
use function bin2hex;
use function count;
use function get_class;
use function gettype;
use function implode;
......@@ -103,7 +104,7 @@ class DBALException extends Exception
*/
public static function driverRequired($url = null)
{
if ($url) {
if ($url !== null) {
return new self(
sprintf(
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " .
......@@ -138,7 +139,7 @@ class DBALException extends Exception
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
{
$msg = "An exception occurred while executing '" . $sql . "'";
if ($params) {
if (count($params) > 0) {
$msg .= ' with params ' . self::formatParameters($params);
}
$msg .= ":\n\n" . $driverEx->getMessage();
......
......@@ -140,11 +140,11 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
*/
private function getOracleMysqlVersionNumber(string $versionString) : string
{
if (! preg_match(
if (preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
)) {
) === 0) {
throw DBALException::invalidPlatformVersionSpecified(
$versionString,
'<major_version>.<minor_version>.<patch_version>'
......@@ -171,11 +171,11 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
*/
private function getMariaDbMysqlVersionNumber(string $versionString) : string
{
if (! preg_match(
if (preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
)) {
) === 0) {
throw DBALException::invalidPlatformVersionSpecified(
$versionString,
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>'
......
......@@ -80,7 +80,7 @@ abstract class AbstractPostgreSQLDriver implements ExceptionConverterDriver, Ver
*/
public function createDatabasePlatformForVersion($version)
{
if (! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) === 0) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
......
......@@ -65,11 +65,11 @@ abstract class AbstractSQLAnywhereDriver implements ExceptionConverterDriver, Ve
*/
public function createDatabasePlatformForVersion($version)
{
if (! preg_match(
if (preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
)) {
) === 0) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>.<build_version>'
......
......@@ -81,7 +81,7 @@ class DB2Connection implements ServerInfoAwareConnection
public function prepare(string $sql) : DriverStatement
{
$stmt = @db2_prepare($this->conn, $sql);
if (! $stmt) {
if ($stmt === false) {
throw new DB2Exception(db2_stmt_errormsg());
}
......
......@@ -80,7 +80,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
}
if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches)) {
if (preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches) === 0) {
throw new UnexpectedValueException(
sprintf(
'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' .
......
......@@ -191,7 +191,7 @@ class OCI8Statement implements IteratorAggregate, Statement
) {
$token = self::findToken($statement, $tokenOffset, '/[?\'"]/');
if (! $token) {
if ($token === null) {
return false;
}
......@@ -233,7 +233,7 @@ class OCI8Statement implements IteratorAggregate, Statement
'/' . preg_quote($currentLiteralDelimiter, '/') . '/'
);
if (! $token) {
if ($token === null) {
return false;
}
......@@ -255,7 +255,7 @@ class OCI8Statement implements IteratorAggregate, Statement
*/
private static function findToken($statement, &$offset, $regex)
{
if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset)) {
if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset) === 1) {
$offset = $matches[0][1];
return $matches[0][0];
......@@ -387,9 +387,8 @@ class OCI8Statement implements IteratorAggregate, Statement
*/
public function execute($params = null)
{
if ($params) {
if ($params !== null) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
if ($hasZeroIndex && is_int($key)) {
$this->bindValue($key + 1, $val);
......
......@@ -27,14 +27,14 @@ class SQLAnywhereException extends AbstractDriverException
*/
public static function fromSQLAnywhereError($conn = null, $stmt = null)
{
$state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
$code = null;
$state = $conn !== null ? sasql_sqlstate($conn) : sasql_sqlstate();
$code = 0;
$message = null;
/**
* Try retrieving the last error from statement resource if given
*/
if ($stmt) {
if ($stmt !== null) {
$code = sasql_stmt_errno($stmt);
$message = sasql_stmt_error($stmt);
}
......@@ -47,7 +47,7 @@ class SQLAnywhereException extends AbstractDriverException
* it from the connection resource even though it occurred during
* a prepared statement.
*/
if ($conn && ! $code) {
if ($conn !== null && $code === 0) {
$code = sasql_errorcode($conn);
$message = sasql_error($conn);
}
......@@ -57,7 +57,7 @@ class SQLAnywhereException extends AbstractDriverException
* or the last error could not be retrieved from the given
* connection / statement resource.
*/
if (! $conn || ! $code) {
if ($conn === null || $code === 0) {
$code = sasql_errorcode();
$message = sasql_error();
}
......
......@@ -14,7 +14,6 @@ use const SASQL_BOTH;
use function array_key_exists;
use function count;
use function gettype;
use function is_array;
use function is_int;
use function is_object;
use function is_resource;
......@@ -171,7 +170,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function execute($params = null)
{
if (is_array($params)) {
if ($params !== null) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
......
......@@ -184,7 +184,7 @@ class SQLSrvConnection implements ServerInfoAwareConnection
public function errorCode()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if ($errors) {
if ($errors !== null) {
return $errors[0]['code'];
}
......
......@@ -34,7 +34,7 @@ class SQLSrvException extends AbstractDriverException
$errorCode = $error['code'];
}
if (! $message) {
if ($message === '') {
$message = 'SQL Server error occurred but no error message was retrieved from driver.';
}
......
......@@ -224,7 +224,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
public function errorCode()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if ($errors) {
if ($errors !== null) {
return $errors[0]['code'];
}
......@@ -244,9 +244,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public function execute($params = null)
{
if ($params) {
if ($params !== null) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
if ($hasZeroIndex && is_int($key)) {
$this->bindValue($key + 1, $val);
......@@ -256,7 +255,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
}
}
if (! $this->stmt) {
if ($this->stmt === null) {
$this->stmt = $this->prepare();
}
......@@ -264,7 +263,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
throw SQLSrvException::fromSqlSrvErrors();
}
if ($this->lastInsertId) {
if ($this->lastInsertId !== null) {
sqlsrv_next_result($this->stmt);
sqlsrv_fetch($this->stmt);
$this->lastInsertId->setId(sqlsrv_get_field($this->stmt, 0));
......@@ -313,7 +312,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$stmt = sqlsrv_prepare($this->conn, $this->sql, $params);
if (! $stmt) {
if ($stmt === false) {
throw SQLSrvException::fromSqlSrvErrors();
}
......
......@@ -124,10 +124,10 @@ final class DriverManager
?EventManager $eventManager = null
) : Connection {
// create default config and event manager, if not set
if (! $config) {
if ($config === null) {
$config = new Configuration();
}
if (! $eventManager) {
if ($eventManager === null) {
$eventManager = new EventManager();
}
......
......@@ -44,8 +44,13 @@ class MysqlSessionInit implements EventSubscriber
*/
public function postConnect(ConnectionEventArgs $args)
{
$collation = $this->collation ? ' COLLATE ' . $this->collation : '';
$args->getConnection()->executeUpdate('SET NAMES ' . $this->charset . $collation);
$statement = 'SET NAMES ' . $this->charset;
if ($this->collation !== false) {
$statement .= ' COLLATE ' . $this->collation;
}
$args->getConnection()->executeUpdate($statement);
}
/**
......
......@@ -45,7 +45,7 @@ class OracleSessionInit implements EventSubscriber
*/
public function postConnect(ConnectionEventArgs $args)
{
if (! count($this->_defaultSessionVars)) {
if (count($this->_defaultSessionVars) === 0) {
return;
}
......
......@@ -814,7 +814,7 @@ abstract class AbstractPlatform
$expression .= $char . ' ';
}
if ($mode || $char !== false) {
if ($mode !== TrimMode::UNSPECIFIED || $char !== false) {
$expression .= 'FROM ';
}
......@@ -2247,19 +2247,18 @@ abstract class AbstractPlatform
} else {
$default = $this->getDefaultValueDeclarationSQL($field);
$charset = isset($field['charset']) && $field['charset'] ?
$charset = ! empty($field['charset']) ?
' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : '';
$collation = isset($field['collation']) && $field['collation'] ?
$collation = ! empty($field['collation']) ?
' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : '';
$notnull = isset($field['notnull']) && $field['notnull'] ? ' NOT NULL' : '';
$notnull = ! empty($field['notnull']) ? ' NOT NULL' : '';
$unique = isset($field['unique']) && $field['unique'] ?
$unique = ! empty($field['unique']) ?
' ' . $this->getUniqueFieldDeclarationSQL() : '';
$check = isset($field['check']) && $field['check'] ?
' ' . $field['check'] : '';
$check = ! empty($field['check']) ? ' ' . $field['check'] : '';
$typeDecl = $field['type']->getSQLDeclaration($field, $this);
$columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation;
......@@ -2557,7 +2556,7 @@ abstract class AbstractPlatform
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
{
$sql = '';
if (strlen($foreignKey->getName())) {
if (strlen($foreignKey->getName()) > 0) {
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
}
$sql .= 'FOREIGN KEY (';
......@@ -3560,7 +3559,7 @@ abstract class AbstractPlatform
final public function getReservedKeywordsList()
{
// Check for an existing instantiation of the keywords class.
if ($this->_keywords) {
if ($this->_keywords !== null) {
return $this->_keywords;
}
......
......@@ -111,8 +111,8 @@ class DB2Platform extends AbstractPlatform
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(254)')
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(254)')
: ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
}
/**
......@@ -664,7 +664,7 @@ class DB2Platform extends AbstractPlatform
$alterClause = 'ALTER COLUMN ' . $columnDiff->column->getQuotedName($this);
if ($column['columnDefinition']) {
if ($column['columnDefinition'] !== null) {
return [$alterClause . ' ' . $column['columnDefinition']];
}
......@@ -687,7 +687,7 @@ class DB2Platform extends AbstractPlatform
if (isset($column['default'])) {
$defaultClause = $this->getDefaultValueDeclarationSQL($column);
if ($defaultClause) {
if ($defaultClause !== '') {
$clauses[] = $alterClause . ' SET' . $defaultClause;
}
} else {
......@@ -753,7 +753,7 @@ class DB2Platform extends AbstractPlatform
return '';
}
if (isset($field['version']) && $field['version']) {
if (! empty($field['version'])) {
if ((string) $field['type'] !== 'DateTime') {
$field['default'] = '1';
}
......
......@@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use function count;
use function implode;
use function str_replace;
......@@ -67,7 +68,7 @@ class ReservedKeywordsValidator implements Visitor
*/
private function addViolation($asset, $violatedPlatforms)
{
if (! $violatedPlatforms) {
if (count($violatedPlatforms) === 0) {
return;
}
......
......@@ -150,7 +150,7 @@ class MySqlPlatform extends AbstractPlatform
*/
public function getListTableIndexesSQL($table, $currentDatabase = null)
{
if ($currentDatabase) {
if ($currentDatabase !== null) {
$currentDatabase = $this->quoteStringLiteral($currentDatabase);
$table = $this->quoteStringLiteral($table);
......@@ -224,8 +224,8 @@ class MySqlPlatform extends AbstractPlatform
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
}
/**
......@@ -372,7 +372,7 @@ class MySqlPlatform extends AbstractPlatform
{
$table = $this->quoteStringLiteral($table);
if ($database) {
if ($database !== null) {
$database = $this->quoteStringLiteral($database);
} else {
$database = 'DATABASE()';
......@@ -394,7 +394,7 @@ FROM information_schema.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s
SQL
,
$database ? $this->quoteStringLiteral($database) : 'DATABASE()',
$database !== null ? $this->quoteStringLiteral($database) : 'DATABASE()',
$this->quoteStringLiteral($table)
);
}
......
......@@ -43,7 +43,7 @@ class OraclePlatform extends AbstractPlatform
*/
public static function assertValidIdentifier($identifier)
{
if (! preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier)) {
if (preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier) === 0) {
throw new DBALException('Invalid Oracle identifier');
}
}
......@@ -329,8 +329,8 @@ class OraclePlatform extends AbstractPlatform
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)')
: ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(2000)')
: ($length > 0 ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
}
/**
......@@ -725,13 +725,17 @@ SQL
*/
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
{
$referentialAction = null;
$referentialAction = '';
if ($foreignKey->hasOption('onDelete')) {
$referentialAction = $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete'));
}
return $referentialAction ? ' ON DELETE ' . $referentialAction : '';
if ($referentialAction !== '') {
return ' ON DELETE ' . $referentialAction;
}
return '';
}
/**
......@@ -785,7 +789,7 @@ SQL
$fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$comment = $this->getColumnComment($column);
if (! $comment) {
if ($comment === null || $comment === '') {
continue;
}
......@@ -796,7 +800,7 @@ SQL
);
}
if (count($fields)) {
if (count($fields) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ADD (' . implode(', ', $fields) . ')';
}
......@@ -844,7 +848,7 @@ SQL
);
}
if (count($fields)) {
if (count($fields) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' MODIFY (' . implode(', ', $fields) . ')';
}
......@@ -868,7 +872,7 @@ SQL
$fields[] = $column->getQuotedName($this);
}
if (count($fields)) {
if (count($fields) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' DROP (' . implode(', ', $fields) . ')';
}
......@@ -913,10 +917,10 @@ SQL
$notnull = $field['notnull'] ? ' NOT NULL' : ' NULL';
}
$unique = isset($field['unique']) && $field['unique'] ?
$unique = ! empty($field['unique']) ?
' ' . $this->getUniqueFieldDeclarationSQL() : '';
$check = isset($field['check']) && $field['check'] ?
$check = ! empty($field['check']) ?
' ' . $field['check'] : '';
$typeDecl = $field['type']->getSQLDeclaration($field, $this);
......@@ -999,8 +1003,8 @@ SQL
return $query;
}
if (preg_match('/^\s*SELECT/i', $query)) {
if (! preg_match('/\sFROM\s/i', $query)) {
if (preg_match('/^\s*SELECT/i', $query) === 1) {
if (preg_match('/\sFROM\s/i', $query) === 0) {
$query .= ' FROM dual';
}
......
......@@ -662,7 +662,7 @@ SQL
$fromColumn = $columnDiff->fromColumn instanceof Column ? $columnDiff->fromColumn : null;
if ($fromColumn) {
if ($fromColumn !== null) {
$fromColumnType = $fromColumn->getType();
if (! $fromColumnType instanceof BinaryType && ! $fromColumnType instanceof BlobType) {
......@@ -1047,8 +1047,8 @@ SQL
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
}
/**
......@@ -1277,7 +1277,7 @@ SQL
*/
private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff) : bool
{
if (! $columnDiff->fromColumn) {
if ($columnDiff->fromColumn === null) {
return $columnDiff->hasChanged('type');
}
......@@ -1296,7 +1296,7 @@ SQL
private function getOldColumnComment(ColumnDiff $columnDiff) : ?string
{
return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null;
return $columnDiff->fromColumn !== null ? $this->getColumnComment($columnDiff->fromColumn) : null;
}
public function getListTableMetadataSQL(string $table, ?string $schema = null) : string
......
......@@ -1132,7 +1132,7 @@ SQL
*/
public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false)
{
if (! $char) {
if ($char === false) {
switch ($pos) {
case TrimMode::LEADING:
return $this->getLtrimExpression($str);
......@@ -1389,7 +1389,7 @@ SQL
return $query;
}
if (! preg_match('/^\s*(SELECT\s+(DISTINCT\s+)?)(.*)/i', $query, $matches)) {
if (preg_match('/^\s*(SELECT\s+(DISTINCT\s+)?)(.*)/i', $query, $matches) === 0) {
return $query;
}
......@@ -1543,8 +1543,8 @@ SQL
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed
? ($length ? 'CHAR(' . $length . ')' : 'CHAR(' . $this->getVarcharDefaultLength() . ')')
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(' . $this->getVarcharDefaultLength() . ')');
? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(' . $this->getVarcharDefaultLength() . ')')
: ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(' . $this->getVarcharDefaultLength() . ')');
}
/**
......
......@@ -316,7 +316,7 @@ SQL
// @todo does other code breaks because of this?
// force primary keys to be not null
foreach ($columns as &$column) {
if (isset($column['primary']) && $column['primary']) {
if (! empty($column['primary'])) {
$column['notnull'] = true;
}
......@@ -1123,7 +1123,7 @@ SQL
*/
public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false)
{
if (! $char) {
if ($char === false) {
switch ($pos) {
case TrimMode::LEADING:
$trimFn = 'LTRIM';
......@@ -1261,7 +1261,9 @@ SQL
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length ? 'NCHAR(' . $length . ')' : 'CHAR(255)') : ($length ? 'NVARCHAR(' . $length . ')' : 'NVARCHAR(255)');
return $fixed
? ($length > 0 ? 'NCHAR(' . $length . ')' : 'CHAR(255)')
: ($length > 0 ? 'NVARCHAR(' . $length . ')' : 'NVARCHAR(255)');
}
/**
......@@ -1352,9 +1354,9 @@ SQL
}
if ($orderByPos === false
|| substr_count($query, '(', $orderByPos) - substr_count($query, ')', $orderByPos)
|| substr_count($query, '(', $orderByPos) !== substr_count($query, ')', $orderByPos)
) {
if (preg_match('/^SELECT\s+DISTINCT/im', $query)) {
if (preg_match('/^SELECT\s+DISTINCT/im', $query) > 0) {
// SQL Server won't let us order by a non-selected column in a DISTINCT query,
// so we have to do this madness. This says, order by the first column in the
// result. SQL Server's docs say that a nonordered query's result order is non-
......@@ -1399,10 +1401,10 @@ SQL
continue;
}
$item[$key] = $value ? 1 : 0;
$item[$key] = (int) (bool) $value;
}
} elseif (is_bool($item) || is_numeric($item)) {
$item = $item ? 1 : 0;
$item = (int) (bool) $item;
}
return $item;
......@@ -1611,15 +1613,15 @@ SQL
if (isset($field['columnDefinition'])) {
$columnDef = $this->getCustomTypeDeclarationSQL($field);
} else {
$collation = isset($field['collation']) && $field['collation'] ?
$collation = ! empty($field['collation']) ?
' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : '';
$notnull = isset($field['notnull']) && $field['notnull'] ? ' NOT NULL' : '';
$notnull = ! empty($field['notnull']) ? ' NOT NULL' : '';
$unique = isset($field['unique']) && $field['unique'] ?
$unique = ! empty($field['unique']) ?
' ' . $this->getUniqueFieldDeclarationSQL() : '';
$check = isset($field['check']) && $field['check'] ?
$check = ! empty($field['check']) ?
' ' . $field['check'] : '';
$typeDecl = $field['type']->getSQLDeclaration($field, $this);
......
......@@ -394,8 +394,8 @@ class SqlitePlatform extends AbstractPlatform
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length > 0 ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
/**
......@@ -1109,7 +1109,7 @@ class SqlitePlatform extends AbstractPlatform
foreach ($diff->removedIndexes as $index) {
$indexName = strtolower($index->getName());
if (! strlen($indexName) || ! isset($indexes[$indexName])) {
if (strlen($indexName) === 0 || ! isset($indexes[$indexName])) {
continue;
}
......@@ -1118,7 +1118,7 @@ class SqlitePlatform extends AbstractPlatform
foreach (array_merge($diff->changedIndexes, $diff->addedIndexes, $diff->renamedIndexes) as $index) {
$indexName = strtolower($index->getName());
if (strlen($indexName)) {
if (strlen($indexName) > 0) {
$indexes[$indexName] = $index;
} else {
$indexes[] = $index;
......@@ -1167,7 +1167,7 @@ class SqlitePlatform extends AbstractPlatform
}
$constraintName = strtolower($constraint->getName());
if (! strlen($constraintName) || ! isset($foreignKeys[$constraintName])) {
if (strlen($constraintName) === 0 || ! isset($foreignKeys[$constraintName])) {
continue;
}
......@@ -1176,7 +1176,7 @@ class SqlitePlatform extends AbstractPlatform
foreach (array_merge($diff->changedForeignKeys, $diff->addedForeignKeys) as $constraint) {
$constraintName = strtolower($constraint->getName());
if (strlen($constraintName)) {
if (strlen($constraintName) > 0) {
$foreignKeys[$constraintName] = $constraint;
} else {
$foreignKeys[] = $constraint;
......
......@@ -63,7 +63,7 @@ class Connection extends \Doctrine\DBAL\Connection
$this->portability = $params['portability'];
}
if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) {
if (isset($params['fetch_case']) && ($this->portability & self::PORTABILITY_FIX_CASE) !== 0) {
if ($this->_conn instanceof PDOConnection) {
// make use of c-level support for case handling
$this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $params['fetch_case']);
......
......@@ -135,10 +135,10 @@ class Statement implements IteratorAggregate, DriverStatement
$row = $this->stmt->fetch($fetchMode, ...$args);
$iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM);
$iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0;
$fixCase = $this->case !== null
&& ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED)
&& ($this->portability & Connection::PORTABILITY_FIX_CASE);
&& ($this->portability & Connection::PORTABILITY_FIX_CASE) !== 0;
$row = $this->fixRow($row, $iterateRow, $fixCase);
......@@ -154,10 +154,10 @@ class Statement implements IteratorAggregate, DriverStatement
$rows = $this->stmt->fetchAll($fetchMode, ...$args);
$iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM);
$iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0;
$fixCase = $this->case !== null
&& ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED)
&& ($this->portability & Connection::PORTABILITY_FIX_CASE);
&& ($this->portability & Connection::PORTABILITY_FIX_CASE) !== 0;
if (! $iterateRow && ! $fixCase) {
return $rows;
......@@ -184,14 +184,14 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* @param mixed $row
* @param int $iterateRow
* @param bool $iterateRow
* @param bool $fixCase
*
* @return mixed
*/
protected function fixRow($row, $iterateRow, $fixCase)
{
if (! $row) {
if ($row === false) {
return $row;
}
......@@ -201,9 +201,9 @@ class Statement implements IteratorAggregate, DriverStatement
if ($iterateRow) {
foreach ($row as $k => $v) {
if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) && $v === '') {
if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $v === '') {
$row[$k] = null;
} elseif (($this->portability & Connection::PORTABILITY_RTRIM) && is_string($v)) {
} elseif (($this->portability & Connection::PORTABILITY_RTRIM) !== 0 && is_string($v)) {
$row[$k] = rtrim($v);
}
}
......@@ -219,12 +219,10 @@ class Statement implements IteratorAggregate, DriverStatement
{
$value = $this->stmt->fetchColumn($columnIndex);
if ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) {
if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) && $value === '') {
$value = null;
} elseif (($this->portability & Connection::PORTABILITY_RTRIM) && is_string($value)) {
$value = rtrim($value);
}
if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $value === '') {
$value = null;
} elseif (($this->portability & Connection::PORTABILITY_RTRIM) !== 0 && is_string($value)) {
$value = rtrim($value);
}
return $value;
......
......@@ -548,7 +548,7 @@ class QueryBuilder
{
$this->type = self::DELETE;
if (! $delete) {
if ($delete === null) {
return $this;
}
......@@ -578,7 +578,7 @@ class QueryBuilder
{
$this->type = self::UPDATE;
if (! $update) {
if ($update === null) {
return $this;
}
......@@ -611,7 +611,7 @@ class QueryBuilder
{
$this->type = self::INSERT;
if (! $insert) {
if ($insert === null) {
return $this;
}
......@@ -1053,7 +1053,7 @@ class QueryBuilder
*/
public function orderBy($sort, $order = null)
{
return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), false);
return $this->add('orderBy', $sort . ' ' . ($order ?? 'ASC'), false);
}
/**
......@@ -1066,7 +1066,7 @@ class QueryBuilder
*/
public function addOrderBy($sort, $order = null)
{
return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), true);
return $this->add('orderBy', $sort . ' ' . ($order ?? 'ASC'), true);
}
/**
......
......@@ -155,7 +155,7 @@ class SQLParserUtils
$arrayPositions[$name] = false;
}
if (( ! $arrayPositions && $isPositional)) {
if ($isPositional && count($arrayPositions) === 0) {
return [$query, $params, $types];
}
......@@ -184,7 +184,7 @@ class SQLParserUtils
$types = array_merge(
array_slice($types, 0, $needle),
$count ?
$count > 0 ?
// array needles are at {@link \Doctrine\DBAL\ParameterType} constants
// + {@link Doctrine\DBAL\Connection::ARRAY_PARAM_OFFSET}
array_fill(0, $count, $types[$needle] - Connection::ARRAY_PARAM_OFFSET) :
......@@ -192,7 +192,7 @@ class SQLParserUtils
array_slice($types, $needle + 1)
);
$expandStr = $count ? implode(', ', array_fill(0, $count, '?')) : 'NULL';
$expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : 'NULL';
$query = substr($query, 0, $needlePos) . $expandStr . substr($query, $needlePos + 1);
$paramOffset += ($count - 1); // Grows larger by number of parameters minus the replaced needle.
......
......@@ -114,7 +114,7 @@ abstract class AbstractAsset
public function getFullQualifiedName($defaultNamespaceName)
{
$name = $this->getName();
if (! $this->_namespace) {
if ($this->_namespace === null) {
$name = $defaultNamespaceName . '.' . $name;
}
......@@ -162,7 +162,7 @@ abstract class AbstractAsset
*/
public function getName()
{
if ($this->_namespace) {
if ($this->_namespace !== null) {
return $this->_namespace . '.' . $this->_name;
}
......
......@@ -155,7 +155,7 @@ abstract class AbstractSchemaManager
*/
public function listTableColumns($table, $database = null)
{
if (! $database) {
if ($database === null) {
$database = $this->_conn->getDatabase();
}
......@@ -226,7 +226,7 @@ abstract class AbstractSchemaManager
protected function filterAssetNames($assetNames)
{
$filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter();
if (! $filter) {
if ($filter === null) {
return $assetNames;
}
......@@ -628,13 +628,7 @@ abstract class AbstractSchemaManager
{
$list = [];
foreach ($databases as $value) {
$value = $this->_getPortableDatabaseDefinition($value);
if (! $value) {
continue;
}
$list[] = $value;
$list[] = $this->_getPortableDatabaseDefinition($value);
}
return $list;
......@@ -806,7 +800,7 @@ abstract class AbstractSchemaManager
$column = $this->_getPortableTableColumnDefinition($tableColumn);
}
if (! $column) {
if ($column === null) {
continue;
}
......@@ -886,7 +880,7 @@ abstract class AbstractSchemaManager
$index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['options']);
}
if (! $index) {
if ($index === null) {
continue;
}
......@@ -905,13 +899,7 @@ abstract class AbstractSchemaManager
{
$list = [];
foreach ($tables as $value) {
$value = $this->_getPortableTableDefinition($value);
if (! $value) {
continue;
}
$list[] = $value;
$list[] = $this->_getPortableTableDefinition($value);
}
return $list;
......@@ -936,13 +924,7 @@ abstract class AbstractSchemaManager
{
$list = [];
foreach ($users as $value) {
$value = $this->_getPortableUserDefinition($value);
if (! $value) {
continue;
}
$list[] = $value;
$list[] = $this->_getPortableUserDefinition($value);
}
return $list;
......@@ -969,7 +951,7 @@ abstract class AbstractSchemaManager
foreach ($views as $value) {
$view = $this->_getPortableViewDefinition($value);
if (! $view) {
if ($view === false) {
continue;
}
......@@ -1107,7 +1089,7 @@ abstract class AbstractSchemaManager
*/
public function extractDoctrineTypeFromComment($comment, $currentType)
{
if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match)) {
if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match) === 1) {
return $match[1];
}
......
......@@ -48,7 +48,7 @@ class ColumnDiff
*/
public function getOldColumnName()
{
$quote = $this->fromColumn && $this->fromColumn->isQuoted();
$quote = $this->fromColumn !== null && $this->fromColumn->isQuoted();
return new Identifier($this->oldColumnName, $quote);
}
......
......@@ -293,7 +293,7 @@ class Comparator
$changes++;
}
return $changes ? $tableDifferences : false;
return $changes > 0 ? $tableDifferences : false;
}
/**
......
......@@ -51,7 +51,7 @@ class DB2SchemaManager extends AbstractSchemaManager
if ($tableColumn['default'] !== null && $tableColumn['default'] !== 'NULL') {
$default = $tableColumn['default'];
if (preg_match('/^\'(.*)\'$/s', $default, $matches)) {
if (preg_match('/^\'(.*)\'$/s', $default, $matches) === 1) {
$default = str_replace("''", "'", $matches[1]);
}
}
......
......@@ -143,7 +143,11 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'real':
case 'numeric':
case 'decimal':
if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['type'], $match)) {
if (preg_match(
'([A-Za-z]+\(([0-9]+),([0-9]+)\))',
$tableColumn['type'],
$match
) === 1) {
$precision = $match[1];
$scale = $match[2];
$length = null;
......@@ -237,7 +241,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
return null;
}
if (preg_match('/^\'(.*)\'$/', $columnDefault, $matches)) {
if (preg_match('/^\'(.*)\'$/', $columnDefault, $matches) === 1) {
return strtr($matches[1], self::MARIADB_ESCAPE_SEQUENCES);
}
......
......@@ -124,7 +124,7 @@ class OracleSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['data_type']);
if (strpos($dbType, 'timestamp(') === 0) {
if (strpos($dbType, 'with time zone')) {
if (strpos($dbType, 'with time zone') !== false) {
$dbType = 'timestamptz';
} else {
$dbType = 'timestamp';
......@@ -146,7 +146,7 @@ class OracleSchemaManager extends AbstractSchemaManager
if ($tableColumn['data_default'] !== null) {
// Default values returned from database are represented as literal expressions
if (preg_match('/^\'(.*)\'$/s', $tableColumn['data_default'], $matches)) {
if (preg_match('/^\'(.*)\'$/s', $tableColumn['data_default'], $matches) === 1) {
$tableColumn['data_default'] = str_replace("''", "'", $matches[1]);
}
}
......@@ -345,7 +345,7 @@ class OracleSchemaManager extends AbstractSchemaManager
*/
private function getQuotedIdentifierName($identifier)
{
if (preg_match('/[a-z]/', $identifier)) {
if (preg_match('/[a-z]/', $identifier) === 1) {
return $this->_platform->quoteIdentifier($identifier);
}
......
......@@ -138,14 +138,26 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$foreignColumns = [];
$foreignTable = null;
if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
if (preg_match(
'(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))',
$tableForeignKey['condef'],
$match
) === 1) {
$onUpdate = $match[1];
}
if (preg_match('(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
if (preg_match(
'(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))',
$tableForeignKey['condef'],
$match
) === 1) {
$onDelete = $match[1];
}
if (preg_match('/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', $tableForeignKey['condef'], $values)) {
if (preg_match(
'/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/',
$tableForeignKey['condef'],
$values
) === 1) {
// PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get
// the idea to trim them here.
$localColumns = array_map('trim', explode(',', $values[1]));
......@@ -323,15 +335,15 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$matches = [];
$autoincrement = false;
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) {
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches) === 1) {
$tableColumn['sequence'] = $matches[1];
$tableColumn['default'] = null;
$autoincrement = true;
}
if (preg_match("/^['(](.*)[')]::/", $tableColumn['default'], $matches)) {
if (preg_match("/^['(](.*)[')]::/", $tableColumn['default'], $matches) === 1) {
$tableColumn['default'] = $matches[1];
} elseif (preg_match('/^NULL::/', $tableColumn['default'])) {
} elseif (preg_match('/^NULL::/', $tableColumn['default']) === 1) {
$tableColumn['default'] = null;
}
......@@ -353,7 +365,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$jsonb = null;
$dbType = strtolower($tableColumn['type']);
if (strlen($tableColumn['domain_type']) && ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) {
if (strlen($tableColumn['domain_type']) > 0
&& ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) {
$dbType = strtolower($tableColumn['domain_type']);
$tableColumn['complete_type'] = $tableColumn['domain_complete_type'];
}
......@@ -415,7 +428,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'numeric':
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) {
if (preg_match(
'([A-Za-z]+\(([0-9]+)\,([0-9]+)\))',
$tableColumn['complete_type'],
$match
) === 1) {
$precision = $match[1];
$scale = $match[2];
$length = null;
......@@ -431,7 +448,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
break;
}
if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) {
if ($tableColumn['default'] !== null && preg_match(
"('([^']+)'::)",
$tableColumn['default'],
$match
) === 1) {
$tableColumn['default'] = $match[1];
}
......
......@@ -134,7 +134,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
return null;
}
if (preg_match('/^\'(.*)\'$/s', $value, $matches)) {
if (preg_match('/^\'(.*)\'$/s', $value, $matches) === 1) {
$value = str_replace("''", "'", $matches[1]);
}
......
......@@ -131,7 +131,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
)?#isx',
$createSql,
$match
)) {
) > 0) {
$names = array_reverse($match[1]);
$deferrable = array_reverse($match[2]);
$deferred = array_reverse($match[3]);
......@@ -334,7 +334,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
if ($default !== null) {
// SQLite returns the default value as a literal expression, so we need to parse it
if (preg_match('/^\'(.*)\'$/s', $default, $matches)) {
if (preg_match('/^\'(.*)\'$/s', $default, $matches) === 1) {
$default = str_replace("''", "'", $matches[1]);
}
}
......
......@@ -271,7 +271,7 @@ class Table extends AbstractAsset
*/
private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrimary, array $flags = [], array $options = [])
{
if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) {
if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName)) === 1) {
throw SchemaException::indexNameInvalid($indexName);
}
......@@ -511,7 +511,7 @@ class Table extends AbstractAsset
{
$constraint->setLocalTable($this);
if (strlen($constraint->getName())) {
if (strlen($constraint->getName()) > 0) {
$name = $constraint->getName();
} else {
$name = $this->_generateIdentifierName(
......@@ -714,7 +714,7 @@ class Table extends AbstractAsset
*/
public function hasPrimaryKey()
{
return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName);
return $this->_primaryKeyName !== false && $this->hasIndex($this->_primaryKeyName);
}
/**
......
......@@ -7,7 +7,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use IteratorAggregate;
use Throwable;
use function is_array;
use function is_string;
/**
......@@ -139,19 +138,19 @@ class Statement implements IteratorAggregate, DriverStatement
*/
public function execute($params = null)
{
if (is_array($params)) {
if ($params !== null) {
$this->params = $params;
}
$logger = $this->conn->getConfiguration()->getSQLLogger();
if ($logger) {
if ($logger !== null) {
$logger->startQuery($this->sql, $this->params, $this->types);
}
try {
$stmt = $this->stmt->execute($params);
} catch (Throwable $ex) {
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
throw DBALException::driverExceptionDuringQuery(
......@@ -162,7 +161,7 @@ class Statement implements IteratorAggregate, DriverStatement
);
}
if ($logger) {
if ($logger !== null) {
$logger->stopQuery();
}
$this->params = [];
......
......@@ -108,7 +108,7 @@ EOT
$conn = $this->getHelper('db')->getConnection();
$keywordLists = (array) $input->getOption('list');
if (! $keywordLists) {
if (count($keywordLists) === 0) {
$keywordLists = array_keys($this->keywordListClasses);
}
......
......@@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function assert;
use function is_bool;
use function is_numeric;
use function is_string;
use function stripos;
......@@ -59,7 +60,10 @@ EOT
throw new LogicException("Option 'depth' must contains an integer value");
}
if (stripos($sql, 'select') === 0 || $input->getOption('force-fetch')) {
$forceFetch = $input->getOption('force-fetch');
assert(is_bool($forceFetch));
if (stripos($sql, 'select') === 0 || $forceFetch) {
$resultSet = $conn->fetchAll($sql);
} else {
$resultSet = $conn->executeUpdate($sql);
......
......@@ -49,7 +49,7 @@ class DateImmutableType extends DateType
$dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getDateFormatString(), $value);
if (! $dateTime) {
if ($dateTime === false) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
......
......@@ -50,11 +50,11 @@ class DateTimeImmutableType extends DateTimeType
$dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value);
if (! $dateTime) {
if ($dateTime === false) {
$dateTime = date_create_immutable($value);
}
if (! $dateTime) {
if ($dateTime === false) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
......
......@@ -55,11 +55,11 @@ class DateTimeType extends Type implements PhpDateTimeMappingType
$val = DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
if (! $val) {
if ($val === false) {
$val = date_create($value);
}
if (! $val) {
if ($val === false) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
}
......
......@@ -49,7 +49,7 @@ class DateTimeTzImmutableType extends DateTimeTzType
$dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeTzFormatString(), $value);
if (! $dateTime) {
if ($dateTime === false) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
......
......@@ -66,7 +66,7 @@ class DateTimeTzType extends Type implements PhpDateTimeMappingType
}
$val = DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value);
if (! $val) {
if ($val === false) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeTzFormatString());
}
......
......@@ -53,7 +53,7 @@ class DateType extends Type
}
$val = DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value);
if (! $val) {
if ($val === false) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString());
}
......
......@@ -3,8 +3,10 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function count;
use function explode;
use function implode;
use function is_array;
use function is_resource;
use function stream_get_contents;
......@@ -28,7 +30,7 @@ class SimpleArrayType extends Type
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (! $value) {
if (! is_array($value) || count($value) === 0) {
return null;
}
......
......@@ -49,7 +49,7 @@ class TimeImmutableType extends TimeType
$dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value);
if (! $dateTime) {
if ($dateTime === false) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
......
......@@ -53,7 +53,7 @@ class TimeType extends Type
}
$val = DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value);
if (! $val) {
if ($val === false) {
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
}
......
......@@ -50,7 +50,7 @@ class VarDateTimeImmutableType extends VarDateTimeType
$dateTime = date_create_immutable($value);
if (! $dateTime) {
if ($dateTime === false) {
throw ConversionException::conversionFailed($value, $this->getName());
}
......
......@@ -25,7 +25,7 @@ class VarDateTimeType extends DateTimeType
}
$val = date_create($value);
if (! $val) {
if ($val === false) {
throw ConversionException::conversionFailed($value, $this->getName());
}
......
......@@ -68,7 +68,7 @@ abstract class FunctionalTestCase extends TestCase
throw $t;
}
if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) {
if (count($this->sqlLoggerStack->queries) > 0) {
$queries = '';
$i = count($this->sqlLoggerStack->queries);
foreach (array_reverse($this->sqlLoggerStack->queries) as $query) {
......
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