Skip to content

Commit

Permalink
Merge pull request #3576 from jwage/types-root-namespace
Browse files Browse the repository at this point in the history
Add proper types to root Doctrine\DBAL namespace.
  • Loading branch information
morozov committed Jun 13, 2019
2 parents b12966c + aba1c76 commit 96d6ce4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 44 deletions.
31 changes: 10 additions & 21 deletions lib/Doctrine/DBAL/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,16 @@ public function getSQLLogger() : SQLLogger

/**
* 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;
}
Expand All @@ -70,12 +66,8 @@ public function setResultCacheImpl(Cache $cacheImpl)
* {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) {
Expand All @@ -85,17 +77,14 @@ public function setFilterSchemaAssetsExpression($filterExpression)
}
}

/**
* @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;
};
}

Expand Down Expand Up @@ -124,13 +113,13 @@ public function getSchemaAssetsFilter() : ?callable
* transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
* the method commit or the method rollback. By default, new connections are in auto-commit mode.
*
* @see getAutoCommit
* @see getAutoCommit
*
* @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;
}

/**
Expand All @@ -140,7 +129,7 @@ public function setAutoCommit($autoCommit)
*
* @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;
}
Expand Down
17 changes: 4 additions & 13 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
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:
Expand All @@ -44,18 +41,12 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri
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;
Expand All @@ -75,7 +66,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
*/
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;
}
Expand Down
9 changes: 3 additions & 6 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static function collectPlaceholders(string $statement, string $match, st
*
* @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 = [];
Expand Down Expand Up @@ -225,11 +225,9 @@ public static function expandListParameters($query, $params, $types)
* 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 . '|' .
Expand All @@ -245,14 +243,13 @@ private static function getUnquotedStatementFragments($statement)
/**
* @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];
Expand Down
4 changes: 0 additions & 4 deletions tests/Doctrine/Tests/DBAL/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,5 @@ public function testSetsDefaultConnectionAutoCommitMode() : void
$this->config->setAutoCommit(false);

self::assertFalse($this->config->getAutoCommit());

$this->config->setAutoCommit(0);

self::assertFalse($this->config->getAutoCommit());
}
}

0 comments on commit 96d6ce4

Please sign in to comment.