Skip to content

Commit 1514837

Browse files
committed
Avoid using a null alias as an array offset in getAliases()
Misc::getAliases() built a table-alias map with `$tables[$thisDb][$expr->alias] = $expr->table` for every FROM/JOIN expression. When a table has no alias, `$expr->alias` is null, so this used null as an array offset, which is deprecated as of PHP 8.5. The null-keyed entry was never read back: the only consumer looks up `$tables[$thisDb][$expr->table]`, whose offset is always a non-empty string. Skip expressions without an alias. getAliases() output is unchanged. Removes the now-resolved PossiblyNullArrayOffset baseline entry and adds a regression test.
1 parent 4c45eac commit 1514837

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,9 +1359,6 @@
13591359
<MixedArrayOffset occurrences="1">
13601360
<code>$tables[$thisDb][$expr-&gt;table]</code>
13611361
</MixedArrayOffset>
1362-
<PossiblyNullArrayOffset occurrences="1">
1363-
<code>$tables[$thisDb]</code>
1364-
</PossiblyNullArrayOffset>
13651362
</file>
13661363
<file src="src/Utils/Query.php">
13671364
<InvalidNullableReturnType occurrences="1">

src/Utils/Misc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public static function getAliases($statement, $database)
6868
];
6969
}
7070

71+
if (null === $expr->alias || $expr->alias === '') {
72+
continue;
73+
}
74+
7175
if (! isset($tables[$thisDb])) {
7276
$tables[$thisDb] = [];
7377
}

tests/Utils/MiscTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ public static function getAliasesProvider(): array
132132
],
133133
],
134134
],
135+
[
136+
'SELECT mytable.a x, o.b y FROM mytable JOIN other o ON o.id = mytable.id',
137+
'shop',
138+
[
139+
'shop' => [
140+
'alias' => null,
141+
'tables' => [
142+
'mytable' => [
143+
'alias' => null,
144+
'columns' => ['a' => 'x'],
145+
],
146+
'other' => [
147+
'alias' => 'o',
148+
'columns' => ['b' => 'y'],
149+
],
150+
],
151+
],
152+
],
153+
],
135154
];
136155
}
137156
}

0 commit comments

Comments
 (0)