From f9702992894d33537f69d3240211f3620c983104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 9 Aug 2021 12:20:32 -0300 Subject: [PATCH] Remove `$defaultFunction` variable from `Display\Results` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes the type of $transformationPlugin variable more strict. Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Display/Results.php | 298 ++++++++++---------------- phpstan-baseline.neon | 10 - psalm-baseline.xml | 45 ++-- test/classes/Display/ResultsTest.php | 183 ++++++---------- 4 files changed, 192 insertions(+), 344 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 5e580846c7e8..d8fe29cf0044 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -48,7 +48,6 @@ use function implode; use function intval; use function is_array; -use function is_object; use function json_encode; use function mb_check_encoding; use function mb_strlen; @@ -57,7 +56,6 @@ use function mb_strtoupper; use function mb_substr; use function md5; -use function method_exists; use function mt_rand; use function pack; use function preg_match; @@ -228,7 +226,8 @@ class Results * One element of this array represent all relevant columns in all tables in * one specific database * - * @var array + * @var array>> + * @psalm-var array>> $transformationInfo */ public $transformationInfo; @@ -329,8 +328,7 @@ private function setDefaultTransformations() return; } - $this->transformationInfo[$cfgRelation['db']] = []; - $relDb = &$this->transformationInfo[$cfgRelation['db']]; + $relDb = []; if (! empty($cfgRelation['history'])) { $relDb[$cfgRelation['history']] = ['sqlquery' => $sqlHighlightingData]; } @@ -370,11 +368,11 @@ private function setDefaultTransformations() $relDb[$cfgRelation['userconfig']] = ['config_data' => $jsonHighlightingData]; } - if (empty($cfgRelation['export_templates'])) { - return; + if (! empty($cfgRelation['export_templates'])) { + $relDb[$cfgRelation['export_templates']] = ['template_data' => $jsonHighlightingData]; } - $relDb[$cfgRelation['export_templates']] = ['template_data' => $jsonHighlightingData]; + $this->transformationInfo[$cfgRelation['db']] = $relDb; } /** @@ -2287,14 +2285,11 @@ private function buildEmptyDisplay($class, $conditionField, FieldMetadata $meta, * * @see buildNullDisplay(), getRowData() * - * @param string $class class of table cell - * @param bool $conditionField whether to add CSS class condition - * @param FieldMetadata $meta the meta-information about the field - * @param string $nowrap avoid wrapping - * @param bool $isFieldTruncated is field truncated (display ...) - * @param TransformationsPlugin|string $transformationPlugin Can also be the default function: - * Core::mimeDefaultFunction - * @param callable|null $defaultFunction default transformation function + * @param string $class class of table cell + * @param bool $conditionField whether to add CSS class condition + * @param FieldMetadata $meta the meta-information about the field + * @param string $nowrap avoid wrapping + * @param bool $isFieldTruncated is field truncated (display ...) * * @return string the list of classes */ @@ -2304,8 +2299,7 @@ private function addClass( FieldMetadata $meta, $nowrap, $isFieldTruncated = false, - $transformationPlugin = '', - $defaultFunction = null + bool $hasTransformationPlugin = false ) { $classes = [ $class, @@ -2327,10 +2321,7 @@ private function addClass( $mediaTypeMap = $this->properties['mime_map']; $orgFullColName = $this->properties['db'] . '.' . $meta->orgtable . '.' . $meta->orgname; - if ( - $transformationPlugin != $defaultFunction - || ! empty($mediaTypeMap[$orgFullColName]['input_transformation']) - ) { + if ($hasTransformationPlugin || ! empty($mediaTypeMap[$orgFullColName]['input_transformation'])) { $classes[] = 'transformed'; } @@ -2782,11 +2773,7 @@ private function getRowValues( || isset($highlightColumns[Util::backquote($meta->name)])); // Wrap MIME-transformations. [MIME] - $defaultFunction = [ - Core::class, - 'mimeDefaultFunction', - ]; // default_function - $transformationPlugin = $defaultFunction; + $transformationPlugin = null; $transformOptions = []; if ( @@ -2803,21 +2790,19 @@ private function getRowValues( if (@file_exists(ROOT_PATH . $includeFile)) { $className = $this->transformations->getClassName($includeFile); if (class_exists($className)) { - // todo add $plugin_manager - $pluginManager = null; - $transformationPlugin = new $className( - $pluginManager - ); - - $transformOptions = $this->transformations->getOptions( - $mediaTypeMap[$orgFullColName]['transformation_options'] ?? '' - ); - - $meta->internalMediaType = str_replace( - '_', - '/', - $mediaTypeMap[$orgFullColName]['mimetype'] - ); + $plugin = new $className(); + if ($plugin instanceof TransformationsPlugin) { + $transformationPlugin = $plugin; + $transformOptions = $this->transformations->getOptions( + $mediaTypeMap[$orgFullColName]['transformation_options'] ?? '' + ); + + $meta->internalMediaType = str_replace( + '_', + '/', + $mediaTypeMap[$orgFullColName]['mimetype'] + ); + } } } } @@ -2836,20 +2821,22 @@ private function getRowValues( ) { /** @psalm-suppress UnresolvableInclude */ include_once ROOT_PATH . $this->transformationInfo[$dbLower][$tblLower][$nameLower][0]; - $transformationPlugin = new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1](null); - - $transformOptions = $this->transformations->getOptions( - $mediaTypeMap[$orgFullColName]['transformation_options'] ?? '' - ); + $plugin = new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1](); + if ($plugin instanceof TransformationsPlugin) { + $transformationPlugin = $plugin; + $transformOptions = $this->transformations->getOptions( + $mediaTypeMap[$orgFullColName]['transformation_options'] ?? '' + ); - $orgTable = mb_strtolower($meta->orgtable); - $orgName = mb_strtolower($meta->orgname); + $orgTable = mb_strtolower($meta->orgtable); + $orgName = mb_strtolower($meta->orgname); - $meta->internalMediaType = str_replace( - '_', - '/', - $this->transformationInfo[$dbLower][$orgTable][$orgName][2] - ); + $meta->internalMediaType = str_replace( + '_', + '/', + $this->transformationInfo[$dbLower][$orgTable][$orgName][2] + ); + } } // Check for the predefined fields need to show as link in schemas @@ -2940,7 +2927,6 @@ private function getRowValues( $isFieldTruncated, $analyzedSqlResults, $transformationPlugin, - $defaultFunction, $transformOptions ); } elseif ($meta->isMappedTypeGeometry) { @@ -2958,7 +2944,6 @@ private function getRowValues( $urlParams, $conditionField, $transformationPlugin, - $defaultFunction, $transformOptions, $analyzedSqlResults ); @@ -2973,7 +2958,6 @@ private function getRowValues( $urlParams, $conditionField, $transformationPlugin, - $defaultFunction, $transformOptions, $isFieldTruncated, $analyzedSqlResults @@ -3438,17 +3422,14 @@ private function getClassForDateTimeRelatedFields(FieldMetadata $meta): string * * @see getTableBody() * - * @param string|null $column the column's value - * @param string $class the html class for column - * @param bool $conditionField the column should highlighted or not - * @param FieldMetadata $meta the meta-information about this field - * @param array $map the list of relations - * @param bool $isFieldTruncated the condition for blob data replacements - * @param array $analyzedSqlResults the analyzed query - * @param TransformationsPlugin $transformationPlugin the name of transformation plugin - * @param callable $defaultFunction the default transformation function - * @param array $transformOptions the transformation parameters - * @psalm-param callable(string):string $defaultFunction + * @param string|null $column the column's value + * @param string $class the html class for column + * @param bool $conditionField the column should highlighted or not + * @param FieldMetadata $meta the meta-information about this field + * @param array $map the list of relations + * @param bool $isFieldTruncated the condition for blob data replacements + * @param array $analyzedSqlResults the analyzed query + * @param array $transformOptions the transformation parameters * * @return string the prepared cell, html content */ @@ -3460,8 +3441,7 @@ private function getDataCellForNumericColumns( array $map, $isFieldTruncated, array $analyzedSqlResults, - $transformationPlugin, - $defaultFunction, + ?TransformationsPlugin $transformationPlugin, array $transformOptions ) { if (! isset($column)) { @@ -3484,7 +3464,6 @@ private function getDataCellForNumericColumns( $column, $column, $transformationPlugin, - $defaultFunction, $nowrap, $whereComparison, $transformOptions, @@ -3508,17 +3487,14 @@ private function getDataCellForNumericColumns( * * @see getTableBody() * - * @param string|null $column the relevant column in data row - * @param string $class the html class for column - * @param FieldMetadata $meta the meta-information about this field - * @param array $map the list of relations - * @param array $urlParams the parameters for generate url - * @param bool $conditionField the column should highlighted or not - * @param TransformationsPlugin $transformationPlugin the name of transformation function - * @param callable $defaultFunction the default transformation function - * @param array $transformOptions the transformation parameters - * @param array $analyzedSqlResults the analyzed query - * @psalm-param callable(string):string $defaultFunction + * @param string|null $column the relevant column in data row + * @param string $class the html class for column + * @param FieldMetadata $meta the meta-information about this field + * @param array $map the list of relations + * @param array $urlParams the parameters for generate url + * @param bool $conditionField the column should highlighted or not + * @param array $transformOptions the transformation parameters + * @param array $analyzedSqlResults the analyzed query * * @return string the prepared data cell, html content */ @@ -3529,8 +3505,7 @@ private function getDataCellForGeometryColumns( array $map, array $urlParams, $conditionField, - $transformationPlugin, - $defaultFunction, + ?TransformationsPlugin $transformationPlugin, $transformOptions, array $analyzedSqlResults ) { @@ -3549,7 +3524,6 @@ private function getDataCellForGeometryColumns( $column, $transformationPlugin, $transformOptions, - $defaultFunction, $meta, $urlParams ); @@ -3582,7 +3556,6 @@ private function getDataCellForGeometryColumns( $wktval, $displayedColumn, $transformationPlugin, - $defaultFunction, '', $whereComparison, $transformOptions, @@ -3612,7 +3585,6 @@ private function getDataCellForGeometryColumns( $wkbval, $displayedColumn, $transformationPlugin, - $defaultFunction, '', $whereComparison, $transformOptions, @@ -3626,7 +3598,6 @@ private function getDataCellForGeometryColumns( $column, $transformationPlugin, $transformOptions, - $defaultFunction, $meta, $urlParams ); @@ -3643,18 +3614,15 @@ private function getDataCellForGeometryColumns( * * @see getTableBody() * - * @param string|null $column the relevant column in data row - * @param string $class the html class for column - * @param FieldMetadata $meta the meta-information about the field - * @param array $map the list of relations - * @param array $urlParams the parameters for generate url - * @param bool $conditionField the column should highlighted or not - * @param TransformationsPlugin $transformationPlugin the name of transformation function - * @param callable $defaultFunction the default transformation function - * @param array $transformOptions the transformation parameters - * @param bool $isFieldTruncated is data truncated due to LimitChars - * @param array $analyzedSqlResults the analyzed query - * @psalm-param callable(string):string $defaultFunction + * @param string|null $column the relevant column in data row + * @param string $class the html class for column + * @param FieldMetadata $meta the meta-information about the field + * @param array $map the list of relations + * @param array $urlParams the parameters for generate url + * @param bool $conditionField the column should highlighted or not + * @param array $transformOptions the transformation parameters + * @param bool $isFieldTruncated is data truncated due to LimitChars + * @param array $analyzedSqlResults the analyzed query * * @return string the prepared data cell, html content */ @@ -3665,8 +3633,7 @@ private function getDataCellForNonNumericColumns( array $map, array $urlParams, $conditionField, - $transformationPlugin, - $defaultFunction, + ?TransformationsPlugin $transformationPlugin, $transformOptions, $isFieldTruncated, array $analyzedSqlResults @@ -3677,8 +3644,7 @@ private function getDataCellForNonNumericColumns( $isAnalyse = $this->properties['is_analyse']; - $bIsText = is_object($transformationPlugin) - && ! str_contains($transformationPlugin->getMIMEType(), 'Text'); + $bIsText = isset($transformationPlugin) && ! str_contains($transformationPlugin->getMIMEType(), 'Text'); // disable inline grid editing // if binary fields are protected @@ -3711,7 +3677,7 @@ private function getDataCellForNonNumericColumns( $originalDataForWhereClause = $column; $displayedColumn = $column; if ( - ! (is_object($transformationPlugin) + ! (isset($transformationPlugin) && str_contains($transformationPlugin->getName(), 'Link')) && ! $meta->isBinary() ) { @@ -3748,7 +3714,6 @@ private function getDataCellForNonNumericColumns( $displayedColumn, $transformationPlugin, $transformOptions, - $defaultFunction, $meta, $urlParams, $isFieldTruncated @@ -3759,8 +3724,7 @@ private function getDataCellForNonNumericColumns( $meta, '', $isFieldTruncated, - $transformationPlugin, - $defaultFunction + isset($transformationPlugin) ); $result = strip_tags($column); // disable inline grid editing @@ -3781,8 +3745,7 @@ private function getDataCellForNonNumericColumns( } // transform functions may enable no-wrapping: - $boolNoWrap = ($defaultFunction !== $transformationPlugin) - && method_exists($transformationPlugin, 'applyTransformationNoWrap') + $boolNoWrap = isset($transformationPlugin) && $transformationPlugin->applyTransformationNoWrap($transformOptions); // do not wrap if date field type or if no-wrapping enabled by transform functions @@ -3802,7 +3765,6 @@ private function getDataCellForNonNumericColumns( $column, $displayedColumn, $transformationPlugin, - $defaultFunction, $nowrap, $whereComparison, $transformOptions, @@ -4288,14 +4250,6 @@ private function getSortedColumnMessage( // fetch first row of the result set $row = $dbi->fetchRow($dtResult); - // initializing default arguments - $defaultFunction = [ - Core::class, - 'mimeDefaultFunction', - ]; - $transformationPlugin = $defaultFunction; - $transformOptions = []; - // check for non printable sorted row data $meta = $fieldsMeta[$sortedColumnIndex]; @@ -4306,9 +4260,8 @@ private function getSortedColumnMessage( $columnForFirstRow = $this->handleNonPrintableContents( $meta->getMappedType(), $row[$sortedColumnIndex], - $transformationPlugin, - $transformOptions, - $defaultFunction, + null, + [], $meta ); } else { @@ -4336,9 +4289,8 @@ private function getSortedColumnMessage( $columnForLastRow = $this->handleNonPrintableContents( $meta->getMappedType(), $row[$sortedColumnIndex], - $transformationPlugin, - $transformOptions, - $defaultFunction, + null, + [], $meta ); } else { @@ -4700,18 +4652,12 @@ private function getResultsOperations( * * @see getDataCellForGeometryColumns(), getDataCellForNonNumericColumns(), getSortedColumnMessage() * - * @param string $category BLOB|BINARY|GEOMETRY - * @param string|null $content the binary content - * @param mixed $transformationPlugin transformation plugin. - * Can also be the - * default function: - * Core::mimeDefaultFunction - * @param array $transformOptions transformation parameters - * @param callable $defaultFunction default transformation function - * @param FieldMetadata $meta the meta-information about the field - * @param array $urlParams parameters that should go to the - * download link - * @param bool $isTruncated the result is truncated or not + * @param string $category BLOB|BINARY|GEOMETRY + * @param string|null $content the binary content + * @param array $transformOptions transformation parameters + * @param FieldMetadata $meta the meta-information about the field + * @param array $urlParams parameters that should go to the download link + * @param bool $isTruncated the result is truncated or not * * @return mixed string or float * @@ -4720,9 +4666,8 @@ private function getResultsOperations( private function handleNonPrintableContents( $category, ?string $content, - $transformationPlugin, + ?TransformationsPlugin $transformationPlugin, $transformOptions, - $defaultFunction, FieldMetadata $meta, array $urlParams = [], &$isTruncated = null @@ -4745,7 +4690,7 @@ private function handleNonPrintableContents( $result .= ']'; // if we want to use a text transformation on a BLOB column - if (is_object($transformationPlugin)) { + if (isset($transformationPlugin)) { $posMimeOctetstream = strpos( $transformationPlugin->getMIMESubtype(), 'Octetstream' @@ -4765,17 +4710,15 @@ private function handleNonPrintableContents( return $result; } - if ($defaultFunction != $transformationPlugin) { - $result = $transformationPlugin->applyTransformation( + if (isset($transformationPlugin)) { + return $transformationPlugin->applyTransformation( $result, $transformOptions, $meta ); - - return $result; } - $result = $defaultFunction($result, [], $meta); + $result = Core::mimeDefaultFunction($result); if ( ($_SESSION['tmpval']['display_binary'] && $meta->isType(FieldMetadata::TYPE_STRING)) @@ -4865,22 +4808,18 @@ private function getFromForeign(array $map, FieldMetadata $meta, $whereCompariso * @see getDataCellForNumericColumns(), getDataCellForGeometryColumns(), * getDataCellForNonNumericColumns(), * - * @param string $class css classes for the td element - * @param bool $conditionField whether the column is a part of the where clause - * @param array $analyzedSqlResults the analyzed query - * @param FieldMetadata $meta the meta-information about the field - * @param array $map the list of relations - * @param string $data data - * @param string $displayedData data that will be displayed (maybe be chunked) - * @param TransformationsPlugin $transformationPlugin transformation plugin. Can also be the default function: - * Core::mimeDefaultFunction - * @param callable $defaultFunction default function - * @param string $nowrap 'nowrap' if the content should not be wrapped - * @param string $whereComparison data for the where clause - * @param array $transformOptions options for transformation - * @param bool $isFieldTruncated whether the field is truncated - * @param string $originalLength of a truncated column, or '' - * @psalm-param callable(string):string $defaultFunction + * @param string $class css classes for the td element + * @param bool $conditionField whether the column is a part of the where clause + * @param array $analyzedSqlResults the analyzed query + * @param FieldMetadata $meta the meta-information about the field + * @param array $map the list of relations + * @param string $data data + * @param string $displayedData data that will be displayed (maybe be chunked) + * @param string $nowrap 'nowrap' if the content should not be wrapped + * @param string $whereComparison data for the where clause + * @param array $transformOptions options for transformation + * @param bool $isFieldTruncated whether the field is truncated + * @param string $originalLength of a truncated column, or '' * * @return string formatted data * @@ -4894,8 +4833,7 @@ private function getRowData( array $map, $data, $displayedData, - $transformationPlugin, - $defaultFunction, + ?TransformationsPlugin $transformationPlugin, $nowrap, $whereComparison, array $transformOptions, @@ -4911,8 +4849,7 @@ private function getRowData( $meta, $nowrap, $isFieldTruncated, - $transformationPlugin, - $defaultFunction + isset($transformationPlugin) ); if (! empty($analyzedSqlResults['statement']->expr)) { @@ -4945,15 +4882,17 @@ private function getRowData( } if (isset($printView) && ($printView == '1')) { - $value .= ($transformationPlugin != $defaultFunction - ? $transformationPlugin->applyTransformation( + if (isset($transformationPlugin)) { + $value .= $transformationPlugin->applyTransformation( $data, $transformOptions, $meta - ) - : $defaultFunction($data) - ) - . ' [->' . $dispval . ']'; + ); + } else { + $value .= Core::mimeDefaultFunction($data); + } + + $value .= ' [->' . $dispval . ']'; } else { if ($relationalDisplay === self::RELATIONAL_KEY) { // user chose "relational key" in the display options, so @@ -4980,7 +4919,7 @@ private function getRowData( 'sql_query' => $sqlQuery, ]; - if ($transformationPlugin != $defaultFunction) { + if (isset($transformationPlugin)) { // always apply a transformation on the real data, // not on the display field $displayedData = $transformationPlugin->applyTransformation( @@ -4995,10 +4934,10 @@ private function getRowData( ) { // user chose "relational display field" in the // display options, so show display field in the cell - $displayedData = $dispval === null ? 'NULL' : $defaultFunction($dispval); + $displayedData = $dispval === null ? 'NULL' : Core::mimeDefaultFunction($dispval); } else { // otherwise display data in the cell - $displayedData = $defaultFunction($displayedData); + $displayedData = Core::mimeDefaultFunction($displayedData); } } @@ -5013,15 +4952,10 @@ private function getRowData( $tagParams ); } + } elseif (isset($transformationPlugin)) { + $value .= $transformationPlugin->applyTransformation($data, $transformOptions, $meta); } else { - $value .= ($transformationPlugin != $defaultFunction - ? $transformationPlugin->applyTransformation( - $data, - $transformOptions, - $meta - ) - : $defaultFunction($data) - ); + $value .= Core::mimeDefaultFunction($data); } return $this->template->render('display/results/row_data', [ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 92123084c03b..a711b82d48d2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -270,16 +270,6 @@ parameters: count: 1 path: libraries/classes/DatabaseInterface.php - - - message: "#^Call to an undefined method object\\:\\:getMIMESubtype\\(\\)\\.$#" - count: 1 - path: libraries/classes/Display/Results.php - - - - message: "#^Call to an undefined method object\\:\\:getMIMEtype\\(\\)\\.$#" - count: 1 - path: libraries/classes/Display/Results.php - - message: "#^Left side of && is always true\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index de2afed66824..14f4174686da 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7007,15 +7007,13 @@ - - $defaultFunction !== $transformationPlugin + $displayParts['nav_bar'] == '1' && $statement !== null && empty($statement->limit) '-1' -1 [] - is_object($transformationPlugin) - + $added[$orgFullTableName] $dtResult $dtResult @@ -7025,9 +7023,6 @@ $dtResult $dtResult $dtResult - $transformationPlugin - $transformationPlugin - $transformationPlugin $index @@ -7035,7 +7030,7 @@ $originalLength - + $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['query'] $_SESSION['tmpval']['query'] @@ -7110,10 +7105,7 @@ $sortExpressionNoDirection[$indexInExpression] $sortExpressionNoDirection[$indexInExpression] $sqlQuery - $this->transformationInfo[$dbLower][$orgTable][$orgName][2] $total - $transformationPlugin->getMIMESubtype() - $transformationPlugin->getMIMEtype() $unsortedSqlQuery $urlParams['where_clause'] $whereClause @@ -7130,7 +7122,7 @@ $sortExpression $urlParams - + $GLOBALS['cfg']['BrowseMIME'] $GLOBALS['cfg']['BrowseMIME'] $GLOBALS['cfg']['BrowseMarkerEnable'] @@ -7242,9 +7234,6 @@ $rel['foreign_field'] $rel['foreign_table'] $rel['foreign_table'] - $this->transformationInfo[$dbLower][$orgTable] - $this->transformationInfo[$dbLower][$tblLower][$nameLower][0] - $this->transformationInfo[$dbLower][$tblLower][$nameLower][1] $whereClauseMap[$rowNumber][$meta->orgtable] @@ -7320,7 +7309,7 @@ $row[$i] $row[$m] - + $_SESSION['tmpval']['geoOption'] $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['pftext'] @@ -7376,8 +7365,6 @@ $query['repeat_cells'] $rel $relationalDisplay - $result - $result $rowCount $rowInfo[mb_strtolower($fieldsMeta[$m]->orgname)] $sessionMaxRows @@ -7396,13 +7383,11 @@ string|null - - applyTransformation - getMIMESubtype - getMIMEtype - new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1](null) + + new $className() + new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1]() - + $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['pos'] @@ -7426,7 +7411,6 @@ $singleSortOrder $sortExpressionNoDirection[$indexInExpression] $sortOrder - $this->transformationInfo[$dbLower][$tblLower][$nameLower][0] $val Util::backquote($currentName) Util::backquote($map[$meta->name][0]) @@ -7491,15 +7475,13 @@ $bIsProcessList - - $defaultFunction !== $transformationPlugin + $firstStatement->order $meta->decimals $meta->decimals $posNext !== null $sortedColumnMessage !== null ($displayParts['nav_bar'] == '1') && $posNext !== null - is_object($transformationPlugin) isset($fieldsMeta->table) isset($meta->internalMediaType) @@ -7519,9 +7501,8 @@ $columnIndex - + $key - $relDb @@ -20300,9 +20281,7 @@ $output $output - - array - array + array array array diff --git a/test/classes/Display/ResultsTest.php b/test/classes/Display/ResultsTest.php index e6f79f7dc4c7..298ceb3f27a2 100644 --- a/test/classes/Display/ResultsTest.php +++ b/test/classes/Display/ResultsTest.php @@ -4,7 +4,6 @@ namespace PhpMyAdmin\Tests\Display; -use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\Results as DisplayResults; use PhpMyAdmin\FieldMetadata; @@ -13,6 +12,7 @@ use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\Plugins\Transformations\Output\Text_Plain_External; use PhpMyAdmin\Plugins\Transformations\Text_Plain_Link; +use PhpMyAdmin\Plugins\TransformationsPlugin; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Utils\Query; use PhpMyAdmin\Template; @@ -628,9 +628,19 @@ public function testGetPartialText(string $pftext, int $limitChars, string $str, } /** - * Data provider for testHandleNonPrintableContents - * - * @return array parameters and output + * @return mixed[][] + * @psalm-return array{array{ + * bool, + * bool, + * string, + * string|null, + * TransformationsPlugin|null, + * array|object, + * object, + * array, + * bool|null, + * string + * }} */ public function dataProviderForTestHandleNonPrintableContents(): array { @@ -648,15 +658,8 @@ public function dataProviderForTestHandleNonPrintableContents(): array true, 'BLOB', '1001', - [ - Core::class, - 'mimeDefaultFunction', - ], + null, [], - [ - Core::class, - 'mimeDefaultFunction', - ], $meta, $url_params, null, @@ -667,15 +670,8 @@ public function dataProviderForTestHandleNonPrintableContents(): array true, 'BLOB', hex2bin('123456'), - [ - Core::class, - 'mimeDefaultFunction', - ], + null, [], - [ - Core::class, - 'mimeDefaultFunction', - ], $meta, $url_params, null, @@ -686,15 +682,8 @@ public function dataProviderForTestHandleNonPrintableContents(): array false, 'BLOB', '1001', - [ - Core::class, - 'mimeDefaultFunction', - ], + null, [], - [ - Core::class, - 'mimeDefaultFunction', - ], $meta, $url_params, null, @@ -707,10 +696,6 @@ public function dataProviderForTestHandleNonPrintableContents(): array '1001', $transformation_plugin, [], - [ - Core::class, - 'mimeDefaultFunction', - ], $meta, $url_params, null, @@ -721,12 +706,8 @@ public function dataProviderForTestHandleNonPrintableContents(): array true, 'GEOMETRY', null, - '', + null, [], - [ - Core::class, - 'mimeDefaultFunction', - ], $meta, $url_params, null, @@ -736,22 +717,15 @@ public function dataProviderForTestHandleNonPrintableContents(): array } /** - * Test handleNonPrintableContents - * - * @param bool $display_binary show binary contents? - * @param bool $display_blob show blob contents? - * @param string $category BLOB|BINARY|GEOMETRY - * @param string $content the binary content - * @param array|object $transformation_plugin transformation plugin. - * Can also be the default function: - * PhpMyAdmin\Core::mimeDefaultFunction - * @param array|object $transform_options transformation parameters - * @param array $default_function default transformation function - * @param object $meta the meta-information about the field - * @param array $url_params parameters that should go to the - * download link - * @param bool|null $is_truncated the result is truncated or not - * @param string $output the output of this function + * @param bool $display_binary show binary contents? + * @param bool $display_blob show blob contents? + * @param string $category BLOB|BINARY|GEOMETRY + * @param string|null $content the binary content + * @param array|object $transform_options transformation parameters + * @param object $meta the meta-information about the field + * @param array $url_params parameters that should go to the download link + * @param bool|null $is_truncated the result is truncated or not + * @param string $output the output of this function * * @dataProvider dataProviderForTestHandleNonPrintableContents */ @@ -760,10 +734,9 @@ public function testHandleNonPrintableContents( bool $display_blob, string $category, ?string $content, - $transformation_plugin, + ?TransformationsPlugin $transformation_plugin, $transform_options, - array $default_function, - $meta, + object $meta, array $url_params, ?bool $is_truncated, string $output @@ -782,7 +755,6 @@ public function testHandleNonPrintableContents( $content, $transformation_plugin, $transform_options, - $default_function, $meta, $url_params, &$is_truncated, @@ -792,9 +764,23 @@ public function testHandleNonPrintableContents( } /** - * Data provider for testGetDataCellForNonNumericColumns - * - * @return array parameters and output + * @return mixed[][] + * @psalm-return array{array{ + * string, + * string|null, + * string, + * object, + * array, + * array, + * bool, + * TransformationsPlugin|null, + * array, + * bool, + * array, + * int, + * int|string, + * string + * }} */ public function dataProviderForTestGetDataCellForNonNumericColumns(): array { @@ -841,14 +827,7 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array [], $url_params, false, - [ - Core::class, - 'mimeDefaultFunction', - ], - [ - Core::class, - 'mimeDefaultFunction', - ], + null, ['https://www.example.com/'], false, [], @@ -866,10 +845,6 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array $url_params, false, $transformation_plugin, - [ - Core::class, - 'mimeDefaultFunction', - ], [], false, [], @@ -888,10 +863,6 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array $url_params, false, $transformation_plugin, - [ - Core::class, - 'mimeDefaultFunction', - ], [], false, [], @@ -912,14 +883,7 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array [], $url_params, false, - [ - Core::class, - 'mimeDefaultFunction', - ], - [ - Core::class, - 'mimeDefaultFunction', - ], + null, [], false, [], @@ -938,10 +902,6 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array $url_params, false, $transformation_plugin_external, - [ - Core::class, - 'mimeDefaultFunction', - ], [], false, [], @@ -959,14 +919,7 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array [], $url_params, false, - [ - Core::class, - 'mimeDefaultFunction', - ], - [ - Core::class, - 'mimeDefaultFunction', - ], + null, [], false, [], @@ -980,25 +933,19 @@ public function dataProviderForTestGetDataCellForNonNumericColumns(): array } /** - * Test getDataCellForNonNumericColumns - * - * @param string $protectBinary all|blob|noblob|no - * @param string|null $column the relevant column in data row - * @param string $class the html class for column - * @param object $meta the meta-information about the field - * @param array $map the list of relations - * @param array $_url_params the parameters for generate url - * @param bool $condition_field the column should highlighted - * or not - * @param array|object $transformation_plugin the name of transformation function - * @param array|object $default_function the default transformation function - * @param array $transform_options the transformation parameters - * @param bool $is_field_truncated is data truncated due to LimitChars - * @param array $analyzed_sql_results the analyzed query - * @param int $dt_result the link id associated to the query - * which results have to be displayed - * @param int|string $col_index the column index - * @param string $output the output of this function + * @param string $protectBinary all|blob|noblob|no + * @param string|null $column the relevant column in data row + * @param string $class the html class for column + * @param object $meta the meta-information about the field + * @param array $map the list of relations + * @param array $_url_params the parameters for generate url + * @param bool $condition_field the column should highlighted or not + * @param array $transform_options the transformation parameters + * @param bool $is_field_truncated is data truncated due to LimitChars + * @param array $analyzed_sql_results the analyzed query + * @param int $dt_result the link id associated to the query which results have to be displayed + * @param int|string $col_index the column index + * @param string $output the output of this function * * @dataProvider dataProviderForTestGetDataCellForNonNumericColumns */ @@ -1006,12 +953,11 @@ public function testGetDataCellForNonNumericColumns( string $protectBinary, ?string $column, string $class, - $meta, + object $meta, array $map, array $_url_params, bool $condition_field, - $transformation_plugin, - $default_function, + ?TransformationsPlugin $transformation_plugin, array $transform_options, bool $is_field_truncated, array $analyzed_sql_results, @@ -1038,7 +984,6 @@ public function testGetDataCellForNonNumericColumns( $_url_params, $condition_field, $transformation_plugin, - $default_function, $transform_options, $is_field_truncated, $analyzed_sql_results,