Commit 8b373f4a authored by Benjamin Morel's avatar Benjamin Morel

Fix phpstan errors

parent 489cb9eb
...@@ -49,7 +49,7 @@ final class ArrayStatement implements IteratorAggregate, ResultStatement ...@@ -49,7 +49,7 @@ final class ArrayStatement implements IteratorAggregate, ResultStatement
*/ */
public function closeCursor() : void public function closeCursor() : void
{ {
$this->data = null; $this->data = [];
} }
/** /**
...@@ -65,10 +65,6 @@ final class ArrayStatement implements IteratorAggregate, ResultStatement ...@@ -65,10 +65,6 @@ final class ArrayStatement implements IteratorAggregate, ResultStatement
*/ */
public function rowCount() : int public function rowCount() : int
{ {
if ($this->data === null) {
return 0;
}
return count($this->data); return count($this->data);
} }
......
...@@ -1264,6 +1264,8 @@ class Connection implements DriverConnection ...@@ -1264,6 +1264,8 @@ class Connection implements DriverConnection
{ {
$this->connect(); $this->connect();
assert($this->_conn !== null);
return $this->_conn; return $this->_conn;
} }
......
...@@ -688,7 +688,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -688,7 +688,7 @@ class SqlitePlatform extends AbstractPlatform
*/ */
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array
{ {
if (! $diff->fromTable instanceof Table) { if ($diff->fromTable === null) {
throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema.'); throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema.');
} }
...@@ -699,7 +699,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -699,7 +699,7 @@ class SqlitePlatform extends AbstractPlatform
$tableName = $diff->getName($this); $tableName = $diff->getName($this);
} }
foreach ($this->getIndexesInAlteredTable($diff) as $index) { foreach ($this->getIndexesInAlteredTable($diff, $diff->fromTable) as $index) {
if ($index->isPrimary()) { if ($index->isPrimary()) {
continue; continue;
} }
...@@ -823,7 +823,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -823,7 +823,7 @@ class SqlitePlatform extends AbstractPlatform
} }
$fromTable = $diff->fromTable; $fromTable = $diff->fromTable;
if (! $fromTable instanceof Table) { if ($fromTable === null) {
throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema.'); throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema.');
} }
...@@ -908,7 +908,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -908,7 +908,7 @@ class SqlitePlatform extends AbstractPlatform
if (! $this->onSchemaAlterTable($diff, $tableSql)) { if (! $this->onSchemaAlterTable($diff, $tableSql)) {
$dataTable = new Table('__temp__' . $table->getName()); $dataTable = new Table('__temp__' . $table->getName());
$newTable = new Table($table->getQuotedName($this), $columns, $this->getPrimaryIndexInAlteredTable($diff), [], $this->getForeignKeysInAlteredTable($diff), $table->getOptions()); $newTable = new Table($table->getQuotedName($this), $columns, $this->getPrimaryIndexInAlteredTable($diff, $fromTable), [], $this->getForeignKeysInAlteredTable($diff, $fromTable), $table->getOptions());
$newTable->addOption('alter', true); $newTable->addOption('alter', true);
$sql = $this->getPreAlterTableIndexForeignKeySQL($diff); $sql = $this->getPreAlterTableIndexForeignKeySQL($diff);
...@@ -1016,11 +1016,11 @@ class SqlitePlatform extends AbstractPlatform ...@@ -1016,11 +1016,11 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @return string[] * @return string[]
*/ */
private function getColumnNamesInAlteredTable(TableDiff $diff) : array private function getColumnNamesInAlteredTable(TableDiff $diff, Table $fromTable) : array
{ {
$columns = []; $columns = [];
foreach ($diff->fromTable->getColumns() as $columnName => $column) { foreach ($fromTable->getColumns() as $columnName => $column) {
$columns[strtolower($columnName)] = $column->getName(); $columns[strtolower($columnName)] = $column->getName();
} }
...@@ -1056,10 +1056,10 @@ class SqlitePlatform extends AbstractPlatform ...@@ -1056,10 +1056,10 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @return Index[] * @return Index[]
*/ */
private function getIndexesInAlteredTable(TableDiff $diff) : array private function getIndexesInAlteredTable(TableDiff $diff, Table $fromTable) : array
{ {
$indexes = $diff->fromTable->getIndexes(); $indexes = $fromTable->getIndexes();
$columnNames = $this->getColumnNamesInAlteredTable($diff); $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable);
foreach ($indexes as $key => $index) { foreach ($indexes as $key => $index) {
foreach ($diff->renamedIndexes as $oldIndexName => $renamedIndex) { foreach ($diff->renamedIndexes as $oldIndexName => $renamedIndex) {
...@@ -1120,10 +1120,10 @@ class SqlitePlatform extends AbstractPlatform ...@@ -1120,10 +1120,10 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @return ForeignKeyConstraint[] * @return ForeignKeyConstraint[]
*/ */
private function getForeignKeysInAlteredTable(TableDiff $diff) : array private function getForeignKeysInAlteredTable(TableDiff $diff, Table $fromTable) : array
{ {
$foreignKeys = $diff->fromTable->getForeignKeys(); $foreignKeys = $fromTable->getForeignKeys();
$columnNames = $this->getColumnNamesInAlteredTable($diff); $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable);
foreach ($foreignKeys as $key => $constraint) { foreach ($foreignKeys as $key => $constraint) {
$changed = false; $changed = false;
...@@ -1180,11 +1180,11 @@ class SqlitePlatform extends AbstractPlatform ...@@ -1180,11 +1180,11 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @return Index[] * @return Index[]
*/ */
private function getPrimaryIndexInAlteredTable(TableDiff $diff) : array private function getPrimaryIndexInAlteredTable(TableDiff $diff, Table $fromTable) : array
{ {
$primaryIndex = []; $primaryIndex = [];
foreach ($this->getIndexesInAlteredTable($diff) as $index) { foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) {
if (! $index->isPrimary()) { if (! $index->isPrimary()) {
continue; continue;
} }
......
...@@ -35,7 +35,7 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -35,7 +35,7 @@ class Connection extends \Doctrine\DBAL\Connection
/** @var int */ /** @var int */
private $portability = self::PORTABILITY_NONE; private $portability = self::PORTABILITY_NONE;
/** @var int */ /** @var int|null */
private $case; private $case;
/** /**
......
...@@ -26,7 +26,7 @@ final class Statement implements IteratorAggregate, DriverStatement ...@@ -26,7 +26,7 @@ final class Statement implements IteratorAggregate, DriverStatement
/** @var DriverStatement|ResultStatement */ /** @var DriverStatement|ResultStatement */
private $stmt; private $stmt;
/** @var int */ /** @var int|null */
private $case; private $case;
/** @var int */ /** @var int */
...@@ -204,6 +204,7 @@ final class Statement implements IteratorAggregate, DriverStatement ...@@ -204,6 +204,7 @@ final class Statement implements IteratorAggregate, DriverStatement
} }
if ($fixCase) { if ($fixCase) {
assert($this->case !== null);
$row = array_change_key_case($row, $this->case); $row = array_change_key_case($row, $this->case);
} }
......
...@@ -393,9 +393,9 @@ class QueryBuilder ...@@ -393,9 +393,9 @@ class QueryBuilder
* Gets the maximum number of results the query object was set to retrieve (the "limit"). * Gets the maximum number of results the query object was set to retrieve (the "limit").
* Returns NULL if {@link setMaxResults} was not applied to this query builder. * Returns NULL if {@link setMaxResults} was not applied to this query builder.
* *
* @return int The maximum number of results. * @return int|null The maximum number of results.
*/ */
public function getMaxResults() : int public function getMaxResults() : ?int
{ {
return $this->maxResults; return $this->maxResults;
} }
......
...@@ -592,6 +592,8 @@ abstract class AbstractSchemaManager ...@@ -592,6 +592,8 @@ abstract class AbstractSchemaManager
*/ */
protected function _getPortableDatabaseDefinition(array $database) : string protected function _getPortableDatabaseDefinition(array $database) : string
{ {
assert(! empty($database));
return array_shift($database); return array_shift($database);
} }
...@@ -774,6 +776,8 @@ abstract class AbstractSchemaManager ...@@ -774,6 +776,8 @@ abstract class AbstractSchemaManager
*/ */
protected function _getPortableTableDefinition(array $table) : string protected function _getPortableTableDefinition(array $table) : string
{ {
assert(! empty($table));
return array_shift($table); return array_shift($table);
} }
......
...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; ...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Platforms\MySqlPlatform;
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_shift;
use function array_values; use function array_values;
use function assert; use function assert;
use function explode; use function explode;
...@@ -53,14 +52,6 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -53,14 +52,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']); return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']);
} }
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition(array $table) : string
{
return array_shift($table);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -36,7 +36,7 @@ parameters: ...@@ -36,7 +36,7 @@ parameters:
- '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array<string>, array<int, int|string> given\.\z~' - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array<string>, array<int, int|string> given\.\z~'
# PHPStan is too strict about preg_replace(): https://phpstan.org/r/993dc99f-0d43-4b51-868b-d01f982c1463 # PHPStan is too strict about preg_replace(): https://phpstan.org/r/993dc99f-0d43-4b51-868b-d01f982c1463
- '~^Method Doctrine\\DBAL\\Platforms\\AbstractPlatform::escapeStringForLike\(\) should return string but returns string|null\.\z~' - '~^Method Doctrine\\DBAL\\Platforms\\AbstractPlatform::escapeStringForLike\(\) should return string but returns string\|null\.\z~'
# legacy variadic-like signature # legacy variadic-like signature
- '~^Method Doctrine\\DBAL(\\.*)?Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' - '~^Method Doctrine\\DBAL(\\.*)?Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~'
......
...@@ -41,8 +41,6 @@ class DefaultValueTest extends DbalFunctionalTestCase ...@@ -41,8 +41,6 @@ class DefaultValueTest extends DbalFunctionalTestCase
} }
/** /**
* @param mixed $expectedDefault
*
* @dataProvider columnProvider * @dataProvider columnProvider
*/ */
public function testEscapedDefaultValueCanBeIntrospected(string $name, ?string $expectedDefault) : void public function testEscapedDefaultValueCanBeIntrospected(string $name, ?string $expectedDefault) : void
...@@ -58,8 +56,6 @@ class DefaultValueTest extends DbalFunctionalTestCase ...@@ -58,8 +56,6 @@ class DefaultValueTest extends DbalFunctionalTestCase
} }
/** /**
* @param mixed $expectedDefault
*
* @dataProvider columnProvider * @dataProvider columnProvider
*/ */
public function testEscapedDefaultValueCanBeInserted(string $name, ?string $expectedDefault) : void public function testEscapedDefaultValueCanBeInserted(string $name, ?string $expectedDefault) : void
......
...@@ -177,7 +177,10 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -177,7 +177,10 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); self::assertTrue($onlinePrimaryTable->hasColumn('"Id"'));
self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform));
self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); self::assertTrue($onlinePrimaryTable->hasPrimaryKey());
self::assertSame(['"Id"'], $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform));
$onlinePrimaryTablePrimaryKey = $onlinePrimaryTable->getPrimaryKey();
self::assertNotNull($onlinePrimaryTablePrimaryKey);
self::assertSame(['"Id"'], $onlinePrimaryTablePrimaryKey->getQuotedColumns($platform));
self::assertTrue($onlinePrimaryTable->hasColumn('select')); self::assertTrue($onlinePrimaryTable->hasColumn('select'));
self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform));
...@@ -211,7 +214,10 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -211,7 +214,10 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertTrue($onlineForeignTable->hasColumn('id')); self::assertTrue($onlineForeignTable->hasColumn('id'));
self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform));
self::assertTrue($onlineForeignTable->hasPrimaryKey()); self::assertTrue($onlineForeignTable->hasPrimaryKey());
self::assertSame(['ID'], $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform));
$onlineForeignTablePrimaryKey = $onlineForeignTable->getPrimaryKey();
self::assertNotNull($onlineForeignTablePrimaryKey);
self::assertSame(['ID'], $onlineForeignTablePrimaryKey->getQuotedColumns($platform));
self::assertTrue($onlineForeignTable->hasColumn('"Fk"')); self::assertTrue($onlineForeignTable->hasColumn('"Fk"'));
self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform));
......
...@@ -178,11 +178,15 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -178,11 +178,15 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable'); $nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable');
self::assertTrue($nestedSchemaTable->hasColumn('id')); self::assertTrue($nestedSchemaTable->hasColumn('id'));
self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns());
$primaryKey = $nestedSchemaTable->getPrimaryKey();
self::assertNotNull($primaryKey);
self::assertEquals(['id'], $primaryKey->getColumns());
$relatedFks = $nestedSchemaTable->getForeignKeys(); $relatedFks = $nestedSchemaTable->getForeignKeys();
self::assertCount(1, $relatedFks); self::assertCount(1, $relatedFks);
$relatedFk = array_pop($relatedFks); $relatedFk = array_pop($relatedFks);
self::assertNotNull($relatedFk);
self::assertEquals('nested.schemarelated', $relatedFk->getForeignTableName()); self::assertEquals('nested.schemarelated', $relatedFk->getForeignTableName());
} }
......
...@@ -271,7 +271,7 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -271,7 +271,7 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
public function getGenerateForeignKeySql() : string public function getGenerateForeignKeySql() : string
{ {
return null; $this->fail('Foreign key constraints are not yet supported for SQLite.');
} }
public function testModifyLimitQuery() : void public function testModifyLimitQuery() : void
......
...@@ -254,6 +254,7 @@ class ComparatorTest extends TestCase ...@@ -254,6 +254,7 @@ class ComparatorTest extends TestCase
$c = new Comparator(); $c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB); $tableDiff = $c->diffTable($tableA, $tableB);
self::assertNotNull($tableDiff);
self::assertCount(1, $tableDiff->renamedColumns, 'we should have one rename datefield1 => new_datefield1.'); self::assertCount(1, $tableDiff->renamedColumns, 'we should have one rename datefield1 => new_datefield1.');
self::assertArrayHasKey('datefield1', $tableDiff->renamedColumns, "'datefield1' should be set to be renamed to new_datefield1"); self::assertArrayHasKey('datefield1', $tableDiff->renamedColumns, "'datefield1' should be set to be renamed to new_datefield1");
self::assertCount(1, $tableDiff->addedColumns, "'new_datefield2' should be added"); self::assertCount(1, $tableDiff->addedColumns, "'new_datefield2' should be added");
...@@ -723,6 +724,7 @@ class ComparatorTest extends TestCase ...@@ -723,6 +724,7 @@ class ComparatorTest extends TestCase
$c = new Comparator(); $c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB); $tableDiff = $c->diffTable($tableA, $tableB);
self::assertNotNull($tableDiff);
self::assertCount(0, $tableDiff->addedColumns); self::assertCount(0, $tableDiff->addedColumns);
self::assertCount(0, $tableDiff->removedColumns); self::assertCount(0, $tableDiff->removedColumns);
self::assertArrayHasKey('foo', $tableDiff->renamedColumns); self::assertArrayHasKey('foo', $tableDiff->renamedColumns);
...@@ -748,6 +750,7 @@ class ComparatorTest extends TestCase ...@@ -748,6 +750,7 @@ class ComparatorTest extends TestCase
$c = new Comparator(); $c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB); $tableDiff = $c->diffTable($tableA, $tableB);
self::assertNotNull($tableDiff);
self::assertCount(1, $tableDiff->addedColumns, "'baz' should be added, not created through renaming!"); self::assertCount(1, $tableDiff->addedColumns, "'baz' should be added, not created through renaming!");
self::assertArrayHasKey('baz', $tableDiff->addedColumns, "'baz' should be added, not created through renaming!"); self::assertArrayHasKey('baz', $tableDiff->addedColumns, "'baz' should be added, not created through renaming!");
self::assertCount(2, $tableDiff->removedColumns, "'foo' and 'bar' should both be dropped, an ambiguity exists which one could be renamed to 'baz'."); self::assertCount(2, $tableDiff->removedColumns, "'foo' and 'bar' should both be dropped, an ambiguity exists which one could be renamed to 'baz'.");
...@@ -773,6 +776,7 @@ class ComparatorTest extends TestCase ...@@ -773,6 +776,7 @@ class ComparatorTest extends TestCase
$comparator = new Comparator(); $comparator = new Comparator();
$tableDiff = $comparator->diffTable($table1, $table2); $tableDiff = $comparator->diffTable($table1, $table2);
self::assertNotNull($tableDiff);
self::assertCount(0, $tableDiff->addedIndexes); self::assertCount(0, $tableDiff->addedIndexes);
self::assertCount(0, $tableDiff->removedIndexes); self::assertCount(0, $tableDiff->removedIndexes);
self::assertArrayHasKey('idx_foo', $tableDiff->renamedIndexes); self::assertArrayHasKey('idx_foo', $tableDiff->renamedIndexes);
...@@ -801,6 +805,7 @@ class ComparatorTest extends TestCase ...@@ -801,6 +805,7 @@ class ComparatorTest extends TestCase
$comparator = new Comparator(); $comparator = new Comparator();
$tableDiff = $comparator->diffTable($table1, $table2); $tableDiff = $comparator->diffTable($table1, $table2);
self::assertNotNull($tableDiff);
self::assertCount(1, $tableDiff->addedIndexes); self::assertCount(1, $tableDiff->addedIndexes);
self::assertArrayHasKey('idx_baz', $tableDiff->addedIndexes); self::assertArrayHasKey('idx_baz', $tableDiff->addedIndexes);
self::assertCount(2, $tableDiff->removedIndexes); self::assertCount(2, $tableDiff->removedIndexes);
......
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