PHPStan Level 4

parent b90d6324
......@@ -149,7 +149,7 @@ class Connection implements DriverConnection
/**
* The schema manager.
*
* @var AbstractSchemaManager
* @var AbstractSchemaManager|null
*/
protected $_schemaManager;
......@@ -1446,7 +1446,7 @@ class Connection implements DriverConnection
*/
public function getSchemaManager()
{
if (! $this->_schemaManager) {
if ($this->_schemaManager === null) {
$this->_schemaManager = $this->_driver->getSchemaManager($this);
}
......
......@@ -133,7 +133,7 @@ class MasterSlaveConnection extends 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.
// 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;
}
......@@ -144,7 +144,7 @@ class MasterSlaveConnection extends Connection
$forceMasterAsSlave = true;
}
if (isset($this->connections[$connectionName]) && $this->connections[$connectionName]) {
if (isset($this->connections[$connectionName])) {
$this->_conn = $this->connections[$connectionName];
if ($forceMasterAsSlave && ! $this->keepSlave) {
......
......@@ -146,10 +146,6 @@ class DB2Statement implements IteratorAggregate, Statement
*/
public function closeCursor()
{
if (! $this->stmt) {
return false;
}
$this->bindParam = [];
if (! db2_free_result($this->stmt)) {
......@@ -166,11 +162,7 @@ class DB2Statement implements IteratorAggregate, Statement
*/
public function columnCount()
{
if (! $this->stmt) {
return 0;
}
return db2_num_fields($this->stmt);
return db2_num_fields($this->stmt) ?: 0;
}
/**
......@@ -197,10 +189,6 @@ class DB2Statement implements IteratorAggregate, Statement
*/
public function execute($params = null)
{
if (! $this->stmt) {
return false;
}
if ($params === null) {
ksort($this->bindParam);
......
......@@ -97,15 +97,11 @@ class MysqliStatement implements IteratorAggregate, Statement
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{
if ($type === null) {
$type = 's';
} else {
if (! isset(self::$_paramTypeMap[$type])) {
throw new MysqliException(sprintf("Unknown type: '%s'", $type));
}
$type = self::$_paramTypeMap[$type];
}
$this->_bindedValues[$column] =& $variable;
$this->types[$column - 1] = $type;
......@@ -118,15 +114,11 @@ class MysqliStatement implements IteratorAggregate, Statement
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if ($type === null) {
$type = 's';
} else {
if (! isset(self::$_paramTypeMap[$type])) {
throw new MysqliException(sprintf("Unknown type: '%s'", $type));
}
$type = self::$_paramTypeMap[$type];
}
$this->_values[$param] = $value;
$this->_bindedValues[$param] =& $this->_values[$param];
......@@ -284,7 +276,7 @@ class MysqliStatement implements IteratorAggregate, Statement
}
/**
* @return mixed[]|false
* @return mixed[]|false|null
*/
private function _fetch()
{
......
......@@ -144,7 +144,7 @@ abstract class AbstractPlatform
/**
* Holds the KeywordList instance for the current platform.
*
* @var KeywordList
* @var KeywordList|null
*/
protected $_keywords;
......@@ -518,7 +518,7 @@ abstract class AbstractPlatform
/**
* Gets the comment of a passed column modified by potential doctrine type comment hints.
*
* @return string
* @return string|null
*/
protected function getColumnComment(Column $column)
{
......@@ -1612,7 +1612,7 @@ abstract class AbstractPlatform
/**
* @param string $tableName
* @param string $columnName
* @param string $comment
* @param string|null $comment
*
* @return string
*/
......@@ -1620,13 +1620,12 @@ abstract class AbstractPlatform
{
$tableName = new Identifier($tableName);
$columnName = new Identifier($columnName);
$comment = $this->quoteStringLiteral($comment);
return sprintf(
'COMMENT ON COLUMN %s.%s IS %s',
$tableName->getQuotedName($this),
$columnName->getQuotedName($this),
$comment
$this->quoteStringLiteral((string) $comment)
);
}
......@@ -2300,7 +2299,7 @@ abstract class AbstractPlatform
* Obtains DBMS specific SQL code portion needed to set a CHECK constraint
* 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.
*/
......@@ -3154,7 +3153,7 @@ abstract class AbstractPlatform
*/
public function supportsForeignKeyOnUpdate()
{
return $this->supportsForeignKeyConstraints() && true;
return $this->supportsForeignKeyConstraints();
}
/**
......
......@@ -1215,7 +1215,8 @@ SQL
*/
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']);
}
......
......@@ -403,7 +403,7 @@ class QueryBuilder
* 'groupBy', 'having' and 'orderBy'.
*
* @param string $sqlPartName
* @param string $sqlPart
* @param mixed $sqlPart
* @param bool $append
*
* @return $this This QueryBuilder instance.
......
......@@ -747,14 +747,9 @@ abstract class AbstractSchemaManager
protected function _getPortableSequencesList($sequences)
{
$list = [];
foreach ($sequences as $value) {
$value = $this->_getPortableSequenceDefinition($value);
if (! $value) {
continue;
}
$list[] = $value;
foreach ($sequences as $value) {
$list[] = $this->_getPortableSequenceDefinition($value);
}
return $list;
......@@ -996,14 +991,9 @@ abstract class AbstractSchemaManager
protected function _getPortableTableForeignKeysList($tableForeignKeys)
{
$list = [];
foreach ($tableForeignKeys as $value) {
$value = $this->_getPortableTableForeignKeyDefinition($value);
if (! $value) {
continue;
}
$list[] = $value;
foreach ($tableForeignKeys as $value) {
$list[] = $this->_getPortableTableForeignKeyDefinition($value);
}
return $list;
......
......@@ -18,7 +18,7 @@ class ColumnDiff
/** @var string[] */
public $changedProperties = [];
/** @var Column */
/** @var Column|null */
public $fromColumn;
/**
......
......@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use function count;
use function is_numeric;
use function sprintf;
/**
......@@ -66,7 +65,7 @@ class Sequence extends AbstractAsset
*/
public function setAllocationSize($allocationSize)
{
$this->allocationSize = is_numeric($allocationSize) ? (int) $allocationSize : 1;
$this->allocationSize = (int) $allocationSize ?: 1;
return $this;
}
......@@ -78,7 +77,7 @@ class Sequence extends AbstractAsset
*/
public function setInitialValue($initialValue)
{
$this->initialValue = is_numeric($initialValue) ? (int) $initialValue : 1;
$this->initialValue = (int) $initialValue ?: 1;
return $this;
}
......
......@@ -77,7 +77,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
{
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->addedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff);
......@@ -88,7 +88,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
{
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->changedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff);
......@@ -99,7 +99,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/
public function dropForeignKey($foreignKey, $table)
{
$tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table);
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->removedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff);
......@@ -436,11 +436,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
*
* @throws DBALException
*/
private function getTableDiffForAlterForeignKey(ForeignKeyConstraint $foreignKey, $table)
private function getTableDiffForAlterForeignKey($table)
{
if (! $table instanceof 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));
}
......
......@@ -12,7 +12,7 @@ class TableDiff
/** @var string */
public $name = null;
/** @var string|bool */
/** @var string|false */
public $newName = false;
/**
......@@ -92,7 +92,7 @@ class TableDiff
*/
public $removedForeignKeys = [];
/** @var Table */
/** @var Table|null */
public $fromTable;
/**
......@@ -139,10 +139,14 @@ class TableDiff
}
/**
* @return Identifier|string|bool
* @return Identifier|false
*/
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;
use Doctrine\DBAL\Sharding\ShardManager;
use Doctrine\DBAL\Types\Type;
use RuntimeException;
use function is_bool;
use function is_scalar;
use function sprintf;
/**
......@@ -125,10 +123,6 @@ class SQLAzureShardManager implements ShardManager
throw ShardingException::activeTransaction();
}
if ($distributionValue === null || is_bool($distributionValue) || ! is_scalar($distributionValue)) {
throw ShardingException::noShardDistributionValue();
}
$platform = $this->conn->getDatabasePlatform();
$sql = sprintf(
'USE FEDERATION %s (%s = %s) WITH RESET, FILTERING = %s;',
......
parameters:
level: 3
level: 4
paths:
- %currentWorkingDirectory%/lib
autoload_files:
......
......@@ -79,18 +79,6 @@ class SQLAzureShardManagerTest extends TestCase
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
*/
......
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