Unverified Commit 94cec711 authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #3436 from morozov/phpstan-lvl5

PHPStan Level 5
parents 9b88bf37 5600b867
...@@ -12,6 +12,7 @@ use IteratorAggregate; ...@@ -12,6 +12,7 @@ use IteratorAggregate;
use PDO; use PDO;
use function array_merge; use function array_merge;
use function array_values; use function array_values;
use function assert;
use function reset; use function reset;
/** /**
...@@ -41,7 +42,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement ...@@ -41,7 +42,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/** @var int */ /** @var int */
private $lifetime; private $lifetime;
/** @var Statement */ /** @var ResultStatement */
private $statement; private $statement;
/** /**
...@@ -62,7 +63,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement ...@@ -62,7 +63,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
* @param string $realKey * @param string $realKey
* @param int $lifetime * @param int $lifetime
*/ */
public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime) public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime)
{ {
$this->statement = $stmt; $this->statement = $stmt;
$this->resultCache = $resultCache; $this->resultCache = $resultCache;
...@@ -196,6 +197,8 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement ...@@ -196,6 +197,8 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
*/ */
public function rowCount() public function rowCount()
{ {
assert($this->statement instanceof Statement);
return $this->statement->rowCount(); return $this->statement->rowCount();
} }
} }
...@@ -128,11 +128,10 @@ class DBALException extends Exception ...@@ -128,11 +128,10 @@ class DBALException extends Exception
} }
/** /**
* @param Exception $driverEx * @param string $sql
* @param string $sql * @param mixed[] $params
* @param mixed[] $params
* *
* @return \Doctrine\DBAL\DBALException * @return self
*/ */
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = []) public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
{ {
...@@ -146,9 +145,7 @@ class DBALException extends Exception ...@@ -146,9 +145,7 @@ class DBALException extends Exception
} }
/** /**
* @param Exception $driverEx * @return self
*
* @return \Doctrine\DBAL\DBALException
*/ */
public static function driverException(Driver $driver, Throwable $driverEx) public static function driverException(Driver $driver, Throwable $driverEx)
{ {
...@@ -156,9 +153,7 @@ class DBALException extends Exception ...@@ -156,9 +153,7 @@ class DBALException extends Exception
} }
/** /**
* @param Exception $driverEx * @return self
*
* @return \Doctrine\DBAL\DBALException
*/ */
private static function wrapException(Driver $driver, Throwable $driverEx, $msg) private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
{ {
......
...@@ -240,7 +240,7 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -240,7 +240,7 @@ class OCI8Statement implements IteratorAggregate, Statement
* where the token was found. * where the token was found.
* *
* @param string $statement The SQL statement to parse * @param string $statement The SQL statement to parse
* @param string $offset The offset to start searching from * @param int $offset The offset to start searching from
* @param string $regex The regex containing token pattern * @param string $regex The regex containing token pattern
* *
* @return string|null Token or NULL if not found * @return string|null Token or NULL if not found
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Event; namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use function array_merge; use function array_merge;
use function is_array; use function is_array;
...@@ -16,7 +15,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -16,7 +15,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/** @var Table */ /** @var Table */
private $table; private $table;
/** @var Column[] */ /** @var mixed[][] */
private $columns; private $columns;
/** @var mixed[] */ /** @var mixed[] */
...@@ -29,8 +28,8 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -29,8 +28,8 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
private $sql = []; private $sql = [];
/** /**
* @param Column[] $columns * @param mixed[][] $columns
* @param mixed[] $options * @param mixed[] $options
*/ */
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
{ {
...@@ -49,7 +48,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -49,7 +48,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
} }
/** /**
* @return Column[] * @return mixed[][]
*/ */
public function getColumns() public function getColumns()
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Portability; namespace Doctrine\DBAL\Portability;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
...@@ -9,6 +10,7 @@ use Doctrine\DBAL\ParameterType; ...@@ -9,6 +10,7 @@ use Doctrine\DBAL\ParameterType;
use IteratorAggregate; use IteratorAggregate;
use PDO; use PDO;
use function array_change_key_case; use function array_change_key_case;
use function assert;
use function is_string; use function is_string;
use function rtrim; use function rtrim;
...@@ -20,7 +22,7 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -20,7 +22,7 @@ class Statement implements IteratorAggregate, DriverStatement
/** @var int */ /** @var int */
private $portability; private $portability;
/** @var DriverStatement */ /** @var DriverStatement|ResultStatement */
private $stmt; private $stmt;
/** @var int */ /** @var int */
...@@ -32,7 +34,7 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -32,7 +34,7 @@ class Statement implements IteratorAggregate, DriverStatement
/** /**
* Wraps <tt>Statement</tt> and applies portability measures. * Wraps <tt>Statement</tt> and applies portability measures.
* *
* @param DriverStatement $stmt * @param DriverStatement|ResultStatement $stmt
*/ */
public function __construct($stmt, Connection $conn) public function __construct($stmt, Connection $conn)
{ {
...@@ -46,6 +48,8 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -46,6 +48,8 @@ class Statement implements IteratorAggregate, DriverStatement
*/ */
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{ {
assert($this->stmt instanceof DriverStatement);
return $this->stmt->bindParam($column, $variable, $type, $length); return $this->stmt->bindParam($column, $variable, $type, $length);
} }
...@@ -54,6 +58,8 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -54,6 +58,8 @@ class Statement implements IteratorAggregate, DriverStatement
*/ */
public function bindValue($param, $value, $type = ParameterType::STRING) public function bindValue($param, $value, $type = ParameterType::STRING)
{ {
assert($this->stmt instanceof DriverStatement);
return $this->stmt->bindValue($param, $value, $type); return $this->stmt->bindValue($param, $value, $type);
} }
...@@ -78,6 +84,8 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -78,6 +84,8 @@ class Statement implements IteratorAggregate, DriverStatement
*/ */
public function errorCode() public function errorCode()
{ {
assert($this->stmt instanceof DriverStatement);
return $this->stmt->errorCode(); return $this->stmt->errorCode();
} }
...@@ -86,6 +94,8 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -86,6 +94,8 @@ class Statement implements IteratorAggregate, DriverStatement
*/ */
public function errorInfo() public function errorInfo()
{ {
assert($this->stmt instanceof DriverStatement);
return $this->stmt->errorInfo(); return $this->stmt->errorInfo();
} }
...@@ -94,6 +104,8 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -94,6 +104,8 @@ class Statement implements IteratorAggregate, DriverStatement
*/ */
public function execute($params = null) public function execute($params = null)
{ {
assert($this->stmt instanceof DriverStatement);
return $this->stmt->execute($params); return $this->stmt->execute($params);
} }
...@@ -228,6 +240,8 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -228,6 +240,8 @@ class Statement implements IteratorAggregate, DriverStatement
*/ */
public function rowCount() public function rowCount()
{ {
assert($this->stmt instanceof DriverStatement);
return $this->stmt->rowCount(); return $this->stmt->rowCount();
} }
} }
...@@ -286,8 +286,8 @@ class ExpressionBuilder ...@@ -286,8 +286,8 @@ class ExpressionBuilder
/** /**
* Quotes a given input parameter. * Quotes a given input parameter.
* *
* @param mixed $input The parameter to be quoted. * @param mixed $input The parameter to be quoted.
* @param string|null $type The type of the parameter. * @param int|null $type The type of the parameter.
* *
* @return string * @return string
*/ */
......
...@@ -36,13 +36,13 @@ class SQLParserUtils ...@@ -36,13 +36,13 @@ class SQLParserUtils
/** /**
* Gets an array of the placeholders in an sql statements as keys and their positions in the query string. * Gets an array of the placeholders in an sql statements as keys and their positions in the query string.
* *
* Returns an integer => integer pair (indexed from zero) for a positional statement * For a statement with positional parameters, returns a zero-indexed list of placeholder position.
* and a string => int[] pair for a named statement. * For a statement with named parameters, returns a map of placeholder positions to their parameter names.
* *
* @param string $statement * @param string $statement
* @param bool $isPositional * @param bool $isPositional
* *
* @return int[] * @return int[]|string[]
*/ */
public static function getPlaceholderPositions($statement, $isPositional = true) public static function getPlaceholderPositions($statement, $isPositional = true)
{ {
......
...@@ -268,7 +268,7 @@ abstract class AbstractSchemaManager ...@@ -268,7 +268,7 @@ abstract class AbstractSchemaManager
} }
$indexes = $this->listTableIndexes($tableName); $indexes = $this->listTableIndexes($tableName);
return new Table($tableName, $columns, $indexes, $foreignKeys, false, []); return new Table($tableName, $columns, $indexes, $foreignKeys);
} }
/** /**
......
...@@ -216,7 +216,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -216,7 +216,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition($view)
{ {
// @todo // @todo
return new View($view['name'], null); return new View($view['name'], '');
} }
/** /**
......
...@@ -283,9 +283,9 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -283,9 +283,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
continue; continue;
} }
$type = $this->extractDoctrineTypeFromComment($comment, null); $type = $this->extractDoctrineTypeFromComment($comment, '');
if ($type !== null) { if ($type !== '') {
$column->setType(Type::getType($type)); $column->setType(Type::getType($type));
$comment = $this->removeDoctrineTypeFromComment($comment, $type); $comment = $this->removeDoctrineTypeFromComment($comment, $type);
......
...@@ -425,7 +425,7 @@ class Table extends AbstractAsset ...@@ -425,7 +425,7 @@ class Table extends AbstractAsset
/** /**
* @param string $name * @param string $name
* @param string $value * @param mixed $value
* *
* @return self * @return self
*/ */
......
...@@ -78,15 +78,18 @@ class DropSchemaSqlCollector extends AbstractVisitor ...@@ -78,15 +78,18 @@ class DropSchemaSqlCollector extends AbstractVisitor
{ {
$sql = []; $sql = [];
/** @var ForeignKeyConstraint $fkConstraint */
foreach ($this->constraints as $fkConstraint) { foreach ($this->constraints as $fkConstraint) {
$localTable = $this->constraints[$fkConstraint]; $localTable = $this->constraints[$fkConstraint];
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable); $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
} }
/** @var Sequence $sequence */
foreach ($this->sequences as $sequence) { foreach ($this->sequences as $sequence) {
$sql[] = $this->platform->getDropSequenceSQL($sequence); $sql[] = $this->platform->getDropSequenceSQL($sequence);
} }
/** @var Table $table */
foreach ($this->tables as $table) { foreach ($this->tables as $table) {
$sql[] = $this->platform->getDropTableSQL($table); $sql[] = $this->platform->getDropTableSQL($table);
} }
......
...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Schema\Table; ...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Schema\Table;
use function current; use function current;
use function file_put_contents; use function file_put_contents;
use function in_array; use function in_array;
use function mt_rand;
use function sha1;
use function strtolower; use function strtolower;
/** /**
...@@ -41,7 +39,7 @@ class Graphviz extends AbstractVisitor ...@@ -41,7 +39,7 @@ class Graphviz extends AbstractVisitor
*/ */
public function acceptSchema(Schema $schema) public function acceptSchema(Schema $schema)
{ {
$this->output = 'digraph "' . sha1(mt_rand()) . '" {' . "\n"; $this->output = 'digraph "' . $schema->getName() . '" {' . "\n";
$this->output .= 'splines = true;' . "\n"; $this->output .= 'splines = true;' . "\n";
$this->output .= 'overlap = false;' . "\n"; $this->output .= 'overlap = false;' . "\n";
$this->output .= 'outputorder=edgesfirst;' . "\n"; $this->output .= 'outputorder=edgesfirst;' . "\n";
......
...@@ -205,7 +205,7 @@ class PoolingShardConnection extends Connection ...@@ -205,7 +205,7 @@ class PoolingShardConnection extends Connection
/** /**
* Connects to a specific connection. * Connects to a specific connection.
* *
* @param string $shardId * @param string|int $shardId
* *
* @return \Doctrine\DBAL\Driver\Connection * @return \Doctrine\DBAL\Driver\Connection
*/ */
......
parameters: parameters:
level: 4 level: 5
paths: paths:
- %currentWorkingDirectory%/lib - %currentWorkingDirectory%/lib
autoload_files: autoload_files:
...@@ -26,6 +26,9 @@ parameters: ...@@ -26,6 +26,9 @@ parameters:
# http://php.net/manual/en/pdo.sqlitecreatefunction.php # http://php.net/manual/en/pdo.sqlitecreatefunction.php
- '~^Call to an undefined method Doctrine\\DBAL\\Driver\\PDOConnection::sqliteCreateFunction\(\)\.\z~' - '~^Call to an undefined method Doctrine\\DBAL\\Driver\\PDOConnection::sqliteCreateFunction\(\)\.\z~'
# https://github.com/JetBrains/phpstorm-stubs/pull/488
- '~^Parameter #1 \$byteCount of function SQLSRV_SQLTYPE_VARBINARY expects int, string given\.\z~'
# legacy variadic-like signature # legacy variadic-like signature
- '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' - '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment