Skip to content

Commit 7bb0e02

Browse files
author
Jamison Bryant
committed
Add null guards for column diff loop in BakeMigrationDiffCommand
Use early-continue pattern to narrow nullable safeGetColumn() return types before array operations, fixing PHPStan level 8 errors.
1 parent fd66adf commit 7bb0e02

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/Command/BakeMigrationDiffCommand.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,23 +279,27 @@ protected function getColumns(): void
279279
// changes in columns meta-data
280280
foreach ($currentColumns as $columnName) {
281281
$column = $this->safeGetColumn($currentSchema, $columnName);
282+
if ($column === null) {
283+
continue;
284+
}
285+
286+
if (!in_array($columnName, $oldColumns, true)) {
287+
continue;
288+
}
289+
282290
$oldColumn = $this->safeGetColumn($this->dumpSchema[$table], $columnName);
291+
if ($oldColumn === null) {
292+
continue;
293+
}
294+
283295
unset(
284296
$column['collate'],
285297
$column['fixed'],
298+
$oldColumn['collate'],
299+
$oldColumn['fixed'],
286300
);
287-
if ($oldColumn !== null) {
288-
unset(
289-
$oldColumn['collate'],
290-
$oldColumn['fixed'],
291-
);
292-
}
293301

294-
if (
295-
in_array($columnName, $oldColumns, true) &&
296-
$oldColumn !== null &&
297-
$column !== $oldColumn
298-
) {
302+
if ($column !== $oldColumn) {
299303
$changedAttributes = array_diff_assoc($column, $oldColumn);
300304

301305
foreach (['type', 'length', 'null', 'default'] as $attribute) {

0 commit comments

Comments
 (0)