Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Narrow down driver return types #4926

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Driver/AbstractDB2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\IBMDB2\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\DB2SchemaManager;
use Doctrine\DBAL\ServerVersionProvider;

Expand All @@ -21,19 +19,19 @@
*/
abstract class AbstractDB2Driver implements Driver
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): DB2Platform
{
return new DB2Platform();
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): DB2SchemaManager
{
assert($platform instanceof DB2Platform);

return new DB2SchemaManager($conn, $platform);
}

public function getExceptionConverter(): ExceptionConverterInterface
public function getExceptionConverter(): ExceptionConverter
{
return new ExceptionConverter();
}
Expand Down
17 changes: 4 additions & 13 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\MySQL;
use Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\MySQLSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;

Expand All @@ -32,11 +30,9 @@ abstract class AbstractMySQLDriver implements Driver
/**
* {@inheritdoc}
*
* @return MySQLPlatform
*
* @throws Exception
*/
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): MySQLPlatform
{
$version = $versionProvider->getServerVersion();
$mariadb = stripos($version, 'mariadb') !== false;
Expand Down Expand Up @@ -118,12 +114,7 @@ private function getMariaDbMysqlVersionNumber(string $versionString): string
return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
}

/**
* {@inheritdoc}
*
* @return MySQLSchemaManager
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): MySQLSchemaManager
{
assert($platform instanceof MySQLPlatform);

Expand All @@ -132,6 +123,6 @@ public function getSchemaManager(Connection $conn, AbstractPlatform $platform):

public function getExceptionConverter(): ExceptionConverter
{
return new MySQL\ExceptionConverter();
return new ExceptionConverter();
}
}
10 changes: 4 additions & 6 deletions src/Driver/AbstractOracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\OCI;
use Doctrine\DBAL\Driver\API\OCI\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\OracleSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;

Expand All @@ -22,12 +20,12 @@
*/
abstract class AbstractOracleDriver implements Driver
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): OraclePlatform
{
return new OraclePlatform();
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): OracleSchemaManager
{
assert($platform instanceof OraclePlatform);

Expand All @@ -36,7 +34,7 @@ public function getSchemaManager(Connection $conn, AbstractPlatform $platform):

public function getExceptionConverter(): ExceptionConverter
{
return new OCI\ExceptionConverter();
return new ExceptionConverter();
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Driver/AbstractPostgreSQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\PostgreSQL;
use Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\PostgreSQLSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;

Expand All @@ -25,7 +23,7 @@
*/
abstract class AbstractPostgreSQLDriver implements Driver
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): PostgreSQLPlatform
{
$version = $versionProvider->getServerVersion();

Expand All @@ -48,7 +46,7 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
return new PostgreSQLPlatform();
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): PostgreSQLSchemaManager
{
assert($platform instanceof PostgreSQLPlatform);

Expand All @@ -57,6 +55,6 @@ public function getSchemaManager(Connection $conn, AbstractPlatform $platform):

public function getExceptionConverter(): ExceptionConverter
{
return new PostgreSQL\ExceptionConverter();
return new ExceptionConverter();
}
}
8 changes: 3 additions & 5 deletions src/Driver/AbstractSQLServerDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
use Doctrine\DBAL\Driver\API\SQLSrv\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;

Expand All @@ -21,19 +19,19 @@
*/
abstract class AbstractSQLServerDriver implements Driver
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): SQLServerPlatform
{
return new SQLServerPlatform();
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): SQLServerSchemaManager
{
assert($platform instanceof SQLServerPlatform);

return new SQLServerSchemaManager($conn, $platform);
}

public function getExceptionConverter(): ExceptionConverterInterface
public function getExceptionConverter(): ExceptionConverter
{
return new ExceptionConverter();
}
Expand Down
10 changes: 4 additions & 6 deletions src/Driver/AbstractSQLiteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\SQLite;
use Doctrine\DBAL\Driver\API\SQLite\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\SqliteSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;

Expand All @@ -21,12 +19,12 @@
*/
abstract class AbstractSQLiteDriver implements Driver
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): SqlitePlatform
{
return new SqlitePlatform();
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): SqliteSchemaManager
{
assert($platform instanceof SqlitePlatform);

Expand All @@ -35,6 +33,6 @@ public function getSchemaManager(Connection $conn, AbstractPlatform $platform):

public function getExceptionConverter(): ExceptionConverter
{
return new SQLite\ExceptionConverter();
return new ExceptionConverter();
}
}
6 changes: 2 additions & 4 deletions src/Driver/IBMDB2/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionError;
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use stdClass;

