Skip to content

Commit

Permalink
Enforce parameter and return value types in the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Nov 18, 2018
1 parent fa42c10 commit 16ef126
Show file tree
Hide file tree
Showing 371 changed files with 4,987 additions and 6,444 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/Doctrine/DBAL/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ public function __construct(array $data)
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
unset($this->data);
}

/**
* {@inheritdoc}
*/
public function columnCount()
public function columnCount() : int
{
return $this->columnCount;
}

/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode(int $fetchMode, ...$args) : bool
{
if (count($args) > 0) {
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
Expand All @@ -82,7 +82,7 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, ...$args)
public function fetch(?int $fetchMode = null, ...$args)
{
if (! isset($this->data[$this->num])) {
return false;
Expand Down Expand Up @@ -113,7 +113,7 @@ public function fetch($fetchMode = null, ...$args)
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, ...$args)
public function fetchAll(?int $fetchMode = null, ...$args) : array
{
$rows = [];
while ($row = $this->fetch($fetchMode, ...$args)) {
Expand All @@ -126,7 +126,7 @@ public function fetchAll($fetchMode = null, ...$args)
/**
* {@inheritdoc}
*/
public function fetchColumn($columnIndex = 0)
public function fetchColumn(int $columnIndex = 0)
{
$row = $this->fetch(FetchMode::NUMERIC);

Expand Down
10 changes: 2 additions & 8 deletions lib/Doctrine/DBAL/Cache/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@

class CacheException extends DBALException
{
/**
* @return \Doctrine\DBAL\Cache\CacheException
*/
public static function noCacheKey()
public static function noCacheKey() : self
{
return new self('No cache key was set.');
}

/**
* @return \Doctrine\DBAL\Cache\CacheException
*/
public static function noResultDriverConfigured()
public static function noResultDriverConfigured() : self
{
return new self('Trying to cache a query but no result driver is configured.');
}
Expand Down
42 changes: 8 additions & 34 deletions lib/Doctrine/DBAL/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,27 @@ class QueryCacheProfile
/** @var string|null */
private $cacheKey;

/**
* @param int $lifetime
* @param string|null $cacheKey
*/
public function __construct($lifetime = 0, $cacheKey = null, ?Cache $resultCache = null)
public function __construct(int $lifetime = 0, ?string $cacheKey = null, ?Cache $resultCache = null)
{
$this->lifetime = $lifetime;
$this->cacheKey = $cacheKey;
$this->resultCacheDriver = $resultCache;
}

/**
* @return Cache|null
*/
public function getResultCacheDriver()
public function getResultCacheDriver() : ?Cache
{
return $this->resultCacheDriver;
}

/**
* @return int
*/
public function getLifetime()
public function getLifetime() : int
{
return $this->lifetime;
}

/**
* @return string
*
* @throws CacheException
*/
public function getCacheKey()
public function getCacheKey() : string
{
if ($this->cacheKey === null) {
throw CacheException::noCacheKey();
Expand All @@ -67,14 +55,13 @@ public function getCacheKey()
/**
* Generates the real cache key from query, params, types and connection parameters.
*
* @param string $query
* @param mixed[] $params
* @param int[]|string[] $types
* @param mixed[] $connectionParams
*
* @return string[]
*/
public function generateCacheKeys($query, $params, $types, array $connectionParams = [])
public function generateCacheKeys(string $query, array $params, array $types, array $connectionParams = []) : array
{
$realCacheKey = 'query=' . $query .
'&params=' . serialize($params) .
Expand All @@ -91,30 +78,17 @@ public function generateCacheKeys($query, $params, $types, array $connectionPara
return [$cacheKey, $realCacheKey];
}

/**
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setResultCacheDriver(Cache $cache)
public function setResultCacheDriver(Cache $cache) : self
{
return new QueryCacheProfile($this->lifetime, $this->cacheKey, $cache);
}

/**
* @param string|null $cacheKey
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setCacheKey($cacheKey)
public function setCacheKey(?string $cacheKey) : self
{
return new QueryCacheProfile($this->lifetime, $cacheKey, $this->resultCacheDriver);
}

/**
* @param int $lifetime
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setLifetime($lifetime)
public function setLifetime(int $lifetime) : self
{
return new QueryCacheProfile($lifetime, $this->cacheKey, $this->resultCacheDriver);
}
Expand Down
23 changes: 8 additions & 15 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;

/**
* @param string $cacheKey
* @param string $realKey
* @param int $lifetime
*/
public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime)
public function __construct(Statement $stmt, Cache $resultCache, string $cacheKey, string $realKey, int $lifetime)
{
$this->statement = $stmt;
$this->resultCache = $resultCache;
Expand All @@ -73,11 +68,11 @@ public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $rea
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
$this->statement->closeCursor();
if (! $this->emptied || $this->data === null) {
return true;
return;
}

$data = $this->resultCache->fetch($this->cacheKey);
Expand All @@ -88,22 +83,20 @@ public function closeCursor()

$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
unset($this->data);

return true;
}

/**
* {@inheritdoc}
*/
public function columnCount()
public function columnCount() : int
{
return $this->statement->columnCount();
}

/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode(int $fetchMode, ...$args) : bool
{
$this->defaultFetchMode = $fetchMode;

Expand All @@ -123,7 +116,7 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, ...$args)
public function fetch(?int $fetchMode = null, ...$args)
{
if ($this->data === null) {
$this->data = [];
Expand Down Expand Up @@ -163,15 +156,15 @@ public function fetch($fetchMode = null, ...$args)
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, ...$args)
public function fetchAll(?int $fetchMode = null, ...$args) : array
{
return $this->statement->fetchAll($fetchMode, ...$args);
}

/**
* {@inheritdoc}
*/
public function fetchColumn($columnIndex = 0)
public function fetchColumn(int $columnIndex = 0)
{
$row = $this->fetch(FetchMode::NUMERIC);

Expand Down
34 changes: 12 additions & 22 deletions lib/Doctrine/DBAL/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,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 @@ -68,12 +64,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 @@ -87,20 +79,18 @@ public function setFilterSchemaAssetsExpression($filterExpression)
* Returns filter schema assets expression.
*
* @deprecated Use Configuration::getSchemaAssetsFilter() instead
*
* @return string|null
*/
public function getFilterSchemaAssetsExpression()
public function getFilterSchemaAssetsExpression() : ?string
{
return $this->_attributes['filterSchemaAssetsExpression'] ?? null;
}

/**
* @param string $filterExpression
*/
private function buildSchemaAssetsFilterFromExpression($filterExpression) : callable
private function buildSchemaAssetsFilterFromExpression(string $filterExpression) : callable
{
return static function ($assetName) use ($filterExpression) {
return /**
* @return int|false
*/
static function ($assetName) use ($filterExpression) {
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}
Expand Down Expand Up @@ -132,11 +122,11 @@ 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;
}
Expand All @@ -148,7 +138,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
Loading

0 comments on commit 16ef126

Please sign in to comment.