Unverified Commit 402bbcf0 authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #3025 from Majkl578/phpstan

Added PHPStan, apply changes for level 3
parents 3979efee df434372
...@@ -7,3 +7,4 @@ vendor/ ...@@ -7,3 +7,4 @@ vendor/
*.phpunit.xml *.phpunit.xml
/phpunit.xml /phpunit.xml
/.phpcs-cache /.phpcs-cache
/phpstan.neon
...@@ -414,6 +414,11 @@ jobs: ...@@ -414,6 +414,11 @@ jobs:
- composer config minimum-stability dev - composer config minimum-stability dev
- travis_retry composer update --prefer-dist - travis_retry composer update --prefer-dist
- stage: Code Quality
env: DB=none STATIC_ANALYSIS
install: travis_retry composer update --prefer-dist
script: vendor/bin/phpstan analyse
- stage: Pull request coding standard - stage: Pull request coding standard
if: type = pull_request if: type = pull_request
php: 7.1 php: 7.1
......
This diff is collapsed.
...@@ -19,12 +19,14 @@ ...@@ -19,12 +19,14 @@
namespace Doctrine\DBAL; namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidArgumentException;
use Closure; use Closure;
use Exception; use Exception;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\Cache\ResultCacheStatement; use Doctrine\DBAL\Cache\ResultCacheStatement;
use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Cache\QueryCacheProfile;
...@@ -32,6 +34,7 @@ use Doctrine\DBAL\Cache\ArrayStatement; ...@@ -32,6 +34,7 @@ use Doctrine\DBAL\Cache\ArrayStatement;
use Doctrine\DBAL\Cache\CacheException; use Doctrine\DBAL\Cache\CacheException;
use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\PingableConnection;
use Throwable; use Throwable;
use function assert;
use function array_key_exists; use function array_key_exists;
use function array_merge; use function array_merge;
use function func_get_args; use function func_get_args;
...@@ -108,7 +111,7 @@ class Connection implements DriverConnection ...@@ -108,7 +111,7 @@ class Connection implements DriverConnection
/** /**
* The wrapped driver connection. * The wrapped driver connection.
* *
* @var \Doctrine\DBAL\Driver\Connection * @var \Doctrine\DBAL\Driver\Connection|null
*/ */
protected $_conn; protected $_conn;
...@@ -409,7 +412,9 @@ class Connection implements DriverConnection ...@@ -409,7 +412,9 @@ class Connection implements DriverConnection
{ {
$version = $this->getDatabasePlatformVersion(); $version = $this->getDatabasePlatformVersion();
if (null !== $version) { if ($version !== null) {
assert($this->_driver instanceof VersionAwarePlatformDriver);
$this->platform = $this->_driver->createDatabasePlatformForVersion($version); $this->platform = $this->_driver->createDatabasePlatformForVersion($version);
} else { } else {
$this->platform = $this->_driver->getDatabasePlatform(); $this->platform = $this->_driver->getDatabasePlatform();
...@@ -875,7 +880,7 @@ class Connection implements DriverConnection ...@@ -875,7 +880,7 @@ class Connection implements DriverConnection
* *
* @param string $statement The SQL statement to prepare. * @param string $statement The SQL statement to prepare.
* *
* @return \Doctrine\DBAL\Statement The prepared statement. * @return DriverStatement The prepared statement.
* *
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*/ */
...@@ -903,7 +908,7 @@ class Connection implements DriverConnection ...@@ -903,7 +908,7 @@ class Connection implements DriverConnection
* @param array $types The types the previous parameters are in. * @param array $types The types the previous parameters are in.
* @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional.
* *
* @return \Doctrine\DBAL\Driver\Statement The executed statement. * @return ResultStatement The executed statement.
* *
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*/ */
...@@ -955,7 +960,7 @@ class Connection implements DriverConnection ...@@ -955,7 +960,7 @@ class Connection implements DriverConnection
* @param array $types The types the previous parameters are in. * @param array $types The types the previous parameters are in.
* @param \Doctrine\DBAL\Cache\QueryCacheProfile $qcp The query cache profile. * @param \Doctrine\DBAL\Cache\QueryCacheProfile $qcp The query cache profile.
* *
* @return \Doctrine\DBAL\Driver\ResultStatement * @return ResultStatement
* *
* @throws \Doctrine\DBAL\Cache\CacheException * @throws \Doctrine\DBAL\Cache\CacheException
*/ */
...@@ -1139,7 +1144,7 @@ class Connection implements DriverConnection ...@@ -1139,7 +1144,7 @@ class Connection implements DriverConnection
/** /**
* Fetches the SQLSTATE associated with the last database operation. * Fetches the SQLSTATE associated with the last database operation.
* *
* @return int The last error code. * @return string|null The last error code.
*/ */
public function errorCode() public function errorCode()
{ {
......
...@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Connections; ...@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Connections;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
...@@ -88,7 +89,7 @@ class MasterSlaveConnection extends Connection ...@@ -88,7 +89,7 @@ class MasterSlaveConnection extends Connection
/** /**
* Master and slave connection (one of the randomly picked slaves). * Master and slave connection (one of the randomly picked slaves).
* *
* @var \Doctrine\DBAL\Driver\Connection[] * @var DriverConnection[]|null[]
*/ */
protected $connections = ['master' => null, 'slave' => null]; protected $connections = ['master' => null, 'slave' => null];
...@@ -199,7 +200,7 @@ class MasterSlaveConnection extends Connection ...@@ -199,7 +200,7 @@ class MasterSlaveConnection extends Connection
* *
* @param string $connectionName * @param string $connectionName
* *
* @return \Doctrine\DBAL\Driver * @return DriverConnection
*/ */
protected function connectTo($connectionName) protected function connectTo($connectionName)
{ {
......
...@@ -36,7 +36,7 @@ interface Connection ...@@ -36,7 +36,7 @@ interface Connection
* *
* @param string $prepareString * @param string $prepareString
* *
* @return \Doctrine\DBAL\Driver\Statement * @return Statement
*/ */
public function prepare($prepareString); public function prepare($prepareString);
......
...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL\Driver\IBMDB2; ...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use stdClass;
use const DB2_AUTOCOMMIT_OFF; use const DB2_AUTOCOMMIT_OFF;
use const DB2_AUTOCOMMIT_ON; use const DB2_AUTOCOMMIT_ON;
use function db2_autocommit; use function db2_autocommit;
...@@ -74,6 +75,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -74,6 +75,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/ */
public function getServerVersion() public function getServerVersion()
{ {
/** @var stdClass $serverInfo */
$serverInfo = db2_server_info($this->_conn); $serverInfo = db2_server_info($this->_conn);
return $serverInfo->DBMS_VER; return $serverInfo->DBMS_VER;
......
...@@ -66,7 +66,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -66,7 +66,7 @@ class DB2Statement implements \IteratorAggregate, Statement
private $defaultFetchClass = '\stdClass'; private $defaultFetchClass = '\stdClass';
/** /**
* @var string Constructor arguments for the default class to instantiate when fetching class instances. * @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/ */
private $defaultFetchClassCtorArgs = []; private $defaultFetchClassCtorArgs = [];
......
...@@ -252,7 +252,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -252,7 +252,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
} }
/** /**
* @return bool|array * @return mixed[]|false
*/ */
private function _fetch() private function _fetch()
{ {
......
...@@ -22,10 +22,12 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; ...@@ -22,10 +22,12 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use function assert;
use function func_get_args; use function func_get_args;
use function is_float; use function is_float;
use function is_int; use function is_int;
use function is_resource; use function is_resource;
use function is_string;
use function sasql_affected_rows; use function sasql_affected_rows;
use function sasql_commit; use function sasql_commit;
use function sasql_connect; use function sasql_connect;
...@@ -149,7 +151,11 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -149,7 +151,11 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function getServerVersion() public function getServerVersion()
{ {
return $this->query("SELECT PROPERTY('ProductVersion')")->fetchColumn(); $version = $this->query("SELECT PROPERTY('ProductVersion')")->fetchColumn();
assert(is_string($version));
return $version;
} }
/** /**
......
...@@ -70,7 +70,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -70,7 +70,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
private $defaultFetchClass = '\stdClass'; private $defaultFetchClass = '\stdClass';
/** /**
* @var string Constructor arguments for the default class to instantiate when fetching class instances. * @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/ */
private $defaultFetchClassCtorArgs = []; private $defaultFetchClassCtorArgs = [];
......
...@@ -75,7 +75,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -75,7 +75,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/** /**
* The SQLSRV statement resource. * The SQLSRV statement resource.
* *
* @var resource * @var resource|null
*/ */
private $stmt; private $stmt;
...@@ -114,7 +114,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -114,7 +114,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/** /**
* The constructor arguments for the default class to instantiate when fetching class instances. * The constructor arguments for the default class to instantiate when fetching class instances.
* *
* @var string * @var mixed[]
*/ */
private $defaultFetchClassCtorArgs = []; private $defaultFetchClassCtorArgs = [];
......
...@@ -85,7 +85,7 @@ interface Statement extends ResultStatement ...@@ -85,7 +85,7 @@ interface Statement extends ResultStatement
* *
* @see Doctrine_Adapter_Interface::errorCode() * @see Doctrine_Adapter_Interface::errorCode()
* *
* @return string The error code string. * @return string|int|bool The error code string.
*/ */
public function errorCode(); public function errorCode();
......
...@@ -402,7 +402,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -402,7 +402,7 @@ class OraclePlatform extends AbstractPlatform
foreach ($columns as $name => $column) { foreach ($columns as $name => $column) {
if (isset($column['sequence'])) { if (isset($column['sequence'])) {
$sql[] = $this->getCreateSequenceSQL($column['sequence'], 1); $sql[] = $this->getCreateSequenceSQL($column['sequence']);
} }
if (isset($column['autoincrement']) && $column['autoincrement'] || if (isset($column['autoincrement']) && $column['autoincrement'] ||
......
...@@ -1306,7 +1306,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -1306,7 +1306,7 @@ class SQLServerPlatform extends AbstractPlatform
* Remove ORDER BY clauses in subqueries - they're not supported by SQL Server. * Remove ORDER BY clauses in subqueries - they're not supported by SQL Server.
* Caveat: will leave ORDER BY in TOP N subqueries. * Caveat: will leave ORDER BY in TOP N subqueries.
* *
* @param $query * @param string $query
* @return string * @return string
*/ */
private function scrubInnerOrderBy($query) private function scrubInnerOrderBy($query)
......
...@@ -934,7 +934,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -934,7 +934,7 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @param \Doctrine\DBAL\Schema\TableDiff $diff * @param \Doctrine\DBAL\Schema\TableDiff $diff
* *
* @return array|bool * @return string[]|false
*/ */
private function getSimpleAlterTableSQL(TableDiff $diff) private function getSimpleAlterTableSQL(TableDiff $diff)
{ {
......
...@@ -204,7 +204,7 @@ class Comparator ...@@ -204,7 +204,7 @@ class Comparator
* @param \Doctrine\DBAL\Schema\Table $table1 * @param \Doctrine\DBAL\Schema\Table $table1
* @param \Doctrine\DBAL\Schema\Table $table2 * @param \Doctrine\DBAL\Schema\Table $table2
* *
* @return bool|\Doctrine\DBAL\Schema\TableDiff * @return TableDiff|false
*/ */
public function diffTable(Table $table1, Table $table2) public function diffTable(Table $table1, Table $table2)
{ {
...@@ -312,8 +312,6 @@ class Comparator ...@@ -312,8 +312,6 @@ class Comparator
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop * Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
* however ambiguities between different possibilities should not lead to renaming at all. * however ambiguities between different possibilities should not lead to renaming at all.
* *
* @param \Doctrine\DBAL\Schema\TableDiff $tableDifferences
*
* @return void * @return void
*/ */
private function detectColumnRenamings(TableDiff $tableDifferences) private function detectColumnRenamings(TableDiff $tableDifferences)
...@@ -348,8 +346,6 @@ class Comparator ...@@ -348,8 +346,6 @@ class Comparator
* Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop * Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop
* however ambiguities between different possibilities should not lead to renaming at all. * however ambiguities between different possibilities should not lead to renaming at all.
* *
* @param \Doctrine\DBAL\Schema\TableDiff $tableDifferences
*
* @return void * @return void
*/ */
private function detectIndexRenamings(TableDiff $tableDifferences) private function detectIndexRenamings(TableDiff $tableDifferences)
......
...@@ -21,10 +21,12 @@ namespace Doctrine\DBAL\Schema; ...@@ -21,10 +21,12 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use const CASE_LOWER; use const CASE_LOWER;
use function array_change_key_case; use function array_change_key_case;
use function array_values; use function array_values;
use function assert;
use function is_null; use function is_null;
use function preg_match; use function preg_match;
use function sprintf; use function sprintf;
...@@ -116,6 +118,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -116,6 +118,7 @@ class OracleSchemaManager extends AbstractSchemaManager
$tableIndex = \array_change_key_case($tableIndex, CASE_LOWER); $tableIndex = \array_change_key_case($tableIndex, CASE_LOWER);
$keyName = strtolower($tableIndex['name']); $keyName = strtolower($tableIndex['name']);
$buffer = [];
if (strtolower($tableIndex['is_primary']) == "p") { if (strtolower($tableIndex['is_primary']) == "p") {
$keyName = 'primary'; $keyName = 'primary';
...@@ -346,8 +349,6 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -346,8 +349,6 @@ class OracleSchemaManager extends AbstractSchemaManager
$query = 'GRANT DBA TO ' . $username; $query = 'GRANT DBA TO ' . $username;
$this->_conn->executeUpdate($query); $this->_conn->executeUpdate($query);
return true;
} }
/** /**
...@@ -357,6 +358,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -357,6 +358,8 @@ class OracleSchemaManager extends AbstractSchemaManager
*/ */
public function dropAutoincrement($table) public function dropAutoincrement($table)
{ {
assert($this->_platform instanceof OraclePlatform);
$sql = $this->_platform->getDropAutoincrementSql($table); $sql = $this->_platform->getDropAutoincrementSql($table);
foreach ($sql as $query) { foreach ($sql as $query) {
$this->_conn->executeUpdate($query); $this->_conn->executeUpdate($query);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use const CASE_LOWER; use const CASE_LOWER;
use function array_change_key_case; use function array_change_key_case;
...@@ -27,6 +28,7 @@ use function array_filter; ...@@ -27,6 +28,7 @@ use function array_filter;
use function array_keys; use function array_keys;
use function array_map; use function array_map;
use function array_shift; use function array_shift;
use function assert;
use function explode; use function explode;
use function in_array; use function in_array;
use function join; use function join;
...@@ -134,6 +136,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -134,6 +136,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
throw $exception; throw $exception;
} }
assert($this->_platform instanceof PostgreSqlPlatform);
$this->_execSql( $this->_execSql(
[ [
$this->_platform->getDisallowDatabaseConnectionsSQL($database), $this->_platform->getDisallowDatabaseConnectionsSQL($database),
...@@ -150,8 +154,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -150,8 +154,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
*/ */
protected function _getPortableTableForeignKeyDefinition($tableForeignKey) protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
{ {
$onUpdate = null; $onUpdate = null;
$onDelete = null; $onDelete = null;
$localColumns = null;
$foreignColumns = null;
$foreignTable = null;
if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) { if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) {
$onUpdate = $match[1]; $onUpdate = $match[1];
...@@ -307,7 +314,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -307,7 +314,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
} }
if ( ! isset($sequence['increment_by'], $sequence['min_value'])) { if ( ! isset($sequence['increment_by'], $sequence['min_value'])) {
/** @var string[] $data */
$data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName)); $data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
$sequence += $data; $sequence += $data;
} }
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function assert;
use function preg_replace; use function preg_replace;
/** /**
...@@ -68,6 +70,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -68,6 +70,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
*/ */
public function startDatabase($database) public function startDatabase($database)
{ {
assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStartDatabaseSQL($database)); $this->_execSql($this->_platform->getStartDatabaseSQL($database));
} }
...@@ -78,6 +81,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -78,6 +81,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
*/ */
public function stopDatabase($database) public function stopDatabase($database)
{ {
assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStopDatabaseSQL($database)); $this->_execSql($this->_platform->getStopDatabaseSQL($database));
} }
......
...@@ -76,7 +76,7 @@ class Schema extends AbstractAsset ...@@ -76,7 +76,7 @@ class Schema extends AbstractAsset
protected $_sequences = []; protected $_sequences = [];
/** /**
* @var \Doctrine\DBAL\Schema\SchemaConfig * @var SchemaConfig
*/ */
protected $_schemaConfig = false; protected $_schemaConfig = false;
......
...@@ -77,7 +77,7 @@ class Table extends AbstractAsset ...@@ -77,7 +77,7 @@ class Table extends AbstractAsset
protected $_options = []; protected $_options = [];
/** /**
* @var SchemaConfig * @var SchemaConfig|null
*/ */
protected $_schemaConfig = null; protected $_schemaConfig = null;
......
...@@ -99,7 +99,7 @@ class TableDiff ...@@ -99,7 +99,7 @@ class TableDiff
/** /**
* All added foreign key definitions * All added foreign key definitions
* *
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[] * @var ForeignKeyConstraint[]
*/ */
public $addedForeignKeys = []; public $addedForeignKeys = [];
...@@ -113,7 +113,7 @@ class TableDiff ...@@ -113,7 +113,7 @@ class TableDiff
/** /**
* All removed foreign keys * All removed foreign keys
* *
* @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[] * @var ForeignKeyConstraint[]|string[]
*/ */
public $removedForeignKeys = []; public $removedForeignKeys = [];
...@@ -161,7 +161,7 @@ class TableDiff ...@@ -161,7 +161,7 @@ class TableDiff
} }
/** /**
* @return \Doctrine\DBAL\Schema\Identifier|boolean * @return Identifier|string|bool
*/ */
public function getNewName() public function getNewName()
{ {
......
...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL\Sharding; ...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL\Sharding;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
...@@ -68,19 +69,19 @@ use function is_string; ...@@ -68,19 +69,19 @@ use function is_string;
class PoolingShardConnection extends Connection class PoolingShardConnection extends Connection
{ {
/** /**
* @var array * @var DriverConnection[]
*/ */
private $activeConnections; private $activeConnections = [];
/** /**
* @var int * @var int|null
*/ */
private $activeShardId; private $activeShardId;
/** /**
* @var array * @var mixed[]
*/ */
private $connections; private $connectionParameters = [];
/** /**
* @param array $params * @param array $params
...@@ -108,7 +109,7 @@ class PoolingShardConnection extends Connection ...@@ -108,7 +109,7 @@ class PoolingShardConnection extends Connection
throw new \InvalidArgumentException("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); throw new \InvalidArgumentException("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser");
} }
$this->connections[0] = array_merge($params, $params['global']); $this->connectionParameters[0] = array_merge($params, $params['global']);
foreach ($params['shards'] as $shard) { foreach ($params['shards'] as $shard) {
if ( ! isset($shard['id'])) { if ( ! isset($shard['id'])) {
...@@ -119,11 +120,11 @@ class PoolingShardConnection extends Connection ...@@ -119,11 +120,11 @@ class PoolingShardConnection extends Connection
throw new \InvalidArgumentException("Shard Id has to be a non-negative number."); throw new \InvalidArgumentException("Shard Id has to be a non-negative number.");
} }
if (isset($this->connections[$shard['id']])) { if (isset($this->connectionParameters[$shard['id']])) {
throw new \InvalidArgumentException("Shard " . $shard['id'] . " is duplicated in the configuration."); throw new \InvalidArgumentException("Shard " . $shard['id'] . " is duplicated in the configuration.");
} }
$this->connections[$shard['id']] = array_merge($params, $shard); $this->connectionParameters[$shard['id']] = array_merge($params, $shard);
} }
parent::__construct($params, $driver, $config, $eventManager); parent::__construct($params, $driver, $config, $eventManager);
...@@ -144,7 +145,7 @@ class PoolingShardConnection extends Connection ...@@ -144,7 +145,7 @@ class PoolingShardConnection extends Connection
*/ */
public function getParams() public function getParams()
{ {
return $this->activeShardId ? $this->connections[$this->activeShardId] : $this->connections[0]; return $this->activeShardId ? $this->connectionParameters[$this->activeShardId] : $this->connectionParameters[0];
} }
/** /**
...@@ -241,7 +242,7 @@ class PoolingShardConnection extends Connection ...@@ -241,7 +242,7 @@ class PoolingShardConnection extends Connection
$driverOptions = $params['driverOptions'] ?? []; $driverOptions = $params['driverOptions'] ?? [];
$connectionParams = $this->connections[$shardId]; $connectionParams = $this->connectionParameters[$shardId];
$user = $connectionParams['user'] ?? null; $user = $connectionParams['user'] ?? null;
$password = $connectionParams['password'] ?? null; $password = $connectionParams['password'] ?? null;
...@@ -269,7 +270,7 @@ class PoolingShardConnection extends Connection ...@@ -269,7 +270,7 @@ class PoolingShardConnection extends Connection
public function close() public function close()
{ {
$this->_conn = null; $this->_conn = null;
$this->activeConnections = null; $this->activeConnections = [];
$this->activeShardId = null; $this->activeShardId = null;
} }
} }
...@@ -32,10 +32,10 @@ interface ShardChoser ...@@ -32,10 +32,10 @@ interface ShardChoser
/** /**
* Picks a shard for the given distribution value. * Picks a shard for the given distribution value.
* *
* @param string $distributionValue * @param string|int $distributionValue
* @param \Doctrine\DBAL\Sharding\PoolingShardConnection $conn * @param \Doctrine\DBAL\Sharding\PoolingShardConnection $conn
* *
* @return int * @return string|int
*/ */
function pickShard($distributionValue, PoolingShardConnection $conn); function pickShard($distributionValue, PoolingShardConnection $conn);
} }
...@@ -211,7 +211,7 @@ class Statement implements \IteratorAggregate, DriverStatement ...@@ -211,7 +211,7 @@ class Statement implements \IteratorAggregate, DriverStatement
/** /**
* Fetches the SQLSTATE associated with the last operation on the statement. * Fetches the SQLSTATE associated with the last operation on the statement.
* *
* @return string * @return string|int|bool
*/ */
public function errorCode() public function errorCode()
{ {
......
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
namespace Doctrine\DBAL\Tools\Console\Command; namespace Doctrine\DBAL\Tools\Console\Command;
use Doctrine\DBAL\Driver\PDOStatement;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use const PHP_EOL; use const PHP_EOL;
use function assert;
use function file_exists; use function file_exists;
use function file_get_contents; use function file_get_contents;
use function is_readable; use function is_readable;
...@@ -97,6 +99,8 @@ EOT ...@@ -97,6 +99,8 @@ EOT
$lines = 0; $lines = 0;
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
assert($stmt instanceof PDOStatement);
$stmt->execute(); $stmt->execute();
do { do {
......
parameters:
level: 3
paths:
- %currentWorkingDirectory%/lib
autoload_files:
- %currentWorkingDirectory%/tests/phpstan-polyfill.php
reportUnmatchedIgnoredErrors: false
ignoreErrors:
# extension not available
- '~^(Used )?(Function|Constant) sasql_\S+ not found\.\z~i'
# removing it would be BC break
- '~^Constructor of class Doctrine\\DBAL\\Schema\\Table has an unused parameter \$idGeneratorType\.\z~'
# changing these would be a BC break, to be done in next major
- '~^Method Doctrine\\DBAL\\Driver\\IBMDB2\\DB2Connection::exec\(\) should return int but returns bool\.\z~'
- '~^Method Doctrine\\DBAL\\Query\\QueryBuilder::execute\(\) should return Doctrine\\DBAL\\Driver\\Statement\|int but returns Doctrine\\DBAL\\Driver\\ResultStatement\.\z~'
- '~^Property Doctrine\\DBAL\\Schema\\Table::\$_primaryKeyName \(string\) does not accept (default value of type )?false\.\z~'
- '~^Property Doctrine\\DBAL\\Schema\\Schema::\$_schemaConfig \(Doctrine\\DBAL\\Schema\\SchemaConfig\) does not accept default value of type false\.\z~'
- '~^Method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint::onEvent\(\) should return string\|null but returns false\.\z~'
- '~^Method Doctrine\\DBAL\\Schema\\(Oracle|PostgreSql|SQLServer)SchemaManager::_getPortableTableDefinition\(\) should return array but returns string\.\z~'
- '~^Method Doctrine\\DBAL\\Platforms\\(|SQLAnywhere|Sqlite)Platform::_getTransactionIsolationLevelSQL\(\) should return string but returns int\.\z~'
- '~^Method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection::lastInsertId\(\) should return string but returns (int|false)\.\z~'
- '~^Method Doctrine\\DBAL\\Driver\\SQLSrv\\SQLSrvConnection::errorCode\(\) should return string\|null but returns false\.\z~'
# actually OCI-Lob - not even a valid class name...
- '~^Call to an undefined method object::writeTemporary\(\)\.\z~'
# http://php.net/manual/en/pdo.sqlitecreatefunction.php
- '~^Call to an undefined method Doctrine\\DBAL\\Driver\\PDOConnection::sqliteCreateFunction\(\)\.\z~'
# legacy variadic-like signature
- '~^Method Doctrine\\DBAL\\Driver\\Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~'
# some drivers actually do accept 2nd parameter...
- '~^Method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getListTableForeignKeysSQL\(\) invoked with \d+ parameters, 1 required\.\z~'
# legacy remnants from doctrine/common
- '~^Class Doctrine\\Common\\(Collections\\Collection|Persistence\\Proxy) not found\.\z~'
- '~^.+ on an unknown class Doctrine\\Common\\(Collections\\Collection|Persistence\\Proxy)\.\z~'
# inheritance variance inference issue
- '~^Method Doctrine\\DBAL\\Driver\\PDOConnection::\w+\(\) should return Doctrine\\DBAL\\Driver\\Statement but returns PDOStatement\.\z~'
# may not exist when pdo_sqlsrv is not loaded
- '~^Access to undefined constant PDO::SQLSRV_ENCODING_BINARY\.\z~'
<?php
declare(strict_types=1);
(function () : void {
foreach (['ibm_db2', 'mysqli', 'oci8', 'sqlsrv', 'pgsql'] as $extension) {
if (extension_loaded($extension)) {
continue;
}
require sprintf(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs/%1$s/%1$s.php', $extension);
}
})();
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