Skip to content

Commit 234edec

Browse files
committed
Enforce parameter and return value types in the codebase
1 parent ffeeb00 commit 234edec

File tree

371 files changed

+4975
-6362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

371 files changed

+4975
-6362
lines changed

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ public function __construct(array $data)
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function closeCursor()
47+
public function closeCursor() : void
4848
{
4949
unset($this->data);
5050
}
5151

5252
/**
5353
* {@inheritdoc}
5454
*/
55-
public function columnCount()
55+
public function columnCount() : int
5656
{
5757
return $this->columnCount;
5858
}
5959

6060
/**
6161
* {@inheritdoc}
6262
*/
63-
public function setFetchMode($fetchMode, ...$args)
63+
public function setFetchMode(int $fetchMode, ...$args) : bool
6464
{
6565
if (count($args) > 0) {
6666
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
@@ -84,7 +84,7 @@ public function getIterator()
8484
/**
8585
* {@inheritdoc}
8686
*/
87-
public function fetch($fetchMode = null, ...$args)
87+
public function fetch(?int $fetchMode = null, ...$args)
8888
{
8989
if (! isset($this->data[$this->num])) {
9090
return false;
@@ -115,7 +115,7 @@ public function fetch($fetchMode = null, ...$args)
115115
/**
116116
* {@inheritdoc}
117117
*/
118-
public function fetchAll($fetchMode = null, ...$args)
118+
public function fetchAll(?int $fetchMode = null, ...$args) : array
119119
{
120120
$rows = [];
121121
while ($row = $this->fetch($fetchMode, ...$args)) {
@@ -128,7 +128,7 @@ public function fetchAll($fetchMode = null, ...$args)
128128
/**
129129
* {@inheritdoc}
130130
*/
131-
public function fetchColumn($columnIndex = 0)
131+
public function fetchColumn(int $columnIndex = 0)
132132
{
133133
$row = $this->fetch(FetchMode::NUMERIC);
134134

lib/Doctrine/DBAL/Cache/CacheException.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66

77
class CacheException extends DBALException
88
{
9-
/**
10-
* @return \Doctrine\DBAL\Cache\CacheException
11-
*/
12-
public static function noCacheKey()
9+
public static function noCacheKey() : self
1310
{
1411
return new self('No cache key was set.');
1512
}
1613

17-
/**
18-
* @return \Doctrine\DBAL\Cache\CacheException
19-
*/
20-
public static function noResultDriverConfigured()
14+
public static function noResultDriverConfigured() : self
2115
{
2216
return new self('Trying to cache a query but no result driver is configured.');
2317
}

lib/Doctrine/DBAL/Cache/QueryCacheProfile.php

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,27 @@ class QueryCacheProfile
2323
/** @var string|null */
2424
private $cacheKey;
2525

26-
/**
27-
* @param int $lifetime
28-
* @param string|null $cacheKey
29-
*/
30-
public function __construct($lifetime = 0, $cacheKey = null, ?Cache $resultCache = null)
26+
public function __construct(int $lifetime = 0, ?string $cacheKey = null, ?Cache $resultCache = null)
3127
{
3228
$this->lifetime = $lifetime;
3329
$this->cacheKey = $cacheKey;
3430
$this->resultCacheDriver = $resultCache;
3531
}
3632

37-
/**
38-
* @return Cache|null
39-
*/
40-
public function getResultCacheDriver()
33+
public function getResultCacheDriver() : ?Cache
4134
{
4235
return $this->resultCacheDriver;
4336
}
4437

45-
/**
46-
* @return int
47-
*/
48-
public function getLifetime()
38+
public function getLifetime() : int
4939
{
5040
return $this->lifetime;
5141
}
5242

5343
/**
54-
* @return string
55-
*
5644
* @throws CacheException
5745
*/
58-
public function getCacheKey()
46+
public function getCacheKey() : string
5947
{
6048
if ($this->cacheKey === null) {
6149
throw CacheException::noCacheKey();
@@ -67,14 +55,13 @@ public function getCacheKey()
6755
/**
6856
* Generates the real cache key from query, params, types and connection parameters.
6957
*
70-
* @param string $query
7158
* @param mixed[] $params
7259
* @param int[]|string[] $types
7360
* @param mixed[] $connectionParams
7461
*
7562
* @return string[]
7663
*/
77-
public function generateCacheKeys($query, $params, $types, array $connectionParams = [])
64+
public function generateCacheKeys(string $query, array $params, array $types, array $connectionParams = []) : array
7865
{
7966
$realCacheKey = 'query=' . $query .
8067
'&params=' . serialize($params) .
@@ -91,30 +78,17 @@ public function generateCacheKeys($query, $params, $types, array $connectionPara
9178
return [$cacheKey, $realCacheKey];
9279
}
9380

94-
/**
95-
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
96-
*/
97-
public function setResultCacheDriver(Cache $cache)
81+
public function setResultCacheDriver(Cache $cache) : self
9882
{
9983
return new QueryCacheProfile($this->lifetime, $this->cacheKey, $cache);
10084
}
10185

102-
/**
103-
* @param string|null $cacheKey
104-
*
105-
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
106-
*/
107-
public function setCacheKey($cacheKey)
86+
public function setCacheKey(?string $cacheKey) : self
10887
{
10988
return new QueryCacheProfile($this->lifetime, $cacheKey, $this->resultCacheDriver);
11089
}
11190

112-
/**
113-
* @param int $lifetime
114-
*
115-
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
116-
*/
117-
public function setLifetime($lifetime)
91+
public function setLifetime(int $lifetime) : self
11892
{
11993
return new QueryCacheProfile($lifetime, $this->cacheKey, $this->resultCacheDriver);
12094
}

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
6060
/** @var int */
6161
private $defaultFetchMode = FetchMode::MIXED;
6262

63-
/**
64-
* @param string $cacheKey
65-
* @param string $realKey
66-
* @param int $lifetime
67-
*/
68-
public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime)
63+
public function __construct(ResultStatement $stmt, Cache $resultCache, string $cacheKey, string $realKey, int $lifetime)
6964
{
7065
$this->statement = $stmt;
7166
$this->resultCache = $resultCache;
@@ -77,11 +72,11 @@ public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey
7772
/**
7873
* {@inheritdoc}
7974
*/
80-
public function closeCursor()
75+
public function closeCursor() : void
8176
{
8277
$this->statement->closeCursor();
8378
if (! $this->emptied || $this->data === null) {
84-
return true;
79+
return;
8580
}
8681

8782
$data = $this->resultCache->fetch($this->cacheKey);
@@ -92,22 +87,20 @@ public function closeCursor()
9287

9388
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
9489
unset($this->data);
95-
96-
return true;
9790
}
9891

9992
/**
10093
* {@inheritdoc}
10194
*/
102-
public function columnCount()
95+
public function columnCount() : int
10396
{
10497
return $this->statement->columnCount();
10598
}
10699

107100
/**
108101
* {@inheritdoc}
109102
*/
110-
public function setFetchMode($fetchMode, ...$args)
103+
public function setFetchMode(int $fetchMode, ...$args) : bool
111104
{
112105
$this->defaultFetchMode = $fetchMode;
113106

@@ -127,7 +120,7 @@ public function getIterator()
127120
/**
128121
* {@inheritdoc}
129122
*/
130-
public function fetch($fetchMode = null, ...$args)
123+
public function fetch(?int $fetchMode = null, ...$args)
131124
{
132125
if ($this->data === null) {
133126
$this->data = [];
@@ -167,7 +160,7 @@ public function fetch($fetchMode = null, ...$args)
167160
/**
168161
* {@inheritdoc}
169162
*/
170-
public function fetchAll($fetchMode = null, ...$args)
163+
public function fetchAll(?int $fetchMode = null, ...$args) : array
171164
{
172165
$this->data = $this->statement->fetchAll($fetchMode, ...$args);
173166
$this->emptied = true;
@@ -178,7 +171,7 @@ public function fetchAll($fetchMode = null, ...$args)
178171
/**
179172
* {@inheritdoc}
180173
*/
181-
public function fetchColumn($columnIndex = 0)
174+
public function fetchColumn(int $columnIndex = 0)
182175
{
183176
$row = $this->fetch(FetchMode::NUMERIC);
184177

lib/Doctrine/DBAL/Configuration.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,16 @@ public function getSQLLogger() : SQLLogger
4242

4343
/**
4444
* Gets the cache driver implementation that is used for query result caching.
45-
*
46-
* @return Cache|null
4745
*/
48-
public function getResultCacheImpl()
46+
public function getResultCacheImpl() : ?Cache
4947
{
5048
return $this->_attributes['resultCacheImpl'] ?? null;
5149
}
5250

5351
/**
5452
* Sets the cache driver implementation that is used for query result caching.
55-
*
56-
* @return void
5753
*/
58-
public function setResultCacheImpl(Cache $cacheImpl)
54+
public function setResultCacheImpl(Cache $cacheImpl) : void
5955
{
6056
$this->_attributes['resultCacheImpl'] = $cacheImpl;
6157
}
@@ -68,12 +64,8 @@ public function setResultCacheImpl(Cache $cacheImpl)
6864
* {AbstractSchemaManager#createSchema()}.
6965
*
7066
* @deprecated Use Configuration::setSchemaAssetsFilter() instead
71-
*
72-
* @param string $filterExpression
73-
*
74-
* @return void
7567
*/
76-
public function setFilterSchemaAssetsExpression($filterExpression)
68+
public function setFilterSchemaAssetsExpression(?string $filterExpression) : void
7769
{
7870
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
7971
if ($filterExpression) {
@@ -87,20 +79,18 @@ public function setFilterSchemaAssetsExpression($filterExpression)
8779
* Returns filter schema assets expression.
8880
*
8981
* @deprecated Use Configuration::getSchemaAssetsFilter() instead
90-
*
91-
* @return string|null
9282
*/
93-
public function getFilterSchemaAssetsExpression()
83+
public function getFilterSchemaAssetsExpression() : ?string
9484
{
9585
return $this->_attributes['filterSchemaAssetsExpression'] ?? null;
9686
}
9787

98-
/**
99-
* @param string $filterExpression
100-
*/
101-
private function buildSchemaAssetsFilterFromExpression($filterExpression) : callable
88+
private function buildSchemaAssetsFilterFromExpression(string $filterExpression) : callable
10289
{
103-
return static function ($assetName) use ($filterExpression) {
90+
return /**
91+
* @return int|false
92+
*/
93+
static function ($assetName) use ($filterExpression) {
10494
if ($assetName instanceof AbstractAsset) {
10595
$assetName = $assetName->getName();
10696
}
@@ -132,13 +122,13 @@ public function getSchemaAssetsFilter() : ?callable
132122
* transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
133123
* the method commit or the method rollback. By default, new connections are in auto-commit mode.
134124
*
135-
* @see getAutoCommit
125+
* @see getAutoCommit
136126
*
137127
* @param bool $autoCommit True to enable auto-commit mode; false to disable it.
138128
*/
139-
public function setAutoCommit($autoCommit)
129+
public function setAutoCommit(bool $autoCommit) : void
140130
{
141-
$this->_attributes['autoCommit'] = (bool) $autoCommit;
131+
$this->_attributes['autoCommit'] = $autoCommit;
142132
}
143133

144134
/**
@@ -148,7 +138,7 @@ public function setAutoCommit($autoCommit)
148138
*
149139
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
150140
*/
151-
public function getAutoCommit()
141+
public function getAutoCommit() : bool
152142
{
153143
return $this->_attributes['autoCommit'] ?? true;
154144
}

0 commit comments

Comments
 (0)