Skip to content

Commit 90d57e0

Browse files
committed
PHPStan Level 5
1 parent 9b88bf3 commit 90d57e0

15 files changed

+45
-33
lines changed

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PDO;
1313
use function array_merge;
1414
use function array_values;
15+
use function assert;
1516
use function reset;
1617

1718
/**
@@ -41,7 +42,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
4142
/** @var int */
4243
private $lifetime;
4344

44-
/** @var Statement */
45+
/** @var ResultStatement */
4546
private $statement;
4647

4748
/**
@@ -62,7 +63,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
6263
* @param string $realKey
6364
* @param int $lifetime
6465
*/
65-
public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime)
66+
public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime)
6667
{
6768
$this->statement = $stmt;
6869
$this->resultCache = $resultCache;
@@ -196,6 +197,8 @@ public function fetchColumn($columnIndex = 0)
196197
*/
197198
public function rowCount()
198199
{
200+
assert($this->statement instanceof Statement);
201+
199202
return $this->statement->rowCount();
200203
}
201204
}

lib/Doctrine/DBAL/DBALException.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ public static function unknownDriver($unknownDriverName, array $knownDrivers)
128128
}
129129

130130
/**
131-
* @param Exception $driverEx
132131
* @param string $sql
133132
* @param mixed[] $params
134133
*
135-
* @return \Doctrine\DBAL\DBALException
134+
* @return self
136135
*/
137136
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
138137
{
@@ -146,19 +145,15 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri
146145
}
147146

148147
/**
149-
* @param Exception $driverEx
150-
*
151-
* @return \Doctrine\DBAL\DBALException
148+
* @return self
152149
*/
153150
public static function driverException(Driver $driver, Throwable $driverEx)
154151
{
155152
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
156153
}
157154

