diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 935f69df02..596f6de39c 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -50,6 +50,7 @@ use function htmlspecialchars_decode; use function implode; use function in_array; use function is_array; +use function is_callable; use function is_object; use function is_string; use function log10; @@ -815,12 +816,12 @@ class Util $timestamp = time(); } - $date = preg_replace( + $date = (string) preg_replace( '@%[aA]@', $day_of_week[(int) strftime('%w', (int) $timestamp)], $format ); - $date = preg_replace( + $date = (string) preg_replace( '@%[bB]@', $month[(int) strftime('%m', (int) $timestamp) - 1], $date @@ -833,14 +834,17 @@ class Util } else { $am_pm = _pgettext('AM/PM indication in time', 'AM'); } - $date = preg_replace('@%[pP]@', $am_pm, $date); + $date = (string) preg_replace('@%[pP]@', $am_pm, $date); // Can return false on windows for Japanese language // See https://github.com/phpmyadmin/phpmyadmin/issues/15830 $ret = strftime($date, (int) $timestamp); // Some OSes such as Win8.1 Traditional Chinese version did not produce UTF-8 // output here. See https://github.com/phpmyadmin/phpmyadmin/issues/10598 - if ($ret === false || mb_detect_encoding($ret, 'UTF-8', true) != 'UTF-8') { + /** @phpstan-ignore-next-line */ + if ($ret === false + || mb_detect_encoding($ret, 'UTF-8', true) !== 'UTF-8' + ) { $ret = date('Y-m-d H:i:s', (int) $timestamp); } @@ -852,9 +856,9 @@ class Util * * @param string $url the URL * - * @return array the parameter/value pairs, for example [0] db=sakila + * @return array the parameter/value pairs, for example [0] db=sakila */ - public static function splitURLQuery($url) + public static function splitURLQuery($url): array { // decode encoded url separators $separator = Url::getArgSeparator(); @@ -869,8 +873,10 @@ class Util $url_parts = parse_url($url); - if (is_array($url_parts) && ! empty($url_parts['query'])) { - return explode($separator, $url_parts['query']); + if (is_array($url_parts) && isset($url_parts['query'])) { + $array = explode($separator, $url_parts['query']); + + return is_array($array) ? $array : []; } return []; @@ -1110,7 +1116,7 @@ class Util $condition = ' ' . $con_key . ' '; [$con_val, $condition] = self::getConditionValue( - ! isset($row[$i]) || $row[$i] === null ? null : $row[$i], + $row[$i] ?? null, $meta, $GLOBALS['dbi']->fieldFlags($handle, $i), $fields_cnt, @@ -1153,7 +1159,7 @@ class Util $clause_is_unique = false; } - $where_clause = trim(preg_replace('|\s?AND$|', '', $preferred_condition)); + $where_clause = trim((string) preg_replace('|\s?AND$|', '', $preferred_condition)); return [ $where_clause, @@ -1562,7 +1568,7 @@ class Util $binary = false; } - $printtype = preg_replace( + $printtype = (string) preg_replace( '@zerofill@', '', $printtype, @@ -1570,7 +1576,7 @@ class Util $zerofill_cnt ); $zerofill = ($zerofill_cnt > 0); - $printtype = preg_replace( + $printtype = (string) preg_replace( '@unsigned@', '', $printtype, @@ -1916,10 +1922,10 @@ class Util foreach ($replace as $key => $val) { if (isset($escape_class, $escape_method)) { $replace[$key] = $escape_class->$escape_method($val); - } else { - $replace[$key] = $escape == 'backquote' - ? self::$escape($val) - : $escape($val); + } elseif ($escape === 'backquote') { + $replace[$key] = self::backquote($val); + } elseif (is_callable($escape)) { + $replace[$key] = $escape($val); } } } @@ -3022,7 +3028,7 @@ class Util while (strlen($result) < $length) { // Get random byte and strip highest bit // to get ASCII only range - $byte = ord($random_func(1)) & 0x7f; + $byte = ord((string) $random_func(1)) & 0x7f; // We want only ASCII chars if ($byte <= 32) { continue; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 604ed1ead4..eefc8a48d4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3320,56 +3320,11 @@ parameters: count: 1 path: libraries/classes/Types.php - - - message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|null given\\.$#" - count: 3 - path: libraries/classes/Util.php - - - - message: "#^Parameter \\#1 \\$format of function strftime expects string, string\\|null given\\.$#" - count: 1 - path: libraries/classes/Util.php - - - - message: "#^Strict comparison using \\=\\=\\= between string and false will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Util.php - - - - message: "#^Method PhpMyAdmin\\\\Util\\:\\:splitURLQuery\\(\\) should return array but returns array\\\\|false\\.$#" - count: 1 - path: libraries/classes/Util.php - - - - message: "#^Offset 'query' does not exist on array\\(\\?'scheme' \\=\\> string, \\?'host' \\=\\> string, \\?'port' \\=\\> int, \\?'user' \\=\\> string, \\?'pass' \\=\\> string, \\?'path' \\=\\> string, \\?'query' \\=\\> string, \\?'fragment' \\=\\> string\\)\\.$#" - count: 1 - path: libraries/classes/Util.php - - - - message: "#^Strict comparison using \\=\\=\\= between mixed and null will always evaluate to false\\.$#" - count: 1 - path: libraries/classes/Util.php - - - - message: "#^Parameter \\#1 \\$str of function trim expects string, string\\|null given\\.$#" - count: 2 - path: libraries/classes/Util.php - - - - message: "#^Trying to invoke array\\|string but it might not be a callable\\.$#" - count: 1 - path: libraries/classes/Util.php - - message: "#^Parameter \\#1 \\$array_arg of function reset expects array, array\\|object given\\.$#" count: 1 path: libraries/classes/Util.php - - - message: "#^Parameter \\#1 \\$character of function ord expects string, string\\|false given\\.$#" - count: 1 - path: libraries/classes/Util.php - - message: "#^Property PhpMyAdmin\\\\Utils\\\\HttpRequest\\:\\:\\$proxyUrl has no typehint specified\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e15ed4e293..81fa7728de 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + Util::formatByteDown($value, $limes, $comma) @@ -435,7 +435,9 @@ $insert_errors - + + $current_value + $current_value $multi_edit_columns_null $multi_edit_columns_null_prev $multi_edit_funcs @@ -747,14 +749,12 @@ $this->__get('sql_query') - + $col_visib $col_visib $sortExpressionNoDirection - $transform_options - $transform_options - + $this->__get('sql_query') $db $table @@ -775,7 +775,6 @@ empty($field->database) ? $this->__get('db') : $field->database $this->__get('table') $this->__get('db') - $display_params $this->__get('fields_cnt') $this->__get('fields_meta') $this->__get('table') @@ -813,7 +812,7 @@ $this->__get('fields_cnt') $this->__get('fields_meta') - + $fields_meta[$i] $fields_meta[$i] $fields_meta[$i] @@ -835,11 +834,6 @@ $display_params['data'] $display_params['data'] $display_params['data'] - $display_params['data'] - $display_params['rowdata'] - $display_params['data'] - $display_params['data'] - $display_params['rowdata'] $fields_meta[$m] $fields_meta[0] $fields_meta[1] @@ -847,7 +841,17 @@ $display_size[0] $display_size[1] - + + $display_params['desc'] + $display_params['desc'] + $whereClauseMap[$row_no] + $whereClauseMap[$row_no] + $display_params['data'] + $display_params['data'] + $display_params['data'] + + + $whereClauseMap[$row_no] $map @@ -1123,9 +1127,6 @@ - - $user - null @@ -1873,7 +1874,8 @@ $com_rs $com_rs - + + $cfgRelation $this->queryAsControlUser($upd_query) $this->dbi->insertId(DatabaseInterface::CONNECT_CONTROL) @@ -2274,17 +2276,16 @@ $group[$group_name]['tab' . $sep . 'count'] - + $group[$group_name]['is' . $sep . 'group'] $group[$group_name]['tab' . $sep . 'count'] + $units[$d] - + $return_value - $gis_data_types - + int - string[] $value