Unverified Commit ab424a1d authored by Sergei Morozov's avatar Sergei Morozov

Merge pull request #3562 from morozov/platform-types

Enforced parameter and return value types in Platform classes
parents c30aac35 a3e53e97
......@@ -83,7 +83,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
{
$params = $conn->getParams();
return $params['path'] ?? null;
return $params['path'] ?? '';
}
/**
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ class DB2Keywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'DB2';
}
......@@ -20,7 +20,7 @@ class DB2Keywords extends KeywordList
/**
* {@inheritdoc}
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ACTIVATE',
......
......@@ -18,12 +18,8 @@ abstract class KeywordList
/**
* Checks if the given word is a keyword of this dialect/vendor platform.
*
* @param string $word
*
* @return bool
*/
public function isKeyword($word)
public function isKeyword(string $word) : bool
{
if ($this->keywords === null) {
$this->initializeKeywords();
......@@ -32,10 +28,7 @@ abstract class KeywordList
return isset($this->keywords[strtoupper($word)]);
}
/**
* @return void
*/
protected function initializeKeywords()
protected function initializeKeywords() : void
{
$this->keywords = array_flip(array_map('strtoupper', $this->getKeywords()));
}
......@@ -45,12 +38,10 @@ abstract class KeywordList
*
* @return string[]
*/
abstract protected function getKeywords();
abstract protected function getKeywords() : array;
/**
* Returns the name of this keyword list.
*
* @return string
*/
abstract public function getName();
abstract public function getName() : string;
}
......@@ -12,7 +12,7 @@ class MySQL57Keywords extends MySQLKeywords
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'MySQL57';
}
......@@ -22,7 +22,7 @@ class MySQL57Keywords extends MySQLKeywords
*
* @link http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-7.html
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ACCESSIBLE',
......
......@@ -14,7 +14,7 @@ class MySQL80Keywords extends MySQL57Keywords
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'MySQL80';
}
......@@ -24,7 +24,7 @@ class MySQL80Keywords extends MySQL57Keywords
*
* @link https://dev.mysql.com/doc/refman/8.0/en/keywords.html
*/
protected function getKeywords()
protected function getKeywords() : array
{
$keywords = parent::getKeywords();
......
......@@ -12,7 +12,7 @@ class MySQLKeywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'MySQL';
}
......@@ -20,7 +20,7 @@ class MySQLKeywords extends KeywordList
/**
* {@inheritdoc}
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ACCESSIBLE',
......
......@@ -12,7 +12,7 @@ class OracleKeywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'Oracle';
}
......@@ -20,7 +20,7 @@ class OracleKeywords extends KeywordList
/**
* {@inheritdoc}
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ACCESS',
......
......@@ -15,7 +15,7 @@ class PostgreSQL94Keywords extends PostgreSQLKeywords
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'PostgreSQL94';
}
......@@ -25,7 +25,7 @@ class PostgreSQL94Keywords extends PostgreSQLKeywords
*
* @link http://www.postgresql.org/docs/9.4/static/sql-keywords-appendix.html
*/
protected function getKeywords()
protected function getKeywords() : array
{
$parentKeywords = array_diff(parent::getKeywords(), ['OVER']);
......
......@@ -12,7 +12,7 @@ class PostgreSQLKeywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'PostgreSQL';
}
......@@ -20,7 +20,7 @@ class PostgreSQLKeywords extends KeywordList
/**
* {@inheritdoc}
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ALL',
......
......@@ -33,17 +33,15 @@ class ReservedKeywordsValidator implements Visitor
/**
* @return string[]
*/
public function getViolations()
public function getViolations() : array
{
return $this->violations;
}
/**
* @param string $word
*
* @return string[]
*/
private function isReservedWord($word)
private function isReservedWord(string $word) : array
{
if ($word[0] === '`') {
$word = str_replace('`', '', $word);
......@@ -62,12 +60,9 @@ class ReservedKeywordsValidator implements Visitor
}
/**
* @param string $asset
* @param string[] $violatedPlatforms
*
* @return void
*/
private function addViolation($asset, $violatedPlatforms)
private function addViolation(string $asset, array $violatedPlatforms) : void
{
if (! $violatedPlatforms) {
return;
......@@ -79,7 +74,7 @@ class ReservedKeywordsValidator implements Visitor
/**
* {@inheritdoc}
*/
public function acceptColumn(Table $table, Column $column)
public function acceptColumn(Table $table, Column $column) : void
{
$this->addViolation(
'Table ' . $table->getName() . ' column ' . $column->getName(),
......@@ -90,35 +85,35 @@ class ReservedKeywordsValidator implements Visitor
/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
}
/**
* {@inheritdoc}
*/
public function acceptIndex(Table $table, Index $index)
public function acceptIndex(Table $table, Index $index) : void
{
}
/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : void
{
}
/**
* {@inheritdoc}
*/
public function acceptSequence(Sequence $sequence)
public function acceptSequence(Sequence $sequence) : void
{
}
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
$this->addViolation(
'Table ' . $table->getName(),
......
......@@ -12,7 +12,7 @@ class SQLAnywhereKeywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'SQLAnywhere';
}
......@@ -22,7 +22,7 @@ class SQLAnywhereKeywords extends KeywordList
*
* @link http://infocenter.sybase.com/help/topic/com.sybase.dbrfen10/pdf/dbrfen10.pdf?noframes=true
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ADD',
......
......@@ -16,7 +16,7 @@ class SQLServer2012Keywords extends SQLServerKeywords
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'SQLServer2012';
}
......@@ -26,7 +26,7 @@ class SQLServer2012Keywords extends SQLServerKeywords
*
* @link http://msdn.microsoft.com/en-us/library/ms189822.aspx
*/
protected function getKeywords()
protected function getKeywords() : array
{
return array_merge(parent::getKeywords(), [
'SEMANTICKEYPHRASETABLE',
......
......@@ -14,7 +14,7 @@ class SQLServerKeywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'SQLServer';
}
......@@ -24,7 +24,7 @@ class SQLServerKeywords extends KeywordList
*
* @link http://msdn.microsoft.com/en-us/library/aa238507%28v=sql.80%29.aspx
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ADD',
......
......@@ -12,7 +12,7 @@ class SQLiteKeywords extends KeywordList
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return 'SQLite';
}
......@@ -20,7 +20,7 @@ class SQLiteKeywords extends KeywordList
/**
* {@inheritdoc}
*/
protected function getKeywords()
protected function getKeywords() : array
{
return [
'ABORT',
......
......@@ -16,7 +16,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
public function hasNativeJsonType()
public function hasNativeJsonType() : bool
{
return true;
}
......@@ -24,7 +24,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
public function getJsonTypeDeclarationSQL(array $field)
public function getJsonTypeDeclarationSQL(array $field) : string
{
return 'JSON';
}
......@@ -32,7 +32,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff)
protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff) : array
{
return [];
}
......@@ -40,7 +40,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff)
protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff) : array
{
return [];
}
......@@ -48,7 +48,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
protected function getRenameIndexSQL(string $oldIndexName, Index $index, string $tableName) : array
{
return ['ALTER TABLE ' . $tableName . ' RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this)];
}
......@@ -56,7 +56,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
protected function getReservedKeywordsClass()
protected function getReservedKeywordsClass() : string
{
return Keywords\MySQL57Keywords::class;
}
......@@ -64,7 +64,7 @@ class MySQL57Platform extends MySqlPlatform
/**
* {@inheritdoc}
*/
protected function initializeDoctrineTypeMappings()
protected function initializeDoctrineTypeMappings() : void
{
parent::initializeDoctrineTypeMappings();
......
......@@ -12,7 +12,7 @@ class MySQL80Platform extends MySQL57Platform
/**
* {@inheritdoc}
*/
protected function getReservedKeywordsClass()
protected function getReservedKeywordsClass() : string
{
return Keywords\MySQL80Keywords::class;
}
......
......@@ -19,7 +19,7 @@ class PostgreSQL100Platform extends PostgreSQL94Platform
return PostgreSQL100Keywords::class;
}
public function getListSequencesSQL($database) : string
public function getListSequencesSQL(string $database) : string
{
return 'SELECT sequence_name AS relname,
sequence_schema AS schemaname,
......
......@@ -13,8 +13,10 @@ class PostgreSQL94Platform extends PostgreSqlPlatform
{
/**
* {@inheritdoc}
*
* @return string
*/
public function getJsonTypeDeclarationSQL(array $field)
public function getJsonTypeDeclarationSQL(array $field) : string
{
if (! empty($field['jsonb'])) {
return 'JSONB';
......@@ -26,7 +28,7 @@ class PostgreSQL94Platform extends PostgreSqlPlatform
/**
* {@inheritdoc}
*/
protected function getReservedKeywordsClass()
protected function getReservedKeywordsClass() : string
{
return Keywords\PostgreSQL94Keywords::class;
}
......@@ -34,7 +36,7 @@ class PostgreSQL94Platform extends PostgreSqlPlatform
/**
* {@inheritdoc}
*/
protected function initializeDoctrineTypeMappings()
protected function initializeDoctrineTypeMappings() : void
{
parent::initializeDoctrineTypeMappings();
......
......@@ -18,7 +18,7 @@ class SQLAzurePlatform extends SQLServerPlatform
/**
* {@inheritDoc}
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
public function getCreateTableSQL(Table $table, int $createFlags = self::CREATE_INDEXES) : array
{
$sql = parent::getCreateTableSQL($table, $createFlags);
......
......@@ -22,7 +22,7 @@ class SQLServer2012Platform extends SQLServerPlatform
/**
* {@inheritdoc}
*/
public function getAlterSequenceSQL(Sequence $sequence)
public function getAlterSequenceSQL(Sequence $sequence) : string
{
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) .
' INCREMENT BY ' . $sequence->getAllocationSize();
......@@ -31,7 +31,7 @@ class SQLServer2012Platform extends SQLServerPlatform
/**
* {@inheritdoc}
*/
public function getCreateSequenceSQL(Sequence $sequence)
public function getCreateSequenceSQL(Sequence $sequence) : string
{
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
' START WITH ' . $sequence->getInitialValue() .
......@@ -42,7 +42,7 @@ class SQLServer2012Platform extends SQLServerPlatform
/**
* {@inheritdoc}
*/
public function getDropSequenceSQL($sequence)
public function getDropSequenceSQL($sequence) : string
{
if ($sequence instanceof Sequence) {
$sequence = $sequence->getQuotedName($this);
......@@ -54,7 +54,7 @@ class SQLServer2012Platform extends SQLServerPlatform
/**
* {@inheritdoc}
*/
public function getListSequencesSQL($database)
public function getListSequencesSQL(string $database) : string
{
return 'SELECT seq.name,
CAST(
......@@ -69,7 +69,7 @@ class SQLServer2012Platform extends SQLServerPlatform
/**
* {@inheritdoc}
*/
public function getSequenceNextValSQL($sequenceName)
public function getSequenceNextValSQL(string $sequenceName) : string
{
return 'SELECT NEXT VALUE FOR ' . $sequenceName;
}
......@@ -77,7 +77,7 @@ class SQLServer2012Platform extends SQLServerPlatform
/**
* {@inheritdoc}
*/
public function supportsSequences()
public function supportsSequences() : bool
{
return true;
}
......@@ -87,7 +87,7 @@ class SQLServer2012Platform extends SQLServerPlatform
*
* Returns Microsoft SQL Server 2012 specific keywords class
*/
protected function getReservedKeywordsClass()
protected function getReservedKeywordsClass() : string
{
return Keywords\SQLServer2012Keywords::class;
}
......
......@@ -26,6 +26,14 @@ class DriverTest extends AbstractDriverTest
$this->markTestSkipped('pdo_sqlite only test.');
}
/**
* {@inheritdoc}
*/
public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void
{
$this->markTestSkipped('SQLite does not support the concept of a database.');
}
/**
* {@inheritdoc}
*/
......
......@@ -1062,12 +1062,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$table = new Table('col_def_lifecycle');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('column1', 'string', ['default' => null]);
$table->addColumn('column2', 'string', ['default' => false]);
$table->addColumn('column3', 'string', ['default' => true]);
$table->addColumn('column4', 'string', ['default' => 0]);
$table->addColumn('column5', 'string', ['default' => '']);
$table->addColumn('column6', 'string', ['default' => 'def']);
$table->addColumn('column7', 'integer', ['default' => 0]);
$table->addColumn('column2', 'string', ['default' => '']);
$table->addColumn('column3', 'string', ['default' => 'default1']);
$table->addColumn('column4', 'integer', ['default' => 0]);
$table->setPrimaryKey(['id']);
$this->schemaManager->dropAndCreateTable($table);
......@@ -1077,21 +1074,15 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
self::assertNull($columns['id']->getDefault());
self::assertNull($columns['column1']->getDefault());
self::assertSame('', $columns['column2']->getDefault());
self::assertSame('1', $columns['column3']->getDefault());
self::assertSame('default1', $columns['column3']->getDefault());
self::assertSame('0', $columns['column4']->getDefault());
self::assertSame('', $columns['column5']->getDefault());
self::assertSame('def', $columns['column6']->getDefault());
self::assertSame('0', $columns['column7']->getDefault());
$diffTable = clone $table;
$diffTable->changeColumn('column1', ['default' => false]);
$diffTable->changeColumn('column1', ['default' => '']);
$diffTable->changeColumn('column2', ['default' => null]);
$diffTable->changeColumn('column3', ['default' => false]);
$diffTable->changeColumn('column3', ['default' => 'default2']);
$diffTable->changeColumn('column4', ['default' => null]);
$diffTable->changeColumn('column5', ['default' => false]);
$diffTable->changeColumn('column6', ['default' => 666]);
$diffTable->changeColumn('column7', ['default' => null]);
$comparator = new Comparator();
......@@ -1101,11 +1092,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
self::assertSame('', $columns['column1']->getDefault());
self::assertNull($columns['column2']->getDefault());
self::assertSame('', $columns['column3']->getDefault());
self::assertSame('default2', $columns['column3']->getDefault());
self::assertNull($columns['column4']->getDefault());
self::assertSame('', $columns['column5']->getDefault());
self::assertSame('666', $columns['column6']->getDefault());
self::assertNull($columns['column7']->getDefault());
}
public function testListTableWithBinary() : void
......
......@@ -246,10 +246,10 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
public function testGeneratesForeignKeyCreationSql() : void
{
$fk = new ForeignKeyConstraint(['fk_name_id'], 'other_table', ['id'], '');
$fk = new ForeignKeyConstraint(['fk_name_id'], 'other_table', ['id']);
$sql = $this->platform->getCreateForeignKeySQL($fk, 'test');
self::assertEquals($sql, $this->getGenerateForeignKeySql());
self::assertEquals($this->getGenerateForeignKeySql(), $sql);
}
abstract public function getGenerateForeignKeySql() : string;
......
......@@ -1032,9 +1032,9 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
$tableDiff->changedColumns['col_string'] = new ColumnDiff(
'col_string',
new Column('col_string', Type::getType('string'), ['default' => 666, 'fixed' => true]),
new Column('col_string', Type::getType('string'), ['default' => 'foo', 'fixed' => true]),
['fixed'],
new Column('col_string', Type::getType('string'), ['default' => 666])
new Column('col_string', Type::getType('string'), ['default' => 'foo'])
);
$expected = $this->platform->getAlterTableSQL($tableDiff);
......@@ -1047,7 +1047,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
'ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_FA2CB292 DEFAULT 666 FOR col_int',
'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_2725A6D0',
'ALTER TABLE column_def_change_type ALTER COLUMN col_string NCHAR(255) NOT NULL',
"ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT '666' FOR col_string",
"ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT 'foo' FOR col_string",
]
);
}
......
......@@ -253,8 +253,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
{
return [
[null, ''],
[false, ''],
[true, ''],
[LockMode::NONE, ' WITH (NOLOCK)'],
[LockMode::OPTIMISTIC, ''],
[LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'],
......@@ -757,13 +755,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
);
}
public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel() : void
{
$this->expectException(InvalidArgumentException::class);
$this->platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level');
}
public function testModifiesLimitQuery() : void
{
self::assertEquals(
......@@ -916,10 +907,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'SELECT myseq.NEXTVAL',
$this->platform->getSequenceNextValSQL('myseq')
);
self::assertEquals(
'SELECT sequence_name, increment_by, start_with, min_value FROM SYS.SYSSEQUENCE',
$this->platform->getListSequencesSQL(null)
);
}
public function testDoesNotSupportInlineColumnComments() : void
......
......@@ -45,8 +45,6 @@ class SQLServerPlatformTest extends AbstractSQLServerPlatformTestCase
{
return [
[null, ''],
[false, ''],
[true, ''],
[LockMode::NONE, ' WITH (NOLOCK)'],
[LockMode::OPTIMISTIC, ''],
[LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'],
......
......@@ -688,7 +688,7 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
protected static function getInlineColumnEmptyCommentSQL() : string
{
return "--\n";
return '';
}
/**
......
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