Unverified Commit 663975d6 authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Add proper types to root Doctrine\DBAL namespace.

parent 77d3dfa3
......@@ -44,20 +44,16 @@ class Configuration
/**
* Gets the cache driver implementation that is used for query result caching.
*
* @return Cache|null
*/
public function getResultCacheImpl()
public function getResultCacheImpl() : ?Cache
{
return $this->_attributes['resultCacheImpl'] ?? null;
}
/**
* Sets the cache driver implementation that is used for query result caching.
*
* @return void
*/
public function setResultCacheImpl(Cache $cacheImpl)
public function setResultCacheImpl(Cache $cacheImpl) : void
{
$this->_attributes['resultCacheImpl'] = $cacheImpl;
}
......@@ -70,12 +66,8 @@ class Configuration
* {AbstractSchemaManager#createSchema()}.
*
* @deprecated Use Configuration::setSchemaAssetsFilter() instead
*
* @param string $filterExpression
*
* @return void
*/
public function setFilterSchemaAssetsExpression($filterExpression)
public function setFilterSchemaAssetsExpression(?string $filterExpression) : void
{
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
......@@ -85,17 +77,14 @@ class Configuration
}
}
/**
* @param string $filterExpression
*/
private function buildSchemaAssetsFilterFromExpression($filterExpression) : callable
private function buildSchemaAssetsFilterFromExpression(string $filterExpression) : callable
{
return static function ($assetName) use ($filterExpression) {
return static function ($assetName) use ($filterExpression) : bool {
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}
return preg_match($filterExpression, $assetName);
return preg_match($filterExpression, $assetName) > 0;
};
}
......@@ -128,9 +117,9 @@ class Configuration
*
* @param bool $autoCommit True to enable auto-commit mode; false to disable it.
*/
public function setAutoCommit($autoCommit)
public function setAutoCommit(bool $autoCommit) : void
{
$this->_attributes['autoCommit'] = (bool) $autoCommit;
$this->_attributes['autoCommit'] = $autoCommit;
}
/**
......@@ -140,7 +129,7 @@ class Configuration
*
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
*/
public function getAutoCommit()
public function getAutoCommit() : bool
{
return $this->_attributes['autoCommit'] ?? true;
}
......
......@@ -21,12 +21,9 @@ use function sprintf;
class DBALException extends Exception
{
/**
* @param string $sql
* @param mixed[] $params
*
* @return self
*/
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, string $sql, array $params = []) : self
{
$messageFormat = <<<'MESSAGE'
An exception occurred while executing "%s"%s:
......@@ -44,18 +41,12 @@ MESSAGE;
return static::wrapException($driver, $driverEx, $message);
}
/**
* @return self
*/
public static function driverException(Driver $driver, Throwable $driverEx)
public static function driverException(Driver $driver, Throwable $driverEx) : self
{
return static::wrapException($driver, $driverEx, sprintf('An exception occurred in driver with message: %s', $driverEx->getMessage()));
}
/**
* @return self
*/
private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
private static function wrapException(Driver $driver, Throwable $driverEx, string $msg) : self
{
if ($driverEx instanceof DriverException) {
return $driverEx;
......@@ -75,7 +66,7 @@ MESSAGE;
*/
private static function formatParameters(array $params) : string
{
return '[' . implode(', ', array_map(static function ($param) {
return '[' . implode(', ', array_map(static function ($param) : string {
if (is_resource($param)) {
return (string) $param;
}
......
......@@ -109,7 +109,7 @@ class SQLParserUtils
*
* @throws SQLParserUtilsException
*/
public static function expandListParameters($query, $params, $types)
public static function expandListParameters(string $query, array $params, array $types) : array
{
$isPositional = is_int(key($params));
$arrayPositions = [];
......@@ -225,11 +225,9 @@ class SQLParserUtils
* 0 => matched fragment string,
* 1 => offset of fragment in $statement
*
* @param string $statement
*
* @return mixed[][]
*/
private static function getUnquotedStatementFragments($statement)
private static function getUnquotedStatementFragments(string $statement) : array
{
$literal = self::ESCAPED_SINGLE_QUOTED_TEXT . '|' .
self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' .
......@@ -245,14 +243,13 @@ class SQLParserUtils
/**
* @param string $paramName The name of the parameter (without a colon in front)
* @param mixed $paramsOrTypes A hash of parameters or types
* @param bool $isParam
* @param mixed $defaultValue An optional default value. If omitted, an exception is thrown
*
* @return mixed
*
* @throws SQLParserUtilsException
*/
private static function extractParam($paramName, $paramsOrTypes, $isParam, $defaultValue = null)
private static function extractParam(string $paramName, $paramsOrTypes, bool $isParam, $defaultValue = null)
{
if (array_key_exists($paramName, $paramsOrTypes)) {
return $paramsOrTypes[$paramName];
......
......@@ -47,9 +47,5 @@ class ConfigurationTest extends DbalTestCase
$this->config->setAutoCommit(false);
self::assertFalse($this->config->getAutoCommit());
$this->config->setAutoCommit(0);
self::assertFalse($this->config->getAutoCommit());
}
}
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