158155
/**
159-
* @param Exception $driverEx
160-
*
161-
* @return \Doctrine\DBAL\DBALException
156+
* @return self
162157
*/
163158
private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
164159
{

lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private static function findClosingQuote(
240240
* where the token was found.
241241
*
242242
* @param string $statement The SQL statement to parse
243-
* @param string $offset The offset to start searching from
243+
* @param int $offset The offset to start searching from
244244
* @param string $regex The regex containing token pattern
245245
*
246246
* @return string|null Token or NULL if not found

lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Doctrine\DBAL\Event;
44

55
use Doctrine\DBAL\Platforms\AbstractPlatform;
6-
use Doctrine\DBAL\Schema\Column;
76
use Doctrine\DBAL\Schema\Table;
87
use function array_merge;
98
use function is_array;
@@ -16,7 +15,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
1615
/** @var Table */
1716
private $table;
1817

19-
/** @var Column[] */
18+
/** @var mixed[][] */
2019
private $columns;
2120

2221
/** @var mixed[] */
@@ -29,8 +28,8 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
2928
private $sql = [];
3029

3130
/**
32-
* @param Column[] $columns
33-
* @param mixed[] $options
31+
* @param mixed[][] $columns
32+
* @param mixed[] $options
3433
*/
3534
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
3635
{
@@ -49,7 +48,7 @@ public function getTable()
4948
}
5049

5150
/**
52-
* @return Column[]
51+
* @return mixed[][]
5352
*/
5453
public function getColumns()
5554
{

lib/Doctrine/DBAL/Portability/Statement.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Doctrine\DBAL\Portability;
44

5+
use Doctrine\DBAL\Driver\ResultStatement;
56
use Doctrine\DBAL\Driver\Statement as DriverStatement;
67
use Doctrine\DBAL\Driver\StatementIterator;
78
use Doctrine\DBAL\FetchMode;
89
use Doctrine\DBAL\ParameterType;
910
use IteratorAggregate;
1011
use PDO;
1112
use function array_change_key_case;
13+
use function assert;
1214
use function is_string;
1315
use function rtrim;
1416

@@ -20,7 +22,7 @@ class Statement implements IteratorAggregate, DriverStatement
2022
/** @var int */
2123
private $portability;
2224

23-
/** @var DriverStatement */
25+
/** @var DriverStatement|ResultStatement */
2426
private $stmt;
2527

2628
/** @var int */
@@ -32,7 +34,7 @@ class Statement implements IteratorAggregate, DriverStatement
3234
/**
3335
* Wraps <tt>Statement</tt> and applies portability measures.
3436
*
35-
* @param DriverStatement $stmt
37+
* @param DriverStatement|ResultStatement $stmt
3638
*/
3739
public function __construct($stmt, Connection $conn)
3840
{
@@ -46,6 +48,8 @@ public function __construct($stmt, Connection $conn)
4648
*/
4749
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
4850
{
51+
assert($this->stmt instanceof DriverStatement);
52+
4953
return $this->stmt->bindParam($column, $variable, $type, $length);
5054
}
5155

@@ -54,6 +58,8 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
5458
*/
5559
public function bindValue($param, $value, $type = ParameterType::STRING)
5660
{
61+
assert($this->stmt instanceof DriverStatement);
62+
5763
return $this->stmt->bindValue($param, $value, $type);
5864
}
5965

@@ -78,6 +84,8 @@ public function columnCount()
7884
*/
7985
public function errorCode()
8086
{
87+
assert($this->stmt instanceof DriverStatement);
88+
8189
return $this->stmt->errorCode();
8290
}
8391

@@ -86,6 +94,8 @@ public function errorCode()
8694
*/
8795
public function errorInfo()
8896
{
97+
assert($this->stmt instanceof DriverStatement);
98+
8999
return $this->stmt->errorInfo();
90100
}
91101

@@ -94,6 +104,8 @@ public function errorInfo()
94104
*/
95105
public function execute($params = null)
96106
{
107+
assert($this->stmt instanceof DriverStatement);
108+
97109
return $this->stmt->execute($params);
98110
}
99111

@@ -228,6 +240,8 @@ public function fetchColumn($columnIndex = 0)
228240
*/
229241
public function rowCount()
230242
{
243+
assert($this->stmt instanceof DriverStatement);
244+
231245
return $this->stmt->rowCount();
232246
}
233247
}

lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ public function notIn($x, $y)
286286
/**
287287
* Quotes a given input parameter.
288288
*
289-
* @param mixed $input The parameter to be quoted.
290-
* @param string|null $type The type of the parameter.
289+
* @param mixed $input The parameter to be quoted.
290+
* @param int|null $type The type of the parameter.
291291
*
292292
* @return string
293293
*/

lib/Doctrine/DBAL/SQLParserUtils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class SQLParserUtils
3636
/**
3737
* Gets an array of the placeholders in an sql statements as keys and their positions in the query string.
3838
*
39-
* Returns an integer => integer pair (indexed from zero) for a positional statement
40-
* and a string => int[] pair for a named statement.
39+
* For a statement with positional parameters, returns a zero-indexed list of placeholder position.
40+
* For a statement with named parameters, returns a map of placeholder positions to their parameter names.
4141
*
4242
* @param string $statement
4343
* @param bool $isPositional
4444
*
45-
* @return int[]
45+
* @return int[]|string[]
4646
*/
4747
public static function getPlaceholderPositions($statement, $isPositional = true)
4848
{

lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function listTableDetails($tableName)
268268
}
269269
$indexes = $this->listTableIndexes($tableName);
270270

271-
return new Table($tableName, $columns, $indexes, $foreignKeys, false, []);
271+
return new Table($tableName, $columns, $indexes, $foreignKeys);
272272
}
273273

274274
/**

lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected function getPortableNamespaceDefinition(array $namespace)
216216
protected function _getPortableViewDefinition($view)
217217
{
218218
// @todo
219-
return new View($view['name'], null);
219+
return new View($view['name'], '');
220220
}
221221

222222
/**

lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns)
283283
continue;
284284
}
285285

286-
$type = $this->extractDoctrineTypeFromComment($comment, null);
286+
$type = $this->extractDoctrineTypeFromComment($comment, '');
287287

288-
if ($type !== null) {
288+
if ($type !== '') {
289289
$column->setType(Type::getType($type));
290290

291291
$comment = $this->removeDoctrineTypeFromComment($comment, $type);

lib/Doctrine/DBAL/Schema/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public function addNamedForeignKeyConstraint($name, $foreignTable, array $localC
425425

426426
/**
427427
* @param string $name
428-
* @param string $value
428+
* @param mixed $value
429429
*
430430
* @return self
431431
*/

lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ public function getQueries()
7878
{
7979
$sql = [];
8080

81+
/** @var ForeignKeyConstraint $fkConstraint */
8182
foreach ($this->constraints as $fkConstraint) {
8283
$localTable = $this->constraints[$fkConstraint];
8384
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
8485
}
8586

87+
/** @var Sequence $sequence */
8688
foreach ($this->sequences as $sequence) {
8789
$sql[] = $this->platform->getDropSequenceSQL($sequence);
8890
}
8991

92+
/** @var Table $table */
9093
foreach ($this->tables as $table) {
9194
$sql[] = $this->platform->getDropTableSQL($table);
9295
}

lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use function current;
99
use function file_put_contents;
1010
use function in_array;
11-
use function mt_rand;
12-
use function sha1;
1311
use function strtolower;
1412

1513
/**
@@ -41,7 +39,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons
4139
*/
4240
public function acceptSchema(Schema $schema)
4341
{
44-
$this->output = 'digraph "' . sha1(mt_rand()) . '" {' . "\n";
42+
$this->output = 'digraph {' . "\n";
4543
$this->output .= 'splines = true;' . "\n";
4644
$this->output .= 'overlap = false;' . "\n";
4745
$this->output .= 'outputorder=edgesfirst;' . "\n";

lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function connect($shardId = null)
205205
/**
206206
* Connects to a specific connection.
207207
*
208-
* @param string $shardId
208+
* @param string|int $shardId
209209
*
210210
* @return \Doctrine\DBAL\Driver\Connection
211211
*/

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 4
2+
level: 5
33
paths:
44
- %currentWorkingDirectory%/lib
55
autoload_files:

0 commit comments

Comments
 (0)