Skip to content

Commit

Permalink
Merge pull request #3436 from morozov/phpstan-lvl5
Browse files Browse the repository at this point in the history
PHPStan Level 5
  • Loading branch information
Ocramius authored Jan 24, 2019
2 parents 9b88bf3 + 5600b86 commit 94cec71
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 35 deletions.
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PDO;
use function array_merge;
use function array_values;
use function assert;
use function reset;

/**
Expand Down Expand Up @@ -41,7 +42,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/** @var int */
private $lifetime;

/** @var Statement */
/** @var ResultStatement */
private $statement;

/**
Expand All @@ -62,7 +63,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
* @param string $realKey
* @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->resultCache = $resultCache;
Expand Down Expand Up @@ -196,6 +197,8 @@ public function fetchColumn($columnIndex = 0)
*/
public function rowCount()
{
assert($this->statement instanceof Statement);

return $this->statement->rowCount();
}
}
15 changes: 5 additions & 10 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ public static function unknownDriver($unknownDriverName, array $knownDrivers)
}

/**
* @param Exception $driverEx
* @param string $sql
* @param mixed[] $params
* @param string $sql
* @param mixed[] $params
*
* @return \Doctrine\DBAL\DBALException
* @return self
*/
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
{
Expand All @@ -146,19 +145,15 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri
}

/**
* @param Exception $driverEx
*
* @return \Doctrine\DBAL\DBALException
* @return self
*/
public static function driverException(Driver $driver, Throwable $driverEx)
{
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
}

/**
* @param Exception $driverEx
*
* @return \Doctrine\DBAL\DBALException
* @return self
*/
private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static function findClosingQuote(
* where the token was found.
*
* @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
*
* @return string|null Token or NULL if not found
Expand Down
9 changes: 4 additions & 5 deletions lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Event;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function is_array;
Expand All @@ -16,7 +15,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/** @var Table */
private $table;

/** @var Column[] */
/** @var mixed[][] */
private $columns;

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

/**
* @param Column[] $columns
* @param mixed[] $options
* @param mixed[][] $columns
* @param mixed[] $options
*/
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
{
Expand All @@ -49,7 +48,7 @@ public function getTable()
}

/**
* @return Column[]
* @return mixed[][]
*/
public function getColumns()
{
Expand Down
18 changes: 16 additions & 2 deletions lib/Doctrine/DBAL/Portability/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Doctrine\DBAL\Portability;

use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use function array_change_key_case;
use function assert;
use function is_string;
use function rtrim;

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

/** @var DriverStatement */
/** @var DriverStatement|ResultStatement */
private $stmt;

/** @var int */
Expand All @@ -32,7 +34,7 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* Wraps <tt>Statement</tt> and applies portability measures.
*
* @param DriverStatement $stmt
* @param DriverStatement|ResultStatement $stmt
*/
public function __construct($stmt, Connection $conn)
{
Expand All @@ -46,6 +48,8 @@ public function __construct($stmt, Connection $conn)
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{
assert($this->stmt instanceof DriverStatement);

return $this->stmt->bindParam($column, $variable, $type, $length);
}

Expand All @@ -54,6 +58,8 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
assert($this->stmt instanceof DriverStatement);

return $this->stmt->bindValue($param, $value, $type);
}

Expand All @@ -78,6 +84,8 @@ public function columnCount()
*/
public function errorCode()
{
assert($this->stmt instanceof DriverStatement);

return $this->stmt->errorCode();
}

Expand All @@ -86,6 +94,8 @@ public function errorCode()
*/
public function errorInfo()
{
assert($this->stmt instanceof DriverStatement);

return $this->stmt->errorInfo();
}

Expand All @@ -94,6 +104,8 @@ public function errorInfo()
*/
public function execute($params = null)
{
assert($this->stmt instanceof DriverStatement);

return $this->stmt->execute($params);
}

Expand Down Expand Up @@ -228,6 +240,8 @@ public function fetchColumn($columnIndex = 0)
*/
public function rowCount()
{
assert($this->stmt instanceof DriverStatement);

return $this->stmt->rowCount();
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public function notIn($x, $y)
/**
* Quotes a given input parameter.
*
* @param mixed $input The parameter to be quoted.
* @param string|null $type The type of the parameter.
* @param mixed $input The parameter to be quoted.
* @param int|null $type The type of the parameter.
*
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* Returns an integer => integer pair (indexed from zero) for a positional statement
* and a string => int[] pair for a named statement.
* For a statement with positional parameters, returns a zero-indexed list of placeholder position.
* For a statement with named parameters, returns a map of placeholder positions to their parameter names.
*
* @param string $statement
* @param bool $isPositional
*
* @return int[]
* @return int[]|string[]
*/
public static function getPlaceholderPositions($statement, $isPositional = true)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function listTableDetails($tableName)
}
$indexes = $this->listTableIndexes($tableName);

return new Table($tableName, $columns, $indexes, $foreignKeys, false, []);
return new Table($tableName, $columns, $indexes, $foreignKeys);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected function getPortableNamespaceDefinition(array $namespace)
protected function _getPortableViewDefinition($view)
{
// @todo
return new View($view['name'], null);
return new View($view['name'], '');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns)
continue;
}

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

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

$comment = $this->removeDoctrineTypeFromComment($comment, $type);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public function addNamedForeignKeyConstraint($name, $foreignTable, array $localC

/**
* @param string $name
* @param string $value
* @param mixed $value
*
* @return self
*/
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ public function getQueries()
{
$sql = [];

/** @var ForeignKeyConstraint $fkConstraint */
foreach ($this->constraints as $fkConstraint) {
$localTable = $this->constraints[$fkConstraint];
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
}

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

/** @var Table $table */
foreach ($this->tables as $table) {
$sql[] = $this->platform->getDropTableSQL($table);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use function current;
use function file_put_contents;
use function in_array;
use function mt_rand;
use function sha1;
use function strtolower;

/**
Expand Down Expand Up @@ -41,7 +39,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons
*/
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 .= 'overlap = false;' . "\n";
$this->output .= 'outputorder=edgesfirst;' . "\n";
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function connect($shardId = null)
/**
* Connects to a specific connection.
*
* @param string $shardId
* @param string|int $shardId
*
* @return \Doctrine\DBAL\Driver\Connection
*/
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 4
level: 5
paths:
- %currentWorkingDirectory%/lib
autoload_files:
Expand All @@ -26,6 +26,9 @@ parameters:
# http://php.net/manual/en/pdo.sqlitecreatefunction.php
- '~^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
- '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~'

Expand Down

0 comments on commit 94cec71

Please sign in to comment.