Skip to content

Commit 7d54ef6

Browse files
committed
Use more specific exception messages
1 parent 8549925 commit 7d54ef6

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/Platforms/AbstractPlatform.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,14 @@ public function getDropTablesSQL(array $tables): array
947947

948948
foreach ($tables as $table) {
949949
foreach ($table->getForeignKeys() as $foreignKey) {
950+
$constraintName = $foreignKey->getObjectName();
951+
952+
if ($constraintName === null) {
953+
throw UnspecifiedConstraintName::forForeignKeyConstraint();
954+
}
955+
950956
$sql[] = $this->getDropForeignKeySQL(
951-
$this->getConstraintName($foreignKey)->toSQL($this),
957+
$constraintName->toSQL($this),
952958
$table->getObjectName()->toSQL($this),
953959
);
954960
}
@@ -2210,15 +2216,4 @@ abstract public function createMetadataProvider(Connection $connection): Metadat
22102216
* database schema according to the dialect of the platform.
22112217
*/
22122218
abstract public function createSchemaManager(Connection $connection): AbstractSchemaManager;
2213-
2214-
private function getConstraintName(ForeignKeyConstraint $constraint): UnqualifiedName
2215-
{
2216-
$name = $constraint->getObjectName();
2217-
2218-
if ($name === null) {
2219-
throw UnspecifiedConstraintName::new();
2220-
}
2221-
2222-
return $name;
2223-
}
22242219
}

src/Platforms/DB2Platform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function getAlterTableSQL(TableDiff $diff): array
273273
$constraintName = $droppedPrimaryKeyConstraint->getObjectName();
274274

275275
if ($constraintName === null) {
276-
throw UnspecifiedConstraintName::new();
276+
throw UnspecifiedConstraintName::forPrimaryKeyConstraint();
277277
}
278278

279279
$sql[] = $this->getDropConstraintSQL($constraintName->toSQL($this), $tableNameSQL);

src/Platforms/OraclePlatform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public function getAlterTableSQL(TableDiff $diff): array
510510
$constraintName = $droppedPrimaryKeyConstraint->getObjectName();
511511

512512
if ($constraintName === null) {
513-
throw UnspecifiedConstraintName::new();
513+
throw UnspecifiedConstraintName::forPrimaryKeyConstraint();
514514
}
515515

516516
$sql[] = $this->getDropConstraintSQL($constraintName->toSQL($this), $tableNameSQL);

src/Platforms/PostgreSQLPlatform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function getAlterTableSQL(TableDiff $diff): array
185185
$constraintName = $droppedPrimaryKeyConstraint->getObjectName();
186186

187187
if ($constraintName === null) {
188-
throw UnspecifiedConstraintName::new();
188+
throw UnspecifiedConstraintName::forPrimaryKeyConstraint();
189189
}
190190

191191
$sql[] = $this->getDropConstraintSQL($constraintName->toSQL($this), $tableNameSQL);

src/Platforms/SQLServerPlatform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public function getAlterTableSQL(TableDiff $diff): array
321321
$constraintName = $droppedPrimaryKeyConstraint->getObjectName();
322322

323323
if ($constraintName === null) {
324-
throw UnspecifiedConstraintName::new();
324+
throw UnspecifiedConstraintName::forPrimaryKeyConstraint();
325325
}
326326

327327
$sql[] = $this->getDropConstraintSQL($constraintName->toSQL($this), $table->getObjectName()->toSQL($this));

src/Schema/Exception/UnspecifiedConstraintName.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99

1010
final class UnspecifiedConstraintName extends InvalidArgumentException implements SchemaException
1111
{
12-
public static function new(): self
12+
public static function forPrimaryKeyConstraint(): self
1313
{
14-
return new self('Constraint name is not specified.');
14+
return new self('Primary key constraint name is not specified.');
15+
}
16+
17+
public static function forForeignKeyConstraint(): self
18+
{
19+
return new self('Foreign key constraint name is not specified.');
1520
}
1621
}

0 commit comments

Comments
 (0)