use function assert;
Expand Down Expand Up @@ -70,7 +68,7 @@ public function getServerVersion(): string
return $serverInfo->DBMS_VER;
}

public function prepare(string $sql): DriverStatement
public function prepare(string $sql): Statement
{
$stmt = @db2_prepare($this->conn, $sql);

Expand All @@ -81,7 +79,7 @@ public function prepare(string $sql): DriverStatement
return new Statement($stmt);
}

public function query(string $sql): ResultInterface
public function query(string $sql): Result
{
return $this->prepare($sql)->execute();
}
Expand Down
5 changes: 1 addition & 4 deletions src/Driver/IBMDB2/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
namespace Doctrine\DBAL\Driver\IBMDB2;

use Doctrine\DBAL\Driver\AbstractDB2Driver;
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;

final class Driver extends AbstractDB2Driver
{
/**
* {@inheritdoc}
*
* @return Connection
*/
public function connect(array $params): ConnectionInterface
public function connect(array $params): Connection
{
return new Connection(
DataSourceName::fromConnectionParameters($params)->toString(),
Expand Down
3 changes: 1 addition & 2 deletions src/Driver/IBMDB2/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCreateTemporaryFile;
use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotWriteToTemporaryFile;
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;

Expand Down Expand Up @@ -115,7 +114,7 @@ private function bind(int $position, &$variable, int $parameterType, int $dataTy
}
}

public function execute(?array $params = null): ResultInterface
public function execute(?array $params = null): Result
{
if ($params === null) {
ksort($this->bindParam);
Expand Down
6 changes: 2 additions & 4 deletions src/Driver/Mysqli/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionError;
use Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use mysqli;
use mysqli_sql_exception;

Expand Down Expand Up @@ -102,7 +100,7 @@ public function getServerVersion(): string
return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
}

public function prepare(string $sql): DriverStatement
public function prepare(string $sql): Statement
{
try {
$stmt = $this->conn->prepare($sql);
Expand All @@ -117,7 +115,7 @@ public function prepare(string $sql): DriverStatement
return new Statement($stmt);
}

public function query(string $sql): ResultInterface
public function query(string $sql): Result
{
return $this->prepare($sql)->execute();
}
Expand Down
5 changes: 1 addition & 4 deletions src/Driver/Mysqli/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\DBAL\Driver\Mysqli;

use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\Mysqli\Exception\HostRequired;
use Doctrine\DBAL\Driver\Mysqli\Initializer\Charset;
use Doctrine\DBAL\Driver\Mysqli\Initializer\Options;
Expand All @@ -17,10 +16,8 @@ final class Driver extends AbstractMySQLDriver
{
/**
* {@inheritdoc}
*
* @return Connection
*/
public function connect(array $params): ConnectionInterface
public function connect(array $params): Connection
{
if (! empty($params['persistent'])) {
if (! isset($params['host'])) {
Expand Down
3 changes: 1 addition & 2 deletions src/Driver/Mysqli/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Driver\Mysqli\Exception\FailedReadingStreamOffset;
use Doctrine\DBAL\Driver\Mysqli\Exception\NonStreamResourceUsedAsLargeObject;
use Doctrine\DBAL\Driver\Mysqli\Exception\StatementError;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use mysqli_sql_exception;
Expand Down Expand Up @@ -96,7 +95,7 @@ public function bindValue($param, $value, int $type = ParameterType::STRING): vo
$this->types[$param - 1] = self::$paramTypeMap[$type];
}

public function execute(?array $params = null): ResultInterface
public function execute(?array $params = null): Result
{
if ($params !== null && count($params) > 0) {
$this->bindUntypedValues($params);
Expand Down
6 changes: 2 additions & 4 deletions src/Driver/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Doctrine\DBAL\Driver\Exception\IdentityColumnsNotSupported;
use Doctrine\DBAL\Driver\OCI8\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\OCI8\Exception\Error;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as DriverStatement;

use function addcslashes;
use function assert;
Expand Down Expand Up @@ -74,12 +72,12 @@ public function getServerVersion(): string
return $matches[1];
}

public function prepare(string $sql): DriverStatement
public function prepare(string $sql): Statement
{
return new Statement($this->connection, $sql, $this->executionMode);
}

public function query(string $sql): ResultInterface
public function query(string $sql): Result
{
return $this->prepare($sql)->execute();
}
Expand Down
Loading