From aba1c768f702f93f59b25beb1acc0249cb1cf598 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Thu, 30 May 2019 16:53:19 -0500 Subject: [PATCH] Add proper types to root Doctrine\DBAL namespace. --- lib/Doctrine/DBAL/Configuration.php | 31 ++++++------------- lib/Doctrine/DBAL/DBALException.php | 17 +++------- lib/Doctrine/DBAL/SQLParserUtils.php | 9 ++---- .../Doctrine/Tests/DBAL/ConfigurationTest.php | 4 --- 4 files changed, 17 insertions(+), 44 deletions(-) diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 9fe9382b89f..796c39162f3 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -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; } @@ -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) { @@ -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; }; } @@ -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; } /** @@ -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; } diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 26bb81923b7..65141360304 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -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: @@ -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; @@ -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; } diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index a9af7b70ec0..fb67e4e843e 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -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 = []; @@ -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 . '|' . @@ -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]; diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 6eba08b88f8..6b41901d254 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -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()); } }