From 9f9066a0af6f6d7ae8755c51c815c49dc1a99f77 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Mon, 2 Dec 2024 13:08:52 +0000 Subject: [PATCH] Fix crash when SELECT with CASE is executed Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 18 ------------------ psalm-baseline.xml | 6 ------ src/UniqueCondition.php | 16 +++++++++------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 324e99b53f..f85fa313bc 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8217,12 +8217,6 @@ parameters: count: 1 path: src/Display/Results.php - - - message: '#^Parameter \#5 \$expressions of class PhpMyAdmin\\UniqueCondition constructor expects array\, array\ given\.$#' - identifier: argument.type - count: 2 - path: src/Display/Results.php - - message: '#^Parameter \#5 \$sortDirection of method PhpMyAdmin\\Display\\Results\:\:getSingleAndMultiSortUrls\(\) expects array\, array\ given\.$#' identifier: argument.type @@ -8247,12 +8241,6 @@ parameters: count: 1 path: src/Display/Results.php - - - message: '#^Parameter \$expressions of class PhpMyAdmin\\UniqueCondition constructor expects array\, array\ given\.$#' - identifier: argument.type - count: 1 - path: src/Display/Results.php - - message: '#^Property PhpMyAdmin\\Display\\Results\:\:\$unlimNumRows \(int\|numeric\-string\|false\) is never assigned false so it can be removed from the property type\.$#' identifier: property.unusedType @@ -18876,12 +18864,6 @@ parameters: count: 1 path: src/UniqueCondition.php - - - message: '#^Only booleans are allowed in &&, bool\|string given on the left side\.$#' - identifier: booleanAnd.leftNotBoolean - count: 1 - path: src/UniqueCondition.php - - message: '#^Parameter \#1 \$row of method PhpMyAdmin\\UniqueCondition\:\:getConditionValue\(\) expects float\|int\|string\|null, mixed given\.$#' identifier: argument.type diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 0bc3e6961a..3923864bf1 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4863,9 +4863,6 @@ - - - @@ -10988,9 +10985,6 @@ - - - diff --git a/src/UniqueCondition.php b/src/UniqueCondition.php index 9191024c50..b1810e1141 100644 --- a/src/UniqueCondition.php +++ b/src/UniqueCondition.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin; +use PhpMyAdmin\SqlParser\Components\CaseExpression; use PhpMyAdmin\SqlParser\Components\Expression; use function bin2hex; @@ -23,18 +24,18 @@ class UniqueCondition /** * Function to generate unique condition for specified row. * - * @param FieldMetadata[] $fieldsMeta meta information about fields - * @param array $row current row - * @param bool $forceUnique generate condition only on pk or unique - * @param string|bool $restrictToTable restrict the unique condition to this table or false if none - * @param Expression[] $expressions An array of Expression instances. + * @param FieldMetadata[] $fieldsMeta meta information about fields + * @param array $row current row + * @param bool $forceUnique generate condition only on pk or unique + * @param string $restrictToTable restrict the unique condition to this table + * @param (Expression|CaseExpression)[] $expressions An array of Expression instances. * @psalm-param array $row */ public function __construct( array $fieldsMeta, array $row, bool $forceUnique = false, - string|bool $restrictToTable = false, + string $restrictToTable = '', array $expressions = [], ) { $fieldsCount = count($fieldsMeta); @@ -54,6 +55,7 @@ class UniqueCondition foreach ($expressions as $expression) { if ( $expression->alias === null || $expression->alias === '' + || $expression instanceof CaseExpression || $expression->column === null || $expression->column === '' ) { continue; @@ -84,7 +86,7 @@ class UniqueCondition // If this field is not from the table which the unique clause needs // to be restricted to. - if ($restrictToTable && $restrictToTable != $meta->table) { + if ($restrictToTable !== '' && $restrictToTable != $meta->table) { continue; }