Use automated fixes

parent c55e22ef
......@@ -10,7 +10,7 @@ use Doctrine\DBAL\DBALException;
class CacheException extends DBALException
{
/**
* @return \Doctrine\DBAL\Cache\CacheException
* @return CacheException
*/
public static function noCacheKey()
{
......@@ -18,7 +18,7 @@ class CacheException extends DBALException
}
/**
* @return \Doctrine\DBAL\Cache\CacheException
* @return CacheException
*/
public static function noResultDriverConfigured()
{
......
......@@ -92,7 +92,7 @@ class QueryCacheProfile
}
/**
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
* @return QueryCacheProfile
*/
public function setResultCacheDriver(Cache $cache)
{
......@@ -102,7 +102,7 @@ class QueryCacheProfile
/**
* @param string|null $cacheKey
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
* @return QueryCacheProfile
*/
public function setCacheKey($cacheKey)
{
......@@ -112,7 +112,7 @@ class QueryCacheProfile
/**
* @param int $lifetime
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
* @return QueryCacheProfile
*/
public function setLifetime($lifetime)
{
......
......@@ -86,6 +86,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
if (! $data) {
$data = [];
}
$data[$this->realKey] = $this->data;
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
......
......@@ -1063,6 +1063,7 @@ class Connection implements DriverConnection
} else {
$stmt->execute($params);
}
$result = $stmt->rowCount();
} else {
$result = $connection->exec($query);
......@@ -1179,9 +1180,11 @@ class Connection implements DriverConnection
return $res;
} catch (Exception $e) {
$this->rollBack();
throw $e;
} catch (Throwable $e) {
$this->rollBack();
throw $e;
}
}
......@@ -1254,6 +1257,7 @@ class Connection implements DriverConnection
if ($logger) {
$logger->startQuery('"SAVEPOINT"');
}
$this->createSavepoint($this->_getNestedTransactionSavePointName());
if ($logger) {
$logger->stopQuery();
......@@ -1274,6 +1278,7 @@ class Connection implements DriverConnection
if ($this->transactionNestingLevel === 0) {
throw ConnectionException::noActiveTransaction();
}
if ($this->isRollbackOnly) {
throw ConnectionException::commitFailedRollbackOnly();
}
......@@ -1298,6 +1303,7 @@ class Connection implements DriverConnection
if ($logger) {
$logger->startQuery('"RELEASE SAVEPOINT"');
}
$this->releaseSavepoint($this->_getNestedTransactionSavePointName());
if ($logger) {
$logger->stopQuery();
......@@ -1354,6 +1360,7 @@ class Connection implements DriverConnection
if ($logger) {
$logger->startQuery('"ROLLBACK"');
}
$this->transactionNestingLevel = 0;
$connection->rollBack();
$this->isRollbackOnly = false;
......@@ -1368,6 +1375,7 @@ class Connection implements DriverConnection
if ($logger) {
$logger->startQuery('"ROLLBACK TO SAVEPOINT"');
}
$this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
--$this->transactionNestingLevel;
if ($logger) {
......@@ -1479,6 +1487,7 @@ class Connection implements DriverConnection
if ($this->transactionNestingLevel === 0) {
throw ConnectionException::noActiveTransaction();
}
$this->isRollbackOnly = true;
}
......@@ -1555,6 +1564,7 @@ class Connection implements DriverConnection
} else {
$stmt->bindValue($bindIndex, $value);
}
++$bindIndex;
}
} else {
......@@ -1584,6 +1594,7 @@ class Connection implements DriverConnection
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform());
$bindingType = $type->getBindingType();
......@@ -1623,6 +1634,7 @@ class Connection implements DriverConnection
} else {
$resolvedParams[$bindIndex] = $value;
}
++$bindIndex;
}
} else {
......
......@@ -8,7 +8,7 @@ namespace Doctrine\DBAL;
class ConnectionException extends DBALException
{
/**
* @return \Doctrine\DBAL\ConnectionException
* @return ConnectionException
*/
public static function commitFailedRollbackOnly()
{
......@@ -16,7 +16,7 @@ class ConnectionException extends DBALException
}
/**
* @return \Doctrine\DBAL\ConnectionException
* @return ConnectionException
*/
public static function noActiveTransaction()
{
......@@ -24,7 +24,7 @@ class ConnectionException extends DBALException
}
/**
* @return \Doctrine\DBAL\ConnectionException
* @return ConnectionException
*/
public static function savepointsNotSupported()
{
......@@ -32,7 +32,7 @@ class ConnectionException extends DBALException
}
/**
* @return \Doctrine\DBAL\ConnectionException
* @return ConnectionException
*/
public static function mayNotAlterNestedTransactionWithSavepointsInTransaction()
{
......
......@@ -95,6 +95,7 @@ class MasterSlaveConnection extends Connection
if (! isset($params['slaves'], $params['master'])) {
throw new InvalidArgumentException('master or slaves configuration missing');
}
if (count($params['slaves']) === 0) {
throw new InvalidArgumentException('You have to configure at least one slaves.');
}
......
......@@ -30,7 +30,7 @@ class DBALException extends Exception
/**
* @param string $method
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function notSupported($method)
{
......@@ -89,7 +89,7 @@ class DBALException extends Exception
}
/**
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function invalidPdoInstance()
{
......@@ -102,7 +102,7 @@ class DBALException extends Exception
/**
* @param string|null $url The URL that was provided in the connection parameters (if any).
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function driverRequired($url = null)
{
......@@ -124,7 +124,7 @@ class DBALException extends Exception
* @param string $unknownDriverName
* @param string[] $knownDrivers
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function unknownDriver($unknownDriverName, array $knownDrivers)
{
......@@ -144,6 +144,7 @@ class DBALException extends Exception
if ($params) {
$msg .= ' with params ' . self::formatParameters($params);
}
$msg .= ":\n\n" . $driverEx->getMessage();
return static::wrapException($driver, $driverEx, $msg);
......@@ -165,6 +166,7 @@ class DBALException extends Exception
if ($driverEx instanceof DriverException) {
return $driverEx;
}
if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverExceptionInterface) {
return $driver->convertException($msg, $driverEx);
}
......@@ -201,7 +203,7 @@ class DBALException extends Exception
/**
* @param string $wrapperClass
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function invalidWrapperClass($wrapperClass)
{
......@@ -212,7 +214,7 @@ class DBALException extends Exception
/**
* @param string $driverClass
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function invalidDriverClass($driverClass)
{
......@@ -222,7 +224,7 @@ class DBALException extends Exception
/**
* @param string $tableName
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function invalidTableName($tableName)
{
......@@ -232,7 +234,7 @@ class DBALException extends Exception
/**
* @param string $tableName
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function noColumnsSpecifiedForTable($tableName)
{
......@@ -240,7 +242,7 @@ class DBALException extends Exception
}
/**
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function limitOffsetInvalid()
{
......@@ -250,7 +252,7 @@ class DBALException extends Exception
/**
* @param string $name
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function typeExists($name)
{
......@@ -260,7 +262,7 @@ class DBALException extends Exception
/**
* @param string $name
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function unknownColumnType($name)
{
......@@ -276,7 +278,7 @@ class DBALException extends Exception
/**
* @param string $name
*
* @return \Doctrine\DBAL\DBALException
* @return DBALException
*/
public static function typeNotFound($name)
{
......
......@@ -125,6 +125,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
if (version_compare($oracleMysqlVersion, '8', '>=')) {
return new MySQL80Platform();
}
if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
return new MySQL57Platform();
}
......@@ -153,6 +154,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? null;
......
......@@ -6,8 +6,6 @@ use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use stdClass;
use const DB2_AUTOCOMMIT_OFF;
use const DB2_AUTOCOMMIT_ON;
use function assert;
use function db2_autocommit;
use function db2_commit;
......@@ -25,6 +23,8 @@ use function db2_server_info;
use function db2_stmt_errormsg;
use function func_get_args;
use function is_bool;
use const DB2_AUTOCOMMIT_OFF;
use const DB2_AUTOCOMMIT_ON;
class DB2Connection implements Connection, ServerInfoAwareConnection
{
......@@ -61,8 +61,8 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/
public function getServerVersion()
{
/** @var stdClass $serverInfo */
$serverInfo = db2_server_info($this->conn);
assert($serverInfo instanceof stdClass);
return $serverInfo->DBMS_VER;
}
......
......@@ -12,12 +12,6 @@ use ReflectionClass;
use ReflectionObject;
use ReflectionProperty;
use stdClass;
use const CASE_LOWER;
use const DB2_BINARY;
use const DB2_CHAR;
use const DB2_LONG;
use const DB2_PARAM_FILE;
use const DB2_PARAM_IN;
use function array_change_key_case;
use function db2_bind_param;
use function db2_execute;
......@@ -45,6 +39,12 @@ use function stream_copy_to_stream;
use function stream_get_meta_data;
use function strtolower;
use function tmpfile;
use const CASE_LOWER;
use const DB2_BINARY;
use const DB2_CHAR;
use const DB2_LONG;
use const DB2_PARAM_FILE;
use const DB2_PARAM_IN;
class DB2Statement implements IteratorAggregate, Statement
{
......@@ -309,12 +309,14 @@ class DB2Statement implements IteratorAggregate, Statement
while (($row = $this->fetch(...func_get_args())) !== false) {
$rows[] = $row;
}
break;
case FetchMode::COLUMN:
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;
default:
......
......@@ -7,12 +7,6 @@ use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use mysqli;
use const MYSQLI_INIT_COMMAND;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use const MYSQLI_OPT_LOCAL_INFILE;
use const MYSQLI_READ_DEFAULT_FILE;
use const MYSQLI_READ_DEFAULT_GROUP;
use const MYSQLI_SERVER_PUBLIC_KEY;
use function defined;
use function floor;
use function func_get_args;
......@@ -26,6 +20,12 @@ use function restore_error_handler;
use function set_error_handler;
use function sprintf;
use function stripos;
use const MYSQLI_INIT_COMMAND;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use const MYSQLI_OPT_LOCAL_INFILE;
use const MYSQLI_READ_DEFAULT_FILE;
use const MYSQLI_READ_DEFAULT_GROUP;
use const MYSQLI_SERVER_PUBLIC_KEY;
class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection
{
......
......@@ -224,6 +224,7 @@ class MysqliStatement implements IteratorAggregate, Statement
if (get_resource_type($value) !== 'stream') {
throw new InvalidArgumentException('Resources passed with the LARGE_OBJECT parameter type must be stream resources.');
}
$streams[$parameter] = $value;
$values[$parameter] = null;
continue;
......
......@@ -6,8 +6,6 @@ use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use UnexpectedValueException;
use const OCI_COMMIT_ON_SUCCESS;
use const OCI_NO_AUTO_COMMIT;
use function addcslashes;
use function func_get_args;
use function is_float;
......@@ -21,6 +19,8 @@ use function oci_server_version;
use function preg_match;
use function sprintf;
use function str_replace;
use const OCI_COMMIT_ON_SUCCESS;
use const OCI_NO_AUTO_COMMIT;
/**
* OCI8 implementation of the Connection interface.
......@@ -129,6 +129,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
if (is_int($value) || is_float($value)) {
return $value;
}
$value = str_replace("'", "''", $value);
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
......@@ -193,6 +194,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
if (! oci_commit($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->executeMode = OCI_COMMIT_ON_SUCCESS;
return true;
......@@ -206,6 +208,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
if (! oci_rollback($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->executeMode = OCI_COMMIT_ON_SUCCESS;
return true;
......
......@@ -12,7 +12,7 @@ class OCI8Exception extends AbstractDriverException
/**
* @param mixed[]|false $error
*
* @return \Doctrine\DBAL\Driver\OCI8\OCI8Exception
* @return OCI8Exception
*/
public static function fromErrorInfo($error)
{
......
......@@ -9,19 +9,6 @@ use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
use const OCI_BOTH;
use const OCI_D_LOB;
use const OCI_FETCHSTATEMENT_BY_COLUMN;
use const OCI_FETCHSTATEMENT_BY_ROW;
use const OCI_NUM;
use const OCI_RETURN_LOBS;
use const OCI_RETURN_NULLS;
use const OCI_TEMP_BLOB;
use const PREG_OFFSET_CAPTURE;
use const SQLT_CHR;
use function array_key_exists;
use function assert;
use function count;
......@@ -43,6 +30,19 @@ use function preg_match;
use function preg_quote;
use function sprintf;
use function substr;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
use const OCI_BOTH;
use const OCI_D_LOB;
use const OCI_FETCHSTATEMENT_BY_COLUMN;
use const OCI_FETCHSTATEMENT_BY_ROW;
use const OCI_NUM;
use const OCI_RETURN_LOBS;
use const OCI_RETURN_NULLS;
use const OCI_TEMP_BLOB;
use const PREG_OFFSET_CAPTURE;
use const SQLT_CHR;
/**
* The OCI8 implementation of the Statement interface.
......
......@@ -36,9 +36,11 @@ class Driver extends AbstractDB2Driver
if (isset($params['host'])) {
$dsn .= 'HOSTNAME=' . $params['host'] . ';';
}
if (isset($params['port'])) {
$dsn .= 'PORT=' . $params['port'] . ';';
}
$dsn .= 'PROTOCOL=TCPIP;';
if (isset($params['dbname'])) {
$dsn .= 'DATABASE=' . $params['dbname'] . ';';
......
......@@ -44,15 +44,19 @@ class Driver extends AbstractMySQLDriver
if (isset($params['host']) && $params['host'] !== '') {
$dsn .= 'host=' . $params['host'] . ';';
}
if (isset($params['port'])) {
$dsn .= 'port=' . $params['port'] . ';';
}
if (isset($params['dbname'])) {
$dsn .= 'dbname=' . $params['dbname'] . ';';
}
if (isset($params['unix_socket'])) {
$dsn .= 'unix_socket=' . $params['unix_socket'] . ';';
}
if (isset($params['charset'])) {
$dsn .= 'charset=' . $params['charset'] . ';';
}
......
......@@ -5,13 +5,13 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use PDO;
use const E_USER_DEPRECATED;
use function array_slice;
use function assert;
use function func_get_args;
use function is_array;
use function sprintf;
use function trigger_error;
use const E_USER_DEPRECATED;
/**
* The PDO implementation of the Statement interface.
......
......@@ -11,7 +11,6 @@ use PDO;
use ReflectionClass;
use ReflectionObject;
use stdClass;
use const SASQL_BOTH;
use function array_key_exists;
use function func_get_args;
use function func_num_args;
......@@ -35,6 +34,7 @@ use function sasql_stmt_field_count;
use function sasql_stmt_reset;
use function sasql_stmt_result_metadata;
use function sprintf;
use const SASQL_BOTH;
/**
* SAP SQL Anywhere implementation of the Statement interface.
......@@ -258,12 +258,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
while (($row = $this->fetch(...func_get_args())) !== false) {
$rows[] = $row;
}
break;
case FetchMode::COLUMN:
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;
default:
......
......@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use const SQLSRV_ERR_ERRORS;
use function func_get_args;
use function is_float;
use function is_int;
......@@ -20,6 +19,7 @@ use function sqlsrv_rollback;
use function sqlsrv_rows_affected;
use function sqlsrv_server_info;
use function str_replace;
use const SQLSRV_ERR_ERRORS;
/**
* SQL Server implementation for the Connection interface.
......
......@@ -3,9 +3,9 @@
namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\AbstractDriverException;
use const SQLSRV_ERR_ERRORS;
use function rtrim;
use function sqlsrv_errors;
use const SQLSRV_ERR_ERRORS;
/**
* @psalm-immutable
......@@ -15,7 +15,7 @@ class SQLSrvException extends AbstractDriverException
/**
* Helper method to turn sql server errors into exception.
*
* @return \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException
* @return SQLSrvException
*/
public static function fromSqlSrvErrors()
{
......
......@@ -8,12 +8,6 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC;
use const SQLSRV_FETCH_BOTH;
use const SQLSRV_FETCH_NUMERIC;
use const SQLSRV_PARAM_IN;
use function array_key_exists;
use function count;
use function func_get_args;
......@@ -34,6 +28,12 @@ use function sqlsrv_prepare;
use function sqlsrv_rows_affected;
use function SQLSRV_SQLTYPE_VARBINARY;
use function stripos;
use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC;
use const SQLSRV_FETCH_BOTH;
use const SQLSRV_FETCH_NUMERIC;
use const SQLSRV_PARAM_IN;
/**
* SQL Server Statement.
......@@ -387,12 +387,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement
while (($row = $this->fetch(...func_get_args())) !== false) {
$rows[] = $row;
}
break;
case FetchMode::COLUMN:
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;
default:
......
......@@ -130,6 +130,7 @@ final class DriverManager
if (! $config) {
$config = new Configuration();
}
if (! $eventManager) {
$eventManager = new EventManager();
}
......@@ -273,12 +274,15 @@ final class DriverManager
if (isset($url['host'])) {
$params['host'] = $url['host'];
}
if (isset($url['port'])) {
$params['port'] = $url['port'];
}
if (isset($url['user'])) {
$params['user'] = $url['user'];
}
if (isset($url['pass'])) {
$params['password'] = $url['pass'];
}
......
......@@ -5,11 +5,11 @@ namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use const CASE_UPPER;
use function array_change_key_case;
use function array_merge;
use function count;
use function implode;
use const CASE_UPPER;
/**
* Should be used when Oracle Server default environment does not match the Doctrine requirements.
......@@ -57,6 +57,7 @@ class OracleSessionInit implements EventSubscriber
$vars[] = $option . " = '" . $value . "'";
}
}
$sql = 'ALTER SESSION SET ' . implode(' ', $vars);
$args->getConnection()->executeUpdate($sql);
}
......
......@@ -62,7 +62,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
* @return SchemaAlterTableAddColumnEventArgs
*/
public function addSql($sql)
{
......
......@@ -62,7 +62,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
* @return SchemaAlterTableChangeColumnEventArgs
*/
public function addSql($sql)
{
......
......@@ -49,7 +49,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs
* @return SchemaAlterTableEventArgs
*/
public function addSql($sql)
{
......
......@@ -62,7 +62,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
* @return SchemaAlterTableRemoveColumnEventArgs
*/
public function addSql($sql)
{
......
......@@ -77,7 +77,7 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
* @return SchemaAlterTableRenameColumnEventArgs
*/
public function addSql($sql)
{
......
......@@ -47,7 +47,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
* Allows to clear the column which means the column will be excluded from
* tables column list.
*
* @return \Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs
* @return SchemaColumnDefinitionEventArgs
*/
public function setColumn(?Column $column = null)
{
......
......@@ -62,7 +62,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
* @return SchemaCreateTableColumnEventArgs
*/
public function addSql($sql)
{
......
......@@ -77,7 +77,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs
* @return SchemaCreateTableEventArgs
*/
public function addSql($sql)
{
......
......@@ -50,7 +50,7 @@ class SchemaDropTableEventArgs extends SchemaEventArgs
/**
* @param string $sql
*
* @return \Doctrine\DBAL\Event\SchemaDropTableEventArgs
* @return SchemaDropTableEventArgs
*/
public function setSql($sql)
{
......
......@@ -13,7 +13,7 @@ class SchemaEventArgs extends EventArgs
private $preventDefault = false;
/**
* @return \Doctrine\DBAL\Event\SchemaEventArgs
* @return SchemaEventArgs
*/
public function preventDefault()
{
......
......@@ -8,10 +8,10 @@ use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\LockMode;
use Throwable;
use const CASE_LOWER;
use function array_change_key_case;
use function assert;
use function is_int;
use const CASE_LOWER;
/**
* Table ID Generator for those poor languages that are missing sequences.
......@@ -72,6 +72,7 @@ class TableGenerator
if ($params['driver'] === 'pdo_sqlite') {
throw new DBALException('Cannot use TableGenerator with SQLite.');
}
$this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager());
$this->generatorTableName = $generatorTableName;
}
......@@ -141,6 +142,7 @@ class TableGenerator
$this->conn->commit();
} catch (Throwable $e) {
$this->conn->rollBack();
throw new DBALException('Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e);
}
......
......@@ -2,8 +2,8 @@
namespace Doctrine\DBAL\Logging;
use const PHP_EOL;
use function var_dump;
use const PHP_EOL;
/**
* A SQL logger that logs to the standard output using echo/var_dump.
......
......@@ -28,7 +28,6 @@ use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use InvalidArgumentException;
use UnexpectedValueException;
use const E_USER_DEPRECATED;
use function addcslashes;
use function array_map;
use function array_merge;
......@@ -55,6 +54,7 @@ use function strpos;
use function strtolower;
use function strtoupper;
use function trigger_error;
use const E_USER_DEPRECATED;
/**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
......@@ -1552,7 +1552,7 @@ abstract class AbstractPlatform
if (($createFlags&self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/** @var $index Index */
assert($index instanceof Index);
if ($index->isPrimary()) {
$options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index;
......@@ -1614,6 +1614,7 @@ abstract class AbstractPlatform
if ($table->hasOption('comment')) {
$sql[] = $this->getCommentOnTableSQL($tableName, $table->getOption('comment'));
}
foreach ($table->getColumns() as $column) {
$comment = $this->getColumnComment($column);
......@@ -1712,6 +1713,7 @@ abstract class AbstractPlatform
if (! empty($check)) {
$query .= ', ' . $check;
}
$query .= ')';
$sql[] = $query;
......@@ -1793,6 +1795,7 @@ abstract class AbstractPlatform
$referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) .
' (' . implode(', ', $constraint->getQuotedForeignColumns($this)) . ')';
}
$query .= ' ' . $columnList . $referencesClause;
return $query;
......@@ -1812,6 +1815,7 @@ abstract class AbstractPlatform
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}
$name = $index->getQuotedName($this);
$columns = $index->getColumns();
......@@ -2080,6 +2084,7 @@ abstract class AbstractPlatform
foreach ($diff->removedForeignKeys as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
}
foreach ($diff->changedForeignKeys as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
}
......@@ -2088,6 +2093,7 @@ abstract class AbstractPlatform
foreach ($diff->removedIndexes as $index) {
$sql[] = $this->getDropIndexSQL($index, $tableName);
}
foreach ($diff->changedIndexes as $index) {
$sql[] = $this->getDropIndexSQL($index, $tableName);
}
......@@ -2515,6 +2521,7 @@ abstract class AbstractPlatform
if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate'));
}
if ($foreignKey->hasOption('onDelete')) {
$query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete'));
}
......@@ -2561,14 +2568,17 @@ abstract class AbstractPlatform
if (strlen($foreignKey->getName())) {
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
}
$sql .= 'FOREIGN KEY (';
if (count($foreignKey->getLocalColumns()) === 0) {
throw new InvalidArgumentException("Incomplete definition. 'local' required.");
}
if (count($foreignKey->getForeignColumns()) === 0) {
throw new InvalidArgumentException("Incomplete definition. 'foreign' required.");
}
if (strlen($foreignKey->getForeignTableName()) === 0) {
throw new InvalidArgumentException("Incomplete definition. 'foreignTable' required.");
}
......
......@@ -22,9 +22,6 @@ use function strtoupper;
class DB2Platform extends AbstractPlatform
{
/**
* {@inheritdoc}
*/
public function getCharMaxLength() : int
{
return 254;
......@@ -495,6 +492,7 @@ class DB2Platform extends AbstractPlatform
if (isset($options['indexes'])) {
$indexes = $options['indexes'];
}
$options['indexes'] = [];
$sqls = parent::_getCreateTableSQL($tableName, $columns, $options);
......@@ -708,21 +706,23 @@ class DB2Platform extends AbstractPlatform
foreach ($diff->removedIndexes as $remKey => $remIndex) {
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() === $addIndex->getColumns()) {
if ($remIndex->isPrimary()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
} elseif ($remIndex->isUnique()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP UNIQUE ' . $remIndex->getQuotedName($this);
} else {
$sql[] = $this->getDropIndexSQL($remIndex, $table);
}
if ($remIndex->getColumns() !== $addIndex->getColumns()) {
continue;
}
$sql[] = $this->getCreateIndexSQL($addIndex, $table);
if ($remIndex->isPrimary()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
} elseif ($remIndex->isUnique()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP UNIQUE ' . $remIndex->getQuotedName($this);
} else {
$sql[] = $this->getDropIndexSQL($remIndex, $table);
}
unset($diff->removedIndexes[$remKey], $diff->addedIndexes[$addKey]);
$sql[] = $this->getCreateIndexSQL($addIndex, $table);
break;
}
unset($diff->removedIndexes[$remKey], $diff->addedIndexes[$addKey]);
break;
}
}
......
......@@ -550,6 +550,7 @@ class DrizzlePlatform extends AbstractPlatform
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(', ', $queryParts);
}
$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
......
......@@ -9,9 +9,6 @@ namespace Doctrine\DBAL\Platforms\Keywords;
*/
final class MariaDb102Keywords extends MySQLKeywords
{
/**
* {@inheritdoc}
*/
public function getName() : string
{
return 'MariaDb102';
......
......@@ -9,9 +9,6 @@ namespace Doctrine\DBAL\Platforms\Keywords;
*/
class PostgreSQL100Keywords extends PostgreSQL94Keywords
{
/**
* {@inheritdoc}
*/
public function getName() : string
{
return 'PostgreSQL100';
......
......@@ -21,17 +21,11 @@ final class MariaDb1027Platform extends MySqlPlatform
return 'LONGTEXT';
}
/**
* {@inheritdoc}
*/
protected function getReservedKeywordsClass() : string
{
return Keywords\MariaDb102Keywords::class;
}
/**
* {@inheritdoc}
*/
protected function initializeDoctrineTypeMappings() : void
{
parent::initializeDoctrineTypeMappings();
......
......@@ -635,6 +635,7 @@ SQL
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(', ', $queryParts);
}
$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
......@@ -661,25 +662,27 @@ SQL
$sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $remIndex));
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() === $addIndex->getColumns()) {
$indexClause = 'INDEX ' . $addIndex->getName();
if ($remIndex->getColumns() !== $addIndex->getColumns()) {
continue;
}
if ($addIndex->isPrimary()) {
$indexClause = 'PRIMARY KEY';
} elseif ($addIndex->isUnique()) {
$indexClause = 'UNIQUE INDEX ' . $addIndex->getName();
}
$indexClause = 'INDEX ' . $addIndex->getName();
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $indexClause;
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex) . ')';
if ($addIndex->isPrimary()) {
$indexClause = 'PRIMARY KEY';
} elseif ($addIndex->isUnique()) {
$indexClause = 'UNIQUE INDEX ' . $addIndex->getName();
}
$sql[] = $query;
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $indexClause;
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex) . ')';
unset($diff->removedIndexes[$remKey], $diff->addedIndexes[$addKey]);
$sql[] = $query;
break;
}
unset($diff->removedIndexes[$remKey], $diff->addedIndexes[$addKey]);
break;
}
}
......@@ -985,6 +988,7 @@ SQL
if ($foreignKey->hasOption('match')) {
$query .= ' MATCH ' . $foreignKey->getOption('match');
}
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
return $query;
......@@ -1180,9 +1184,6 @@ SQL
return TransactionIsolationLevel::REPEATABLE_READ;
}
/**
* {@inheritdoc}
*/
public function supportsColumnLengthIndexes() : bool
{
return true;
......
......@@ -11,9 +11,6 @@ use Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords;
*/
class PostgreSQL100Platform extends PostgreSQL94Platform
{
/**
* {@inheritdoc}
*/
protected function getReservedKeywordsClass() : string
{
return PostgreSQL100Keywords::class;
......
......@@ -19,6 +19,7 @@ use function array_diff;
use function array_merge;
use function array_unique;
use function array_values;
use function assert;
use function count;
use function explode;
use function implode;
......@@ -531,7 +532,7 @@ SQL
}
foreach ($diff->changedColumns as $columnDiff) {
/** @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */
assert($columnDiff instanceof ColumnDiff);
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
......
......@@ -17,6 +17,7 @@ use InvalidArgumentException;
use function array_merge;
use function array_unique;
use function array_values;
use function assert;
use function count;
use function explode;
use function func_get_args;
......@@ -1257,8 +1258,8 @@ SQL
}
if (! empty($options['indexes'])) {
/** @var Index $index */
foreach ((array) $options['indexes'] as $index) {
assert($index instanceof Index);
$indexSql[] = $this->getCreateIndexSQL($index, $tableName);
}
}
......
......@@ -3,10 +3,10 @@
namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\Sequence;
use const PREG_OFFSET_CAPTURE;
use function preg_match;
use function preg_match_all;
use function substr_count;
use const PREG_OFFSET_CAPTURE;
/**
* Platform to ensure compatibility of Doctrine with Microsoft SQL Server 2012 version.
......@@ -105,7 +105,7 @@ class SQLServer2012Platform extends SQLServer2008Platform
$matchesCount = preg_match_all('/[\\s]+order\\s+by\\s/im', $query, $matches, PREG_OFFSET_CAPTURE);
$orderByPos = false;
if ($matchesCount > 0) {
$orderByPos = $matches[0][($matchesCount - 1)][1];
$orderByPos = $matches[0][$matchesCount - 1][1];
}
if ($orderByPos === false
......
......@@ -285,6 +285,7 @@ SQL
if (isset($options['primary_index']) && $options['primary_index']->hasFlag('nonclustered')) {
$flags = ' NONCLUSTERED';
}
$columnListSql .= ', PRIMARY KEY' . $flags . ' (' . implode(', ', array_unique(array_values($options['primary']))) . ')';
}
......@@ -294,6 +295,7 @@ SQL
if (! empty($check)) {
$query .= ', ' . $check;
}
$query .= ')';
$sql = [$query];
......
......@@ -776,9 +776,6 @@ class SqlitePlatform extends AbstractPlatform
return true;
}
/**
* {@inheritDoc}
*/
public function supportsCreateDropForeignKeyConstraints() : bool
{
return false;
......
......@@ -6,9 +6,9 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Driver\PDOConnection;
use PDO;
use function func_get_args;
use const CASE_LOWER;
use const CASE_UPPER;
use function func_get_args;
/**
* Portability wrapper for a Connection.
......@@ -62,6 +62,7 @@ class Connection extends \Doctrine\DBAL\Connection
} else {
$params['portability'] &= self::PORTABILITY_OTHERVENDORS;
}
$this->portability = $params['portability'];
}
......
......@@ -51,7 +51,7 @@ class CompositeExpression implements Countable
*
* @param self[]|string[] $parts
*
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression
* @return CompositeExpression
*/
public function addMultiple(array $parts = [])
{
......@@ -67,7 +67,7 @@ class CompositeExpression implements Countable
*
* @param mixed $part
*
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression
* @return CompositeExpression
*/
public function add($part)
{
......
......@@ -1275,6 +1275,7 @@ class QueryBuilder
$this->boundCounter++;
$placeHolder = ':dcValue' . $this->boundCounter;
}
$this->setParameter(substr($placeHolder, 1), $value, $type);
return $placeHolder;
......@@ -1327,11 +1328,13 @@ class QueryBuilder
if (array_key_exists($join['joinAlias'], $knownAliases)) {
throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases));
}
$sql .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'];
if ($join['joinCondition'] !== null) {
$sql .= ' ON ' . $join['joinCondition'];
}
$knownAliases[$join['joinAlias']] = true;
}
......
......@@ -14,7 +14,7 @@ class QueryException extends DBALException
* @param string $alias
* @param string[] $registeredAliases
*
* @return \Doctrine\DBAL\Query\QueryException
* @return QueryException
*/
public static function unknownAlias($alias, $registeredAliases)
{
......@@ -27,7 +27,7 @@ class QueryException extends DBALException
* @param string $alias
* @param string[] $registeredAliases
*
* @return \Doctrine\DBAL\Query\QueryException
* @return QueryException
*/
public static function nonUniqueAlias($alias, $registeredAliases)
{
......
......@@ -2,7 +2,6 @@
namespace Doctrine\DBAL;
use const PREG_OFFSET_CAPTURE;
use function array_fill;
use function array_fill_keys;
use function array_key_exists;
......@@ -20,6 +19,7 @@ use function sprintf;
use function strlen;
use function strpos;
use function substr;
use const PREG_OFFSET_CAPTURE;
/**
* Utility class that parses sql statements with regard to types and parameters.
......@@ -195,8 +195,8 @@ class SQLParserUtils
$expandStr = $count ? 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.
$queryOffset += (strlen($expandStr) - 1);
$paramOffset += $count - 1; // Grows larger by number of parameters minus the replaced needle.
$queryOffset += strlen($expandStr) - 1;
}
return [$query, $params, $types];
......@@ -214,10 +214,10 @@ class SQLParserUtils
if (! isset($arrayPositions[$paramName]) && ! isset($arrayPositions[':' . $paramName])) {
$pos += $queryOffset;
$queryOffset -= ($paramLen - 1);
$queryOffset -= $paramLen - 1;
$paramsOrd[] = $value;
$typesOrd[] = static::extractParam($paramName, $types, false, ParameterType::STRING);
$query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen));
$query = substr($query, 0, $pos) . '?' . substr($query, $pos + $paramLen);
continue;
}
......@@ -231,8 +231,8 @@ class SQLParserUtils
}
$pos += $queryOffset;
$queryOffset += (strlen($expandStr) - $paramLen);
$query = substr($query, 0, $pos) . $expandStr . substr($query, ($pos + $paramLen));
$queryOffset += strlen($expandStr) - $paramLen;
$query = substr($query, 0, $pos) . $expandStr . substr($query, $pos + $paramLen);
}
return [$query, $paramsOrd, $typesOrd];
......
......@@ -14,7 +14,7 @@ class SQLParserUtilsException extends DBALException
/**
* @param string $paramName
*
* @return \Doctrine\DBAL\SQLParserUtilsException
* @return SQLParserUtilsException
*/
public static function missingParam($paramName)
{
......@@ -24,7 +24,7 @@ class SQLParserUtilsException extends DBALException
/**
* @param string $typeName
*
* @return \Doctrine\DBAL\SQLParserUtilsException
* @return SQLParserUtilsException
*/
public static function missingType($typeName)
{
......
......@@ -48,11 +48,13 @@ abstract class AbstractAsset
$this->_quoted = true;
$name = $this->trimQuotes($name);
}
if (strpos($name, '.') !== false) {
$parts = explode('.', $name);
$this->_namespace = $parts[0];
$name = $parts[1];
}
$this->_name = $name;
}
......
......@@ -132,6 +132,7 @@ abstract class AbstractSchemaManager
if ($database === null) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListSequencesSQL($database);
$sequences = $this->_conn->fetchAll($sql);
......@@ -273,6 +274,7 @@ abstract class AbstractSchemaManager
if ($this->_platform->supportsForeignKeyConstraints()) {
$foreignKeys = $this->listTableForeignKeys($tableName);
}
$indexes = $this->listTableIndexes($tableName);
return new Table($tableName, $columns, $indexes, $foreignKeys);
......@@ -305,6 +307,7 @@ abstract class AbstractSchemaManager
if ($database === null) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
$tableForeignKeys = $this->_conn->fetchAll($sql);
......@@ -846,6 +849,7 @@ abstract class AbstractSchemaManager
if ($tableIndex['primary']) {
$keyName = 'primary';
}
$keyName = strtolower($keyName);
if (! isset($result[$keyName])) {
......@@ -1075,9 +1079,11 @@ abstract class AbstractSchemaManager
if (! isset($params['defaultTableOptions'])) {
$params['defaultTableOptions'] = [];
}
if (! isset($params['defaultTableOptions']['charset']) && isset($params['charset'])) {
$params['defaultTableOptions']['charset'] = $params['charset'];
}
$schemaConfig->setDefaultTableOptions($params['defaultTableOptions']);
return $schemaConfig;
......
......@@ -3,12 +3,12 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
use const E_USER_DEPRECATED;
use function array_merge;
use function is_numeric;
use function method_exists;
use function sprintf;
use function trigger_error;
use const E_USER_DEPRECATED;
/**
* Object representation of a database column.
......@@ -86,6 +86,7 @@ class Column extends AbstractAsset
continue;
}
$this->$method($value);
}
......
......@@ -89,6 +89,7 @@ class Comparator
if (! isset($foreignKeysToTable[$foreignTable])) {
$foreignKeysToTable[$foreignTable] = [];
}
$foreignKeysToTable[$foreignTable][] = $foreignKey;
}
}
......@@ -116,6 +117,7 @@ class Comparator
if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) {
continue;
}
unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]);
}
}
......@@ -205,6 +207,7 @@ class Comparator
$tableDifferences->addedColumns[$columnName] = $column;
$changes++;
}
/* See if there are any removed fields in table 2 */
foreach ($table1Columns as $columnName => $column) {
// See if column is removed in table 2.
......@@ -241,6 +244,7 @@ class Comparator
$tableDifferences->addedIndexes[$indexName] = $index;
$changes++;
}
/* See if there are any removed indexes in table 2 */
foreach ($table1Indexes as $indexName => $index) {
// See if index is removed in table 2.
......@@ -465,6 +469,7 @@ class Comparator
if (($properties1['precision'] ?: 10) !== ($properties2['precision'] ?: 10)) {
$changedProperties[] = 'precision';
}
if ($properties1['scale'] !== $properties2['scale']) {
$changedProperties[] = 'scale';
}
......
......@@ -4,14 +4,15 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Types\Type;
use const CASE_LOWER;
use function array_change_key_case;
use function assert;
use function is_resource;
use function preg_match;
use function str_replace;
use function strpos;
use function strtolower;
use function substr;
use const CASE_LOWER;
/**
* IBM Db2 Schema Manager.
......@@ -220,9 +221,9 @@ class DB2SchemaManager extends AbstractSchemaManager
{
$table = parent::listTableDetails($tableName);
/** @var DB2Platform $platform */
$platform = $this->_platform;
$sql = $platform->getListTableCommentsSQL($tableName);
assert($platform instanceof DB2Platform);
$sql = $platform->getListTableCommentsSQL($tableName);
$tableOptions = $this->_conn->fetchAssoc($sql);
......
......@@ -65,6 +65,7 @@ class Index extends AbstractAsset implements Constraint
foreach ($columns as $column) {
$this->_addColumn($column);
}
foreach ($flags as $flag) {
$this->addFlag($flag);
}
......
......@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Type;
use const CASE_LOWER;
use function array_change_key_case;
use function array_shift;
use function array_values;
......@@ -17,6 +16,7 @@ use function strpos;
use function strtok;
use function strtolower;
use function strtr;
use const CASE_LOWER;
/**
* Schema manager for the MySql RDBMS.
......@@ -82,11 +82,13 @@ class MySqlSchemaManager extends AbstractSchemaManager
} else {
$v['primary'] = false;
}
if (strpos($v['index_type'], 'FULLTEXT') !== false) {
$v['flags'] = ['FULLTEXT'];
} elseif (strpos($v['index_type'], 'SPATIAL') !== false) {
$v['flags'] = ['SPATIAL'];
}
$v['length'] = isset($v['sub_part']) ? (int) $v['sub_part'] : null;
$tableIndexes[$k] = $v;
......@@ -149,6 +151,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$scale = $match[2];
$length = null;
}
break;
case 'tinytext':
......@@ -216,6 +219,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
if (isset($tableColumn['characterset'])) {
$column->setPlatformOption('charset', $tableColumn['characterset']);
}
if (isset($tableColumn['collation'])) {
$column->setPlatformOption('collation', $tableColumn['collation']);
}
......@@ -275,6 +279,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
if (! isset($value['delete_rule']) || $value['delete_rule'] === 'RESTRICT') {
$value['delete_rule'] = null;
}
if (! isset($value['update_rule']) || $value['update_rule'] === 'RESTRICT') {
$value['update_rule'] = null;
}
......@@ -288,6 +293,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
'onUpdate' => $value['update_rule'],
];
}
$list[$value['constraint_name']]['local'][] = $value['column_name'];
$list[$value['constraint_name']]['foreign'][] = $value['referenced_column_name'];
}
......@@ -313,9 +319,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
{
$table = parent::listTableDetails($tableName);
/** @var MySqlPlatform $platform */
$platform = $this->_platform;
$sql = $platform->getListTableMetadataSQL($tableName);
assert($platform instanceof MySqlPlatform);
$sql = $platform->getListTableMetadataSQL($tableName);
$tableOptions = $this->_conn->fetchAssoc($sql);
......
......@@ -7,7 +7,6 @@ use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Types\Type;
use Throwable;
use const CASE_LOWER;
use function array_change_key_case;
use function array_values;
use function assert;
......@@ -18,6 +17,7 @@ use function strpos;
use function strtolower;
use function strtoupper;
use function trim;
use const CASE_LOWER;
/**
* Oracle Schema Manager.
......@@ -107,6 +107,7 @@ class OracleSchemaManager extends AbstractSchemaManager
$buffer['primary'] = false;
$buffer['non_unique'] = ! $tableIndex['is_unique'];
}
$buffer['key_name'] = $keyName;
$buffer['column_name'] = $this->getQuotedIdentifierName($tableIndex['column_name']);
$indexBuffer[] = $buffer;
......@@ -398,9 +399,9 @@ SQL;
{
$table = parent::listTableDetails($tableName);
/** @var OraclePlatform $platform */
$platform = $this->_platform;
$sql = $platform->getListTableCommentsSQL($tableName);
assert($platform instanceof OraclePlatform);
$sql = $platform->getListTableCommentsSQL($tableName);
$tableOptions = $this->_conn->fetchAssoc($sql);
......
......@@ -7,7 +7,6 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use const CASE_LOWER;
use function array_change_key_case;
use function array_filter;
use function array_keys;
......@@ -25,6 +24,7 @@ use function strlen;
use function strpos;
use function strtolower;
use function trim;
use const CASE_LOWER;
/**
* PostgreSQL Schema Manager.
......@@ -141,6 +141,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
$onUpdate = $match[1];
}
if (preg_match('(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
$onDelete = $match[1];
}
......@@ -339,9 +340,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if ($length === '-1' && isset($tableColumn['atttypmod'])) {
$length = $tableColumn['atttypmod'] - 4;
}
if ((int) $length <= 0) {
$length = null;
}
$fixed = null;
if (! isset($tableColumn['name'])) {
......@@ -426,6 +429,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$scale = $match[2];
$length = null;
}
break;
case 'year':
......@@ -501,9 +505,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
{
$table = parent::listTableDetails($tableName);
/** @var PostgreSqlPlatform $platform */
$platform = $this->_platform;
$sql = $platform->getListTableMetadataSQL($tableName);
assert($platform instanceof PostgreSqlPlatform);
$sql = $platform->getListTableMetadataSQL($tableName);
$tableOptions = $this->_conn->fetchAssoc($sql);
......
......@@ -93,6 +93,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
if ($length === -1) {
$dbType = 'text';
}
break;
}
......@@ -335,9 +336,9 @@ class SQLServerSchemaManager extends AbstractSchemaManager
{
$table = parent::listTableDetails($tableName);
/** @var SQLServerPlatform $platform */
$platform = $this->_platform;
$sql = $platform->getListTableMetadataSQL($tableName);
assert($platform instanceof SQLServerPlatform);
$sql = $platform->getListTableMetadataSQL($tableName);
$tableOptions = $this->_conn->fetchAssoc($sql);
......
......@@ -67,6 +67,7 @@ class Schema extends AbstractAsset
if ($schemaConfig === null) {
$schemaConfig = new SchemaConfig();
}
$this->_schemaConfig = $schemaConfig;
$this->_setName($schemaConfig->getName() ?: 'public');
......@@ -287,7 +288,7 @@ class Schema extends AbstractAsset
*
* @param string $namespaceName The name of the namespace to create.
*
* @return \Doctrine\DBAL\Schema\Schema This schema instance.
* @return Schema This schema instance.
*
* @throws SchemaException
*/
......@@ -329,7 +330,7 @@ class Schema extends AbstractAsset
* @param string $oldTableName
* @param string $newTableName
*
* @return \Doctrine\DBAL\Schema\Schema
* @return Schema
*/
public function renameTable($oldTableName, $newTableName)
{
......@@ -347,7 +348,7 @@ class Schema extends AbstractAsset
*
* @param string $tableName
*
* @return \Doctrine\DBAL\Schema\Schema
* @return Schema
*/
public function dropTable($tableName)
{
......@@ -378,7 +379,7 @@ class Schema extends AbstractAsset
/**
* @param string $sequenceName
*
* @return \Doctrine\DBAL\Schema\Schema
* @return Schema
*/
public function dropSequence($sequenceName)
{
......@@ -468,6 +469,7 @@ class Schema extends AbstractAsset
foreach ($this->_tables as $k => $table) {
$this->_tables[$k] = clone $table;
}
foreach ($this->_sequences as $k => $sequence) {
$this->_sequences[$k] = clone $sequence;
}
......
......@@ -155,6 +155,7 @@ class SchemaDiff
$foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
}
}
$sql = array_merge($sql, $foreignKeySql);
if ($saveMode === false) {
......
......@@ -26,7 +26,7 @@ class SchemaException extends DBALException
/**
* @param string $tableName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function tableDoesNotExist($tableName)
{
......@@ -36,7 +36,7 @@ class SchemaException extends DBALException
/**
* @param string $indexName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function indexNameInvalid($indexName)
{
......@@ -50,7 +50,7 @@ class SchemaException extends DBALException
* @param string $indexName
* @param string $table
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function indexDoesNotExist($indexName, $table)
{
......@@ -64,7 +64,7 @@ class SchemaException extends DBALException
* @param string $indexName
* @param string $table
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function indexAlreadyExists($indexName, $table)
{
......@@ -78,7 +78,7 @@ class SchemaException extends DBALException
* @param string $columnName
* @param string $table
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function columnDoesNotExist($columnName, $table)
{
......@@ -91,7 +91,7 @@ class SchemaException extends DBALException
/**
* @param string $namespaceName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function namespaceAlreadyExists($namespaceName)
{
......@@ -104,7 +104,7 @@ class SchemaException extends DBALException
/**
* @param string $tableName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function tableAlreadyExists($tableName)
{
......@@ -115,7 +115,7 @@ class SchemaException extends DBALException
* @param string $tableName
* @param string $columnName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function columnAlreadyExists($tableName, $columnName)
{
......@@ -128,7 +128,7 @@ class SchemaException extends DBALException
/**
* @param string $sequenceName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function sequenceAlreadyExists($sequenceName)
{
......@@ -138,7 +138,7 @@ class SchemaException extends DBALException
/**
* @param string $sequenceName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function sequenceDoesNotExist($sequenceName)
{
......@@ -149,7 +149,7 @@ class SchemaException extends DBALException
* @param string $fkName
* @param string $table
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function foreignKeyDoesNotExist($fkName, $table)
{
......@@ -160,7 +160,7 @@ class SchemaException extends DBALException
}
/**
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
{
......@@ -175,7 +175,7 @@ class SchemaException extends DBALException
/**
* @param string $changeName
*
* @return \Doctrine\DBAL\Schema\SchemaException
* @return SchemaException
*/
public static function alterTableChangeNotSupported($changeName)
{
......
......@@ -61,7 +61,7 @@ class Sequence extends AbstractAsset
/**
* @param int $allocationSize
*
* @return \Doctrine\DBAL\Schema\Sequence
* @return Sequence
*/
public function setAllocationSize($allocationSize)
{
......@@ -73,7 +73,7 @@ class Sequence extends AbstractAsset
/**
* @param int $initialValue
*
* @return \Doctrine\DBAL\Schema\Sequence
* @return Sequence
*/
public function setInitialValue($initialValue)
{
......@@ -85,7 +85,7 @@ class Sequence extends AbstractAsset
/**
* @param int $cache
*
* @return \Doctrine\DBAL\Schema\Sequence
* @return Sequence
*/
public function setCache($cache)
{
......
......@@ -8,7 +8,6 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\Type;
use const CASE_LOWER;
use function array_change_key_case;
use function array_map;
use function array_reverse;
......@@ -27,6 +26,7 @@ use function strtolower;
use function trim;
use function unlink;
use function usort;
use const CASE_LOWER;
/**
* Sqlite SchemaManager.
......@@ -113,6 +113,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
if ($database === null) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
$tableForeignKeys = $this->_conn->fetchAll($sql);
......@@ -358,8 +359,10 @@ class SqliteSchemaManager extends AbstractSchemaManager
if (strpos($tableColumn['length'], ',') === false) {
$tableColumn['length'] .= ',0';
}
[$precision, $scale] = array_map('trim', explode(',', $tableColumn['length']));
}
$length = null;
break;
}
......@@ -399,6 +402,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
if (! isset($value['on_delete']) || $value['on_delete'] === 'RESTRICT') {
$value['on_delete'] = null;
}
if (! isset($value['on_update']) || $value['on_update'] === 'RESTRICT') {
$value['on_update'] = null;
}
......@@ -414,6 +418,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
'deferred'=> $value['deferred'],
];
}
$list[$name]['local'][] = $value['from'];
$list[$name]['foreign'][] = $value['to'];
}
......
......@@ -5,13 +5,14 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Types\Type;
use const ARRAY_FILTER_USE_KEY;
use function array_filter;
use function array_merge;
use function assert;
use function in_array;
use function preg_match;
use function strlen;
use function strtolower;
use const ARRAY_FILTER_USE_KEY;
/**
* Object Representation of a table.
......@@ -161,6 +162,7 @@ class Table extends AbstractAsset
if (! $this->hasIndex($indexName)) {
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
}
unset($this->_indexes[$indexName]);
}
......@@ -240,7 +242,7 @@ class Table extends AbstractAsset
public function columnsAreIndexed(array $columnNames)
{
foreach ($this->getIndexes() as $index) {
/** @var $index Index */
assert($index instanceof Index);
if ($index->spansColumns($columnNames)) {
return true;
}
......@@ -510,6 +512,7 @@ class Table extends AbstractAsset
$this->_getMaxIdentifierLength()
);
}
$name = $this->normalizeIdentifier($name);
$this->_fkConstraints[$name] = $constraint;
......@@ -816,9 +819,11 @@ class Table extends AbstractAsset
foreach ($this->_columns as $k => $column) {
$this->_columns[$k] = clone $column;
}
foreach ($this->_indexes as $k => $index) {
$this->_indexes[$k] = clone $index;
}
foreach ($this->_fkConstraints as $k => $fk) {
$this->_fkConstraints[$k] = clone $fk;
$this->_fkConstraints[$k]->setLocalTable($this);
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use SplObjectStorage;
use function assert;
use function strlen;
/**
......@@ -82,19 +83,19 @@ class DropSchemaSqlCollector extends AbstractVisitor
{
$sql = [];
/** @var ForeignKeyConstraint $fkConstraint */
foreach ($this->constraints as $fkConstraint) {
assert($fkConstraint instanceof ForeignKeyConstraint);
$localTable = $this->constraints[$fkConstraint];
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
}
/** @var Sequence $sequence */
foreach ($this->sequences as $sequence) {
assert($sequence instanceof Sequence);
$sql[] = $this->platform->getDropSequenceSQL($sequence);
}
/** @var Table $table */
foreach ($this->tables as $table) {
assert($table instanceof Table);
$sql[] = $this->platform->getDropTableSQL($table);
}
......
......@@ -87,6 +87,7 @@ class Graphviz extends AbstractVisitor
if ($primaryKey !== null && in_array($column->getName(), $primaryKey->getColumns())) {
$label .= "\xe2\x9c\xb7";
}
$label .= '</TD></TR>';
}
......@@ -108,6 +109,7 @@ class Graphviz extends AbstractVisitor
foreach ($options as $key => $value) {
$node .= $key . '=' . $value . ' ';
}
$node .= "]\n";
return $node;
......@@ -126,6 +128,7 @@ class Graphviz extends AbstractVisitor
foreach ($options as $key => $value) {
$relation .= $key . '=' . $value . ' ';
}
$relation .= "]\n";
return $relation;
......
......@@ -108,6 +108,7 @@ class MultiTenantVisitor implements Visitor
return $index;
}
}
throw new RuntimeException('No clustered index found on table ' . $table->getName());
}
......
......@@ -12,7 +12,7 @@ use Doctrine\DBAL\DBALException;
class ShardingException extends DBALException
{
/**
* @return \Doctrine\DBAL\Sharding\ShardingException
* @return ShardingException
*/
public static function notImplemented()
{
......@@ -20,7 +20,7 @@ class ShardingException extends DBALException
}
/**
* @return \Doctrine\DBAL\Sharding\ShardingException
* @return ShardingException
*/
public static function missingDefaultFederationName()
{
......@@ -28,7 +28,7 @@ class ShardingException extends DBALException
}
/**
* @return \Doctrine\DBAL\Sharding\ShardingException
* @return ShardingException
*/
public static function missingDefaultDistributionKey()
{
......@@ -36,7 +36,7 @@ class ShardingException extends DBALException
}
/**
* @return \Doctrine\DBAL\Sharding\ShardingException
* @return ShardingException
*/
public static function activeTransaction()
{
......@@ -44,7 +44,7 @@ class ShardingException extends DBALException
}
/**
* @return \Doctrine\DBAL\Sharding\ShardingException
* @return ShardingException
*/
public static function noShardDistributionValue()
{
......@@ -52,7 +52,7 @@ class ShardingException extends DBALException
}
/**
* @return \Doctrine\DBAL\Sharding\ShardingException
* @return ShardingException
*/
public static function missingDistributionType()
{
......
......@@ -95,6 +95,7 @@ class Statement implements IteratorAggregate, DriverStatement
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->platform);
$bindingType = $type->getBindingType();
......@@ -155,6 +156,7 @@ class Statement implements IteratorAggregate, DriverStatement
if ($logger) {
$logger->stopQuery();
}
throw DBALException::driverExceptionDuringQuery(
$this->conn->getDriver(),
$ex,
......@@ -166,6 +168,7 @@ class Statement implements IteratorAggregate, DriverStatement
if ($logger) {
$logger->stopQuery();
}
$this->params = [];
$this->types = [];
......
......@@ -11,7 +11,6 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use const PHP_EOL;
use function assert;
use function error_get_last;
use function file_exists;
......@@ -19,6 +18,7 @@ use function file_get_contents;
use function is_readable;
use function realpath;
use function sprintf;
use const PHP_EOL;
/**
* Task for executing arbitrary SQL that can come from a file or directly from
......
......@@ -27,6 +27,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function array_keys;
use function assert;
use function count;
use function implode;
......@@ -120,8 +121,8 @@ EOT
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var Connection $conn */
$conn = $this->getHelper('db')->getConnection();
assert($conn instanceof Connection);
$keywordLists = (array) $input->getOption('list');
if (! $keywordLists) {
......@@ -152,6 +153,7 @@ EOT
'Known lists: ' . implode(', ', array_keys($this->keywordListClasses))
);
}
$class = $this->keywordListClasses[$keywordList];
$keywords[] = new $class();
}
......
......@@ -150,6 +150,7 @@ final class Dumper
if ($aux[0] === '') {
$name .= ':' . ($aux[1] === '*' ? 'protected' : $aux[1] . ':private');
}
$return->$name = self::export($clone[$key], $maxDepth - 1);
}
......
......@@ -26,7 +26,7 @@ class ConversionException extends DBALException
* @param string $value
* @param string $toType
*
* @return \Doctrine\DBAL\Types\ConversionException
* @return ConversionException
*/
public static function conversionFailed($value, $toType, ?Throwable $previous = null)
{
......@@ -43,7 +43,7 @@ class ConversionException extends DBALException
* @param string $toType
* @param string $expectedFormat
*
* @return \Doctrine\DBAL\Types\ConversionException
* @return ConversionException
*/
public static function conversionFailedFormat($value, $toType, $expectedFormat, ?Throwable $previous = null)
{
......@@ -64,7 +64,7 @@ class ConversionException extends DBALException
* @param string $toType
* @param string[] $possibleTypes
*
* @return \Doctrine\DBAL\Types\ConversionException
* @return ConversionException
*/
public static function conversionFailedInvalidType(
$value,
......
......@@ -3,13 +3,13 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use const JSON_ERROR_NONE;
use function is_resource;
use function json_decode;
use function json_encode;
use function json_last_error;
use function json_last_error_msg;
use function stream_get_contents;
use const JSON_ERROR_NONE;
/**
* Type generating json objects values
......
......@@ -222,7 +222,7 @@ abstract class Type
*
* @param string $name The name of the type (as returned by getName()).
*
* @return \Doctrine\DBAL\Types\Type
* @return Type
*
* @throws DBALException
*/
......
......@@ -17,9 +17,6 @@ class ConfigurationTest extends DbalTestCase
*/
protected $config;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{
$this->config = new Configuration();
......
......@@ -27,6 +27,7 @@ use Doctrine\Tests\DbalTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use stdClass;
use function assert;
use function call_user_func_array;
/**
......@@ -171,8 +172,8 @@ class ConnectionTest extends DbalTestCase
->method('setEventManager')
->with($eventManager);
/** @var Driver|MockObject $driver */
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver || $driver instanceof MockObject);
$driver->expects($this->any())
->method('getDatabasePlatform')
->willReturn($platform);
......@@ -564,11 +565,11 @@ class ConnectionTest extends DbalTestCase
->with(FetchMode::ASSOCIATIVE)
->will($this->returnValue($result));
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock])
->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once())
->method('executeQuery')
......@@ -600,11 +601,11 @@ class ConnectionTest extends DbalTestCase
->with(FetchMode::NUMERIC)
->will($this->returnValue($result));
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock])
->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once())
->method('executeQuery')
......@@ -637,11 +638,11 @@ class ConnectionTest extends DbalTestCase
->with($column)
->will($this->returnValue($result));
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock])
->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once())
->method('executeQuery')
......@@ -672,11 +673,11 @@ class ConnectionTest extends DbalTestCase
->method('fetchAll')
->will($this->returnValue($result));
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock])
->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once())
->method('executeQuery')
......@@ -710,8 +711,8 @@ class ConnectionTest extends DbalTestCase
public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void
{
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
$pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class);
// should never execute queries with invalid arguments
......@@ -769,14 +770,14 @@ class ConnectionTest extends DbalTestCase
*/
public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : void
{
/** @var Driver|VersionAwarePlatformDriver|MockObject $driverMock */
$driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]);
assert($driverMock instanceof Driver || $driverMock instanceof VersionAwarePlatformDriver || $driverMock instanceof MockObject);
/** @var ServerInfoAwareConnection|MockObject $driverConnectionMock */
$driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class);
assert($driverConnectionMock instanceof ServerInfoAwareConnection || $driverConnectionMock instanceof MockObject);
/** @var AbstractPlatform|MockObject $platformMock */
$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);
assert($platformMock instanceof AbstractPlatform || $platformMock instanceof MockObject);
$connection = new Connection([], $driverMock);
......@@ -814,8 +815,8 @@ class ConnectionTest extends DbalTestCase
$params = [666];
$types = [ParameterType::INTEGER];
/** @var QueryCacheProfile|MockObject $queryCacheProfileMock */
$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);
assert($queryCacheProfileMock instanceof QueryCacheProfile || $queryCacheProfileMock instanceof MockObject);
$queryCacheProfileMock
->expects($this->any())
......@@ -829,8 +830,8 @@ class ConnectionTest extends DbalTestCase
->with($query, $params, $types, $this->params)
->will($this->returnValue(['cacheKey', 'realKey']));
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
self::assertInstanceOf(
ArrayStatement::class,
......@@ -851,8 +852,8 @@ class ConnectionTest extends DbalTestCase
->with('cacheKey')
->will($this->returnValue(['realKey' => []]));
/** @var QueryCacheProfile|MockObject $queryCacheProfileMock */
$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);
assert($queryCacheProfileMock instanceof QueryCacheProfile || $queryCacheProfileMock instanceof MockObject);
$queryCacheProfileMock
->expects($this->any())
......@@ -871,8 +872,8 @@ class ConnectionTest extends DbalTestCase
$connectionParams['platform'] = $this->createMock(AbstractPlatform::class);
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
(new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock);
}
......@@ -885,8 +886,8 @@ class ConnectionTest extends DbalTestCase
$connectionParams = $this->params;
$connectionParams['platform'] = new stdClass();
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
$this->expectException(DBALException::class);
......@@ -898,8 +899,8 @@ class ConnectionTest extends DbalTestCase
*/
public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() : void
{
/** @var Driver|VersionAwarePlatformDriver|MockObject $driverMock */
$driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]);
assert($driverMock instanceof Driver || $driverMock instanceof VersionAwarePlatformDriver || $driverMock instanceof MockObject);
$connection = new Connection(['dbname' => 'foo'], $driverMock);
$originalException = new Exception('Original exception');
......@@ -923,17 +924,17 @@ class ConnectionTest extends DbalTestCase
*/
public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void
{
/** @var Driver|MockObject $driver */
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver || $driver instanceof MockObject);
/** @var AbstractPlatform|MockObject $platform */
$platform = $this->createMock(AbstractPlatform::class);
assert($platform instanceof AbstractPlatform || $platform instanceof MockObject);
/** @var QueryCacheProfile|MockObject $queryCacheProfile */
$queryCacheProfile = $this->createMock(QueryCacheProfile::class);
assert($queryCacheProfile instanceof QueryCacheProfile || $queryCacheProfile instanceof MockObject);
/** @var Cache|MockObject $resultCacheDriver */
$resultCacheDriver = $this->createMock(Cache::class);
assert($resultCacheDriver instanceof Cache || $resultCacheDriver instanceof MockObject);
$queryCacheProfile
->expects($this->any())
......
......@@ -9,6 +9,7 @@ use Doctrine\DBAL\Exception\DriverException;
use Doctrine\Tests\DbalTestCase;
use Exception;
use stdClass;
use function assert;
use function chr;
use function fopen;
use function sprintf;
......@@ -17,27 +18,27 @@ class DBALExceptionTest extends DbalTestCase
{
public function testDriverExceptionDuringQueryAcceptsBinaryData() : void
{
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]);
assert($driver instanceof Driver);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]);
self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage());
}
public function testDriverExceptionDuringQueryAcceptsResource() : void
{
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]);
assert($driver instanceof Driver);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]);
self::assertStringContainsString('Resource', $e->getMessage());
}
public function testAvoidOverWrappingOnDriverException() : void
{
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
/** @var InnerDriverException $inner */
$inner = $this->createMock(InnerDriverException::class);
assert($inner instanceof InnerDriverException);
$ex = new DriverException('', $inner);
$e = DBALException::driverExceptionDuringQuery($driver, $ex, '');
......
......@@ -31,6 +31,7 @@ use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionProperty;
use function array_merge;
use function assert;
use function get_class;
use function sprintf;
......@@ -79,10 +80,10 @@ abstract class AbstractDriverTest extends DbalTestCase
$this->markTestSkipped('This test is only intended for exception converter drivers.');
}
/** @var DriverExceptionInterface|MockObject $driverException */
$driverException = $this->getMockBuilder(DriverExceptionInterface::class)
->setConstructorArgs([$message])
->getMock();
assert($driverException instanceof DriverExceptionInterface || $driverException instanceof MockObject);
$driverException->method('getErrorCode')
->willReturn($errorCode);
$driverException->method('getSQLState')
......
......@@ -97,9 +97,6 @@ class DriverTest extends AbstractPostgreSQLDriverTest
}
}
/**
* {@inheritDoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
......@@ -14,6 +14,7 @@ use Doctrine\Tests\DbalTestCase;
use IteratorAggregate;
use PHPUnit\Framework\MockObject\MockObject;
use Traversable;
use function assert;
use function extension_loaded;
class StatementIteratorTest extends DbalTestCase
......@@ -23,8 +24,8 @@ class StatementIteratorTest extends DbalTestCase
*/
public function testGettingIteratorDoesNotCallFetch(string $class) : void
{
/** @var IteratorAggregate|MockObject $stmt */
$stmt = $this->createPartialMock($class, ['fetch', 'fetchAll', 'fetchColumn']);
assert($stmt instanceof IteratorAggregate || $stmt instanceof MockObject);
$stmt->expects($this->never())->method('fetch');
$stmt->expects($this->never())->method('fetchAll');
$stmt->expects($this->never())->method('fetchColumn');
......
......@@ -60,13 +60,16 @@ class ConnectionTest extends DbalFunctionalTestCase
try {
$this->connection->beginTransaction();
self::assertEquals(2, $this->connection->getTransactionNestingLevel());
throw new Exception();
$this->connection->commit(); // never reached
} catch (Throwable $e) {
$this->connection->rollBack();
self::assertEquals(1, $this->connection->getTransactionNestingLevel());
//no rethrow
}
self::assertTrue($this->connection->isRollbackOnly());
$this->connection->commit(); // should throw exception
......@@ -130,13 +133,16 @@ class ConnectionTest extends DbalFunctionalTestCase
self::assertEquals(3, $this->connection->getTransactionNestingLevel());
self::assertTrue($this->connection->commit());
self::assertEquals(2, $this->connection->getTransactionNestingLevel());
throw new Exception();
$this->connection->commit(); // never reached
} catch (Throwable $e) {
$this->connection->rollBack();
self::assertEquals(1, $this->connection->getTransactionNestingLevel());
//no rethrow
}
self::assertFalse($this->connection->isRollbackOnly());
try {
$this->connection->setNestTransactionsWithSavepoints(false);
......@@ -144,6 +150,7 @@ class ConnectionTest extends DbalFunctionalTestCase
} catch (ConnectionException $e) {
self::assertTrue($this->connection->getNestTransactionsWithSavepoints());
}
$this->connection->commit(); // should not throw exception
} catch (ConnectionException $e) {
$this->fail('Transaction commit after failed nested transaction should not fail when using savepoints.');
......@@ -246,6 +253,7 @@ class ConnectionTest extends DbalFunctionalTestCase
$this->connection->transactional(static function ($conn) : void {
/** @var Connection $conn */
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
throw new RuntimeException('Ooops!');
});
$this->fail('Expected exception');
......@@ -260,6 +268,7 @@ class ConnectionTest extends DbalFunctionalTestCase
$this->connection->transactional(static function ($conn) : void {
/** @var Connection $conn */
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
throw new Error('Ooops!');
});
$this->fail('Expected exception');
......
......@@ -19,11 +19,10 @@ use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\DbalFunctionalTestCase;
use PDO;
use const CASE_LOWER;
use const PHP_EOL;
use function array_change_key_case;
use function array_filter;
use function array_keys;
use function assert;
use function count;
use function date;
use function implode;
......@@ -32,6 +31,8 @@ use function json_encode;
use function property_exists;
use function sprintf;
use function strtotime;
use const CASE_LOWER;
use const PHP_EOL;
class DataAccessTest extends DbalFunctionalTestCase
{
......@@ -953,8 +954,8 @@ class DataAccessTest extends DbalFunctionalTestCase
return;
}
/** @var PDOConnection $connection */
$connection = $this->connection->getWrappedConnection();
assert($connection instanceof PDOConnection);
$connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
}
}
......
......@@ -24,25 +24,16 @@ class DB2DriverTest extends AbstractDriverTest
$this->markTestSkipped('ibm_db2 only test.');
}
/**
* {@inheritdoc}
*/
public function testConnectsWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('IBM DB2 does not support connecting without database name.');
}
/**
* {@inheritdoc}
*/
public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('IBM DB2 does not support connecting without database name.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : Driver
{
return new DB2Driver();
......
......@@ -6,8 +6,8 @@ use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\Tests\DbalFunctionalTestCase;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use function extension_loaded;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
class ConnectionTest extends DbalFunctionalTestCase
{
......
......@@ -24,9 +24,6 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('MySQLi only test.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
......@@ -24,25 +24,16 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('oci8 only test.');
}
/**
* {@inheritdoc}
*/
public function testConnectsWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('Oracle does not support connecting without database name.');
}
/**
* {@inheritdoc}
*/
public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('Oracle does not support connecting without database name.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
......@@ -24,9 +24,6 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('pdo_mysql only test.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
......@@ -24,25 +24,16 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('PDO_OCI only test.');
}
/**
* {@inheritdoc}
*/
public function testConnectsWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('Oracle does not support connecting without database name.');
}
/**
* {@inheritdoc}
*/
public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('Oracle does not support connecting without database name.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
......@@ -101,17 +101,11 @@ class DriverTest extends AbstractDriverTest
$this->fail(sprintf('Query result does not contain a record where column "query" equals "%s".', $sql));
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
}
/**
* {@inheritdoc}
*/
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return 'postgres';
......
......@@ -24,9 +24,6 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('pdo_sqlite only test.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
......@@ -26,17 +26,11 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('pdo_sqlsrv only test.');
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
}
/**
* {@inheritdoc}
*/
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return 'master';
......
......@@ -42,9 +42,6 @@ class DriverTest extends AbstractDriverTest
self::assertIsString($this->driver->getDatabase($connection));
}
/**
* {@inheritdoc}
*/
protected function createDriver() : DriverInterface
{
return new Driver();
......
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