PHPStan Level 4

parent b90d6324
...@@ -149,7 +149,7 @@ class Connection implements DriverConnection ...@@ -149,7 +149,7 @@ class Connection implements DriverConnection
/** /**
* The schema manager. * The schema manager.
* *
* @var AbstractSchemaManager * @var AbstractSchemaManager|null
*/ */
protected $_schemaManager; protected $_schemaManager;
...@@ -1446,7 +1446,7 @@ class Connection implements DriverConnection ...@@ -1446,7 +1446,7 @@ class Connection implements DriverConnection
*/ */
public function getSchemaManager() public function getSchemaManager()
{ {
if (! $this->_schemaManager) { if ($this->_schemaManager === null) {
$this->_schemaManager = $this->_driver->getSchemaManager($this); $this->_schemaManager = $this->_driver->getSchemaManager($this);
} }
......
...@@ -133,7 +133,7 @@ class MasterSlaveConnection extends Connection ...@@ -133,7 +133,7 @@ class MasterSlaveConnection extends Connection
// If we have a connection open, and this is not an explicit connection // If we have a connection open, and this is not an explicit connection
// change request, then abort right here, because we are already done. // change request, then abort right here, because we are already done.
// This prevents writes to the slave in case of "keepSlave" option enabled. // This prevents writes to the slave in case of "keepSlave" option enabled.
if (isset($this->_conn) && $this->_conn && ! $requestedConnectionChange) { if ($this->_conn !== null && ! $requestedConnectionChange) {
return false; return false;
} }
...@@ -144,7 +144,7 @@ class MasterSlaveConnection extends Connection ...@@ -144,7 +144,7 @@ class MasterSlaveConnection extends Connection
$forceMasterAsSlave = true; $forceMasterAsSlave = true;
} }
if (isset($this->connections[$connectionName]) && $this->connections[$connectionName]) { if (isset($this->connections[$connectionName])) {
$this->_conn = $this->connections[$connectionName]; $this->_conn = $this->connections[$connectionName];
if ($forceMasterAsSlave && ! $this->keepSlave) { if ($forceMasterAsSlave && ! $this->keepSlave) {
......
...@@ -146,10 +146,6 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -146,10 +146,6 @@ class DB2Statement implements IteratorAggregate, Statement
*/ */
public function closeCursor() public function closeCursor()
{ {
if (! $this->stmt) {
return false;
}
$this->bindParam = []; $this->bindParam = [];
if (! db2_free_result($this->stmt)) { if (! db2_free_result($this->stmt)) {
...@@ -166,11 +162,7 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -166,11 +162,7 @@ class DB2Statement implements IteratorAggregate, Statement
*/ */
public function columnCount() public function columnCount()
{ {
if (! $this->stmt) { return db2_num_fields($this->stmt) ?: 0;
return 0;
}
return db2_num_fields($this->stmt);
} }
/** /**
...@@ -197,10 +189,6 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -197,10 +189,6 @@ class DB2Statement implements IteratorAggregate, Statement
*/ */
public function execute($params = null) public function execute($params = null)
{ {
if (! $this->stmt) {
return false;
}
if ($params === null) { if ($params === null) {
ksort($this->bindParam); ksort($this->bindParam);
......
...@@ -97,16 +97,12 @@ class MysqliStatement implements IteratorAggregate, Statement ...@@ -97,16 +97,12 @@ class MysqliStatement implements IteratorAggregate, Statement
*/ */
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{ {
if ($type === null) { if (! isset(self::$_paramTypeMap[$type])) {
$type = 's'; throw new MysqliException(sprintf("Unknown type: '%s'", $type));
} else {
if (! isset(self::$_paramTypeMap[$type])) {
throw new MysqliException(sprintf("Unknown type: '%s'", $type));
}
$type = self::$_paramTypeMap[$type];
} }
$type = self::$_paramTypeMap[$type];
$this->_bindedValues[$column] =& $variable; $this->_bindedValues[$column] =& $variable;
$this->types[$column - 1] = $type; $this->types[$column - 1] = $type;
...@@ -118,16 +114,12 @@ class MysqliStatement implements IteratorAggregate, Statement ...@@ -118,16 +114,12 @@ class MysqliStatement implements IteratorAggregate, Statement
*/ */
public function bindValue($param, $value, $type = ParameterType::STRING) public function bindValue($param, $value, $type = ParameterType::STRING)
{ {
if ($type === null) { if (! isset(self::$_paramTypeMap[$type])) {
$type = 's'; throw new MysqliException(sprintf("Unknown type: '%s'", $type));
} else {
if (! isset(self::$_paramTypeMap[$type])) {
throw new MysqliException(sprintf("Unknown type: '%s'", $type));
}
$type = self::$_paramTypeMap[$type];
} }
$type = self::$_paramTypeMap[$type];
$this->_values[$param] = $value; $this->_values[$param] = $value;
$this->_bindedValues[$param] =& $this->_values[$param]; $this->_bindedValues[$param] =& $this->_values[$param];
$this->types[$param - 1] = $type; $this->types[$param - 1] = $type;
...@@ -284,7 +276,7 @@ class MysqliStatement implements IteratorAggregate, Statement ...@@ -284,7 +276,7 @@ class MysqliStatement implements IteratorAggregate, Statement
} }
/** /**
* @return mixed[]|false * @return mixed[]|false|null
*/ */
private function _fetch() private function _fetch()
{ {
......
...@@ -144,7 +144,7 @@ abstract class AbstractPlatform ...@@ -144,7 +144,7 @@ abstract class AbstractPlatform
/** /**
* Holds the KeywordList instance for the current platform. * Holds the KeywordList instance for the current platform.
* *
* @var KeywordList * @var KeywordList|null
*/ */
protected $_keywords; protected $_keywords;
...@@ -518,7 +518,7 @@ abstract class AbstractPlatform ...@@ -518,7 +518,7 @@ abstract class AbstractPlatform
/** /**
* Gets the comment of a passed column modified by potential doctrine type comment hints. * Gets the comment of a passed column modified by potential doctrine type comment hints.
* *
* @return string * @return string|null
*/ */
protected function getColumnComment(Column $column) protected function getColumnComment(Column $column)
{ {
...@@ -1610,9 +1610,9 @@ abstract class AbstractPlatform ...@@ -1610,9 +1610,9 @@ abstract class AbstractPlatform
} }
/** /**
* @param string $tableName * @param string $tableName
* @param string $columnName * @param string $columnName
* @param string $comment * @param string|null $comment
* *
* @return string * @return string
*/ */
...@@ -1620,13 +1620,12 @@ abstract class AbstractPlatform ...@@ -1620,13 +1620,12 @@ abstract class AbstractPlatform
{ {
$tableName = new Identifier($tableName); $tableName = new Identifier($tableName);
$columnName = new Identifier($columnName); $columnName = new Identifier($columnName);
$comment = $this->quoteStringLiteral($comment);
return sprintf( return sprintf(
'COMMENT ON COLUMN %s.%s IS %s', 'COMMENT ON COLUMN %s.%s IS %s',
$tableName->getQuotedName($this), $tableName->getQuotedName($this),
$columnName->getQuotedName($this), $columnName->getQuotedName($this),
$comment $this->quoteStringLiteral((string) $comment)
); );
} }
...@@ -2300,7 +2299,7 @@ abstract class AbstractPlatform ...@@ -2300,7 +2299,7 @@ abstract class AbstractPlatform
* Obtains DBMS specific SQL code portion needed to set a CHECK constraint * Obtains DBMS specific SQL code portion needed to set a CHECK constraint
* declaration to be used in statements like CREATE TABLE. * declaration to be used in statements like CREATE TABLE.
* *
* @param mixed[][] $definition The check definition. * @param string[]|mixed[][] $definition The check definition.
* *
* @return string DBMS specific SQL code portion needed to set a CHECK constraint. * @return string DBMS specific SQL code portion needed to set a CHECK constraint.
*/ */
...@@ -3154,7 +3153,7 @@ abstract class AbstractPlatform ...@@ -3154,7 +3153,7 @@ abstract class AbstractPlatform
*/ */
public function supportsForeignKeyOnUpdate() public function supportsForeignKeyOnUpdate()
{ {
return $this->supportsForeignKeyConstraints() && true; return $this->supportsForeignKeyConstraints();
} }
/** /**
......
...@@ -1215,7 +1215,8 @@ SQL ...@@ -1215,7 +1215,8 @@ SQL
*/ */
private function isSerialField(array $field) : bool private function isSerialField(array $field) : bool
{ {
return $field['autoincrement'] ?? false === true && isset($field['type']) return isset($field['type'], $field['autoincrement'])
&& $field['autoincrement'] === true
&& $this->isNumericType($field['type']); && $this->isNumericType($field['type']);
} }
......
...@@ -403,7 +403,7 @@ class QueryBuilder ...@@ -403,7 +403,7 @@ class QueryBuilder
* 'groupBy', 'having' and 'orderBy'. * 'groupBy', 'having' and 'orderBy'.
* *
* @param string $sqlPartName * @param string $sqlPartName
* @param string $sqlPart * @param mixed $sqlPart
* @param bool $append * @param bool $append
* *
* @return $this This QueryBuilder instance. * @return $this This QueryBuilder instance.
......
...@@ -747,14 +747,9 @@ abstract class AbstractSchemaManager ...@@ -747,14 +747,9 @@ abstract class AbstractSchemaManager
protected function _getPortableSequencesList($sequences) protected function _getPortableSequencesList($sequences)
{ {
$list = []; $list = [];
foreach ($sequences as $value) {
$value = $this->_getPortableSequenceDefinition($value);
if (! $value) { foreach ($sequences as $value) {
continue; $list[] = $this->_getPortableSequenceDefinition($value);
}
$list[] = $value;
} }
return $list; return $list;
...@@ -996,14 +991,9 @@ abstract class AbstractSchemaManager ...@@ -996,14 +991,9 @@ abstract class AbstractSchemaManager
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList($tableForeignKeys)
{ {
$list = []; $list = [];
foreach ($tableForeignKeys as $value) {
$value = $this->_getPortableTableForeignKeyDefinition($value);
if (! $value) { foreach ($tableForeignKeys as $value) {
continue; $list[] = $this->_getPortableTableForeignKeyDefinition($value);
}
$list[] = $value;
} }
return $list; return $list;
......
...@@ -18,7 +18,7 @@ class ColumnDiff ...@@ -18,7 +18,7 @@ class ColumnDiff
/** @var string[] */ /** @var string[] */
public $changedProperties = []; public $changedProperties = [];
/** @var Column */ /** @var Column|null */
public $fromColumn; public $fromColumn;
/** /**
......
...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Schema; ...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Schema\Visitor\Visitor;
use function count; use function count;
use function is_numeric;
use function sprintf; use function sprintf;
/** /**
...@@ -66,7 +65,7 @@ class Sequence extends AbstractAsset ...@@ -66,7 +65,7 @@ class Sequence extends AbstractAsset
*/ */
public function setAllocationSize($allocationSize) public function setAllocationSize($allocationSize)
{ {
$this->allocationSize = is_numeric($allocationSize) ? (int) $allocationSize : 1; $this->allocationSize = (int) $allocationSize ?: 1;
return $this; return $this;
} }
...@@ -78,7 +77,7 @@ class Sequence extends AbstractAsset ...@@ -78,7 +77,7 @@ class Sequence extends AbstractAsset
*/ */
public function setInitialValue($initialValue) public function setInitialValue($initialValue)
{ {
$this->initialValue = is_numeric($initialValue) ? (int) $initialValue : 1; $this->initialValue = (int) $initialValue ?: 1;
return $this; return $this;
} }
......
...@@ -77,7 +77,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -77,7 +77,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/ */
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
{ {
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); $tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->addedForeignKeys[] = $foreignKey; $tableDiff->addedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff); $this->alterTable($tableDiff);
...@@ -88,7 +88,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -88,7 +88,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/ */
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
{ {
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); $tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->changedForeignKeys[] = $foreignKey; $tableDiff->changedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff); $this->alterTable($tableDiff);
...@@ -99,7 +99,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -99,7 +99,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/ */
public function dropForeignKey($foreignKey, $table) public function dropForeignKey($foreignKey, $table)
{ {
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); $tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->removedForeignKeys[] = $foreignKey; $tableDiff->removedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff); $this->alterTable($tableDiff);
...@@ -436,11 +436,12 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -436,11 +436,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
* *
* @throws DBALException * @throws DBALException
*/ */
private function getTableDiffForAlterForeignKey(ForeignKeyConstraint $foreignKey, $table) private function getTableDiffForAlterForeignKey($table)
{ {
if (! $table instanceof Table) { if (! $table instanceof Table) {
$tableDetails = $this->tryMethod('listTableDetails', $table); $tableDetails = $this->tryMethod('listTableDetails', $table);
if ($table === false) {
if ($tableDetails === false) {
throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table)); throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table));
} }
......
...@@ -12,7 +12,7 @@ class TableDiff ...@@ -12,7 +12,7 @@ class TableDiff
/** @var string */ /** @var string */
public $name = null; public $name = null;
/** @var string|bool */ /** @var string|false */
public $newName = false; public $newName = false;
/** /**
...@@ -92,7 +92,7 @@ class TableDiff ...@@ -92,7 +92,7 @@ class TableDiff
*/ */
public $removedForeignKeys = []; public $removedForeignKeys = [];
/** @var Table */ /** @var Table|null */
public $fromTable; public $fromTable;
/** /**
...@@ -139,10 +139,14 @@ class TableDiff ...@@ -139,10 +139,14 @@ class TableDiff
} }
/** /**
* @return Identifier|string|bool * @return Identifier|false
*/ */
public function getNewName() public function getNewName()
{ {
return $this->newName ? new Identifier($this->newName) : $this->newName; if ($this->newName === false) {
return false;
}
return new Identifier($this->newName);
} }
} }
...@@ -7,8 +7,6 @@ use Doctrine\DBAL\Sharding\ShardingException; ...@@ -7,8 +7,6 @@ use Doctrine\DBAL\Sharding\ShardingException;
use Doctrine\DBAL\Sharding\ShardManager; use Doctrine\DBAL\Sharding\ShardManager;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use RuntimeException; use RuntimeException;
use function is_bool;
use function is_scalar;
use function sprintf; use function sprintf;
/** /**
...@@ -125,10 +123,6 @@ class SQLAzureShardManager implements ShardManager ...@@ -125,10 +123,6 @@ class SQLAzureShardManager implements ShardManager
throw ShardingException::activeTransaction(); throw ShardingException::activeTransaction();
} }
if ($distributionValue === null || is_bool($distributionValue) || ! is_scalar($distributionValue)) {
throw ShardingException::noShardDistributionValue();
}
$platform = $this->conn->getDatabasePlatform(); $platform = $this->conn->getDatabasePlatform();
$sql = sprintf( $sql = sprintf(
'USE FEDERATION %s (%s = %s) WITH RESET, FILTERING = %s;', 'USE FEDERATION %s (%s = %s) WITH RESET, FILTERING = %s;',
......
parameters: parameters:
level: 3 level: 4
paths: paths:
- %currentWorkingDirectory%/lib - %currentWorkingDirectory%/lib
autoload_files: autoload_files:
......
...@@ -79,18 +79,6 @@ class SQLAzureShardManagerTest extends TestCase ...@@ -79,18 +79,6 @@ class SQLAzureShardManagerTest extends TestCase
self::assertEquals(1234, $sm->getCurrentDistributionValue()); self::assertEquals(1234, $sm->getCurrentDistributionValue());
} }
public function testSelectShardNoDistributionValue()
{
$conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]);
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false));
$this->expectException(ShardingException::class);
$this->expectExceptionMessage('You have to specify a string or integer as shard distribution value.');
$sm = new SQLAzureShardManager($conn);
$sm->selectShard(null);
}
/** /**
* @param mixed[] $params * @param mixed[] $params
*/ */
......
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