Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Table::getForeignKeyColumns()
was removed from 4.0.x around 36522aa without having been deprecated first.The logic of
Table::getPrimaryKeyColumns()
is non-obvious and not documented. If the primary key declares a column but it doesn't exist in the table, the column will be silently skipped. This may lead to a situation where a table has the primary key with no columns, which is not valid.This behavior is relied upon by
AbstractMySQLPlatform::getPreAlterTableAlterIndexForeignKeySQL()
and may make sense but then it should be implemented there.Additionally, using this method requires checking whether the primary key exists first which makes it not as convenient as it may look.
The implementation of
Table::hasPrimaryKey()
is almost identical toTable::getPrimaryKey()
. Normally, the consumer of theTable
API will need not only to know whether the primary key exists but get its columns, so they will end up callingTable::getPrimaryKey()
anyways.From the static analysis point of view, a call to
getPrimaryKey()
will return a nullable value even if a prior call tohasPrimaryKey()
returned true. Making them work together would require additional annotations. See Enable PHPStan strict rules #3932 and Bump Psalm level to 3 #4348 for example.