Skip to content

Commit f28d82f

Browse files
Merge pull request #19415 from kamil-tekiela/SELECT-with-CASE-crash
Fix crash when SELECT with CASE is executed Fixes #19328
2 parents c5d6cd5 + 9f9066a commit f28d82f

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8337,12 +8337,6 @@ parameters:
83378337
count: 1
83388338
path: src/Display/Results.php
83398339

8340-
-
8341-
message: '#^Parameter \#5 \$expressions of class PhpMyAdmin\\UniqueCondition constructor expects array\<PhpMyAdmin\\SqlParser\\Components\\Expression\>, array\<PhpMyAdmin\\SqlParser\\Components\\CaseExpression\|PhpMyAdmin\\SqlParser\\Components\\Expression\> given\.$#'
8342-
identifier: argument.type
8343-
count: 2
8344-
path: src/Display/Results.php
8345-
83468340
-
83478341
message: '#^Parameter \#5 \$sortDirection of method PhpMyAdmin\\Display\\Results\:\:getSingleAndMultiSortUrls\(\) expects array\<string\>, array\<mixed\> given\.$#'
83488342
identifier: argument.type
@@ -8367,12 +8361,6 @@ parameters:
83678361
count: 1
83688362
path: src/Display/Results.php
83698363

8370-
-
8371-
message: '#^Parameter \$expressions of class PhpMyAdmin\\UniqueCondition constructor expects array\<PhpMyAdmin\\SqlParser\\Components\\Expression\>, array\<PhpMyAdmin\\SqlParser\\Components\\CaseExpression\|PhpMyAdmin\\SqlParser\\Components\\Expression\> given\.$#'
8372-
identifier: argument.type
8373-
count: 1
8374-
path: src/Display/Results.php
8375-
83768364
-
83778365
message: '#^Property PhpMyAdmin\\Display\\Results\:\:\$unlimNumRows \(int\|numeric\-string\|false\) is never assigned false so it can be removed from the property type\.$#'
83788366
identifier: property.unusedType
@@ -18990,12 +18978,6 @@ parameters:
1899018978
count: 1
1899118979
path: src/UniqueCondition.php
1899218980

18993-
-
18994-
message: '#^Only booleans are allowed in &&, bool\|string given on the left side\.$#'
18995-
identifier: booleanAnd.leftNotBoolean
18996-
count: 1
18997-
path: src/UniqueCondition.php
18998-
1899918981
-
1900018982
message: '#^Parameter \#1 \$row of method PhpMyAdmin\\UniqueCondition\:\:getConditionValue\(\) expects float\|int\|string\|null, mixed given\.$#'
1900118983
identifier: argument.type

psalm-baseline.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4863,9 +4863,6 @@
48634863
</file>
48644864
<file src="src/Display/Results.php">
48654865
<InvalidArgument>
4866-
<code><![CDATA[$expressions]]></code>
4867-
<code><![CDATA[$expressions]]></code>
4868-
<code><![CDATA[$expressions]]></code>
48694866
<code><![CDATA[$linkingUrlParams]]></code>
48704867
<code><![CDATA[$linkingUrlParams]]></code>
48714868
<code><![CDATA[$sortExpressionNoDirection]]></code>
@@ -10988,9 +10985,6 @@
1098810985
<MixedArrayTypeCoercion>
1098910986
<code><![CDATA[$row[$i]]]></code>
1099010987
</MixedArrayTypeCoercion>
10991-
<RiskyTruthyFalsyComparison>
10992-
<code><![CDATA[$restrictToTable]]></code>
10993-
</RiskyTruthyFalsyComparison>
1099410988
</file>
1099510989
<file src="src/Url.php">
1099610990
<DeprecatedMethod>

src/UniqueCondition.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin;
66

7+
use PhpMyAdmin\SqlParser\Components\CaseExpression;
78
use PhpMyAdmin\SqlParser\Components\Expression;
89

910
use function bin2hex;
@@ -23,18 +24,18 @@ class UniqueCondition
2324
/**
2425
* Function to generate unique condition for specified row.
2526
*
26-
* @param FieldMetadata[] $fieldsMeta meta information about fields
27-
* @param array $row current row
28-
* @param bool $forceUnique generate condition only on pk or unique
29-
* @param string|bool $restrictToTable restrict the unique condition to this table or false if none
30-
* @param Expression[] $expressions An array of Expression instances.
27+
* @param FieldMetadata[] $fieldsMeta meta information about fields
28+
* @param array $row current row
29+
* @param bool $forceUnique generate condition only on pk or unique
30+
* @param string $restrictToTable restrict the unique condition to this table
31+
* @param (Expression|CaseExpression)[] $expressions An array of Expression instances.
3132
* @psalm-param array<int, mixed> $row
3233
*/
3334
public function __construct(
3435
array $fieldsMeta,
3536
array $row,
3637
bool $forceUnique = false,
37-
string|bool $restrictToTable = false,
38+
string $restrictToTable = '',
3839
array $expressions = [],
3940
) {
4041
$fieldsCount = count($fieldsMeta);
@@ -54,6 +55,7 @@ public function __construct(
5455
foreach ($expressions as $expression) {
5556
if (
5657
$expression->alias === null || $expression->alias === ''
58+
|| $expression instanceof CaseExpression
5759
|| $expression->column === null || $expression->column === ''
5860
) {
5961
continue;
@@ -84,7 +86,7 @@ public function __construct(
8486

8587
// If this field is not from the table which the unique clause needs
8688
// to be restricted to.
87-
if ($restrictToTable && $restrictToTable != $meta->table) {
89+
if ($restrictToTable !== '' && $restrictToTable != $meta->table) {
8890
continue;
8991
}
9092

0 commit comments

Comments
 (0)