Skip to content

Commit 44a8e6f

Browse files
committed
Split up getPartialText()
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent 25def2c commit 44a8e6f

2 files changed

Lines changed: 26 additions & 45 deletions

File tree

src/Display/Results.php

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,11 +2711,7 @@ private function getDataCellForGeometryColumns(
27112711

27122712
// Convert to WKT format
27132713
$wktval = Gis::convertToWellKnownText($column);
2714-
[
2715-
$isFieldTruncated,
2716-
$displayedColumn,
2717-
// skip 3rd param
2718-
] = $this->getPartialText($wktval);
2714+
$displayedColumn = $this->getPartialText($wktval);
27192715

27202716
return $this->getRowData(
27212717
$class,
@@ -2729,7 +2725,7 @@ private function getDataCellForGeometryColumns(
27292725
'',
27302726
$whereComparison,
27312727
$transformOptions,
2732-
$isFieldTruncated,
2728+
$displayedColumn !== $wktval,
27332729
);
27342730
}
27352731

@@ -2739,11 +2735,7 @@ private function getDataCellForGeometryColumns(
27392735
$whereComparison = ' = ' . $column;
27402736

27412737
$wkbval = substr(bin2hex($column), 8);
2742-
[
2743-
$isFieldTruncated,
2744-
$displayedColumn,
2745-
// skip 3rd param
2746-
] = $this->getPartialText($wkbval);
2738+
$displayedColumn = $this->getPartialText($wkbval);
27472739

27482740
return $this->getRowData(
27492741
$class,
@@ -2757,7 +2749,7 @@ private function getDataCellForGeometryColumns(
27572749
'',
27582750
$whereComparison,
27592751
$transformOptions,
2760-
$isFieldTruncated,
2752+
$displayedColumn !== $wkbval,
27612753
);
27622754
}
27632755

@@ -2799,8 +2791,6 @@ private function getDataCellForNonNumericColumns(
27992791
array $transformOptions,
28002792
StatementInfo $statementInfo,
28012793
): string {
2802-
$originalLength = 0;
2803-
28042794
$bIsText = $transformationPlugin !== null && ! str_contains($transformationPlugin::getMIMEType(), 'Text');
28052795

28062796
// disable inline grid editing
@@ -2831,15 +2821,17 @@ private function getDataCellForNonNumericColumns(
28312821

28322822
// Cut all fields to \PhpMyAdmin\Config::getInstance()->settings['LimitChars']
28332823
// (unless it's a link-type transformation or binary)
2824+
$originalLength = 0;
28342825
$originalDataForWhereClause = $column;
28352826
$displayedColumn = $column;
28362827
$isFieldTruncated = false;
28372828
if (
2838-
! ($transformationPlugin !== null
2839-
&& str_contains($transformationPlugin::getName(), 'Link'))
2829+
! ($transformationPlugin !== null && str_contains($transformationPlugin::getName(), 'Link'))
28402830
&& ! $meta->isBinary()
28412831
) {
2842-
[$isFieldTruncated, $column, $originalLength] = $this->getPartialText($column);
2832+
$originalLength = mb_strlen($displayedColumn);
2833+
$column = $this->getPartialText($displayedColumn);
2834+
$isFieldTruncated = $column !== $displayedColumn;
28432835
}
28442836

28452837
if ($meta->isMappedTypeBit) {
@@ -3702,11 +3694,9 @@ private function handleNonPrintableContents(
37023694
$result = '0x' . bin2hex($content);
37033695
}
37043696

3705-
[
3706-
$isTruncated,
3707-
$result,
3708-
// skip 3rd param
3709-
] = $this->getPartialText($result);
3697+
$preTruncation = $result;
3698+
$result = $this->getPartialText($result);
3699+
$isTruncated = $result !== $preTruncation;
37103700
}
37113701

37123702
/* Create link to download */
@@ -3752,9 +3742,7 @@ private function getFromForeign(ForeignKeyRelatedTable $fieldInfo, string $where
37523742
}
37533743

37543744
// Truncate values that are too long, see: #17902
3755-
[, $dispval] = $this->getPartialText($dispval);
3756-
3757-
return $dispval;
3745+
return $this->getPartialText($dispval);
37583746
}
37593747

37603748
/**
@@ -3908,23 +3896,16 @@ private function getRowData(
39083896
* @see handleNonPrintableContents(), getDataCellForGeometryColumns(), getDataCellForNonNumericColumns
39093897
*
39103898
* @param string $str string to be truncated
3911-
*
3912-
* @return mixed[]
3913-
* @psalm-return array{bool, string, int}
39143899
*/
3915-
private function getPartialText(string $str): array
3900+
private function getPartialText(string $str): string
39163901
{
3917-
$originalLength = mb_strlen($str);
39183902
if (
3919-
$originalLength > $this->config->settings['LimitChars']
3903+
mb_strlen($str) > $this->config->settings['LimitChars']
39203904
&& $_SESSION['tmpval']['pftext'] === self::DISPLAY_PARTIAL_TEXT
39213905
) {
3922-
$str = mb_substr($str, 0, $this->config->settings['LimitChars']) . '...';
3923-
$truncated = true;
3924-
} else {
3925-
$truncated = false;
3906+
return mb_substr($str, 0, $this->config->settings['LimitChars']) . '...';
39263907
}
39273908

3928-
return [$truncated, $str, $originalLength];
3909+
return $str;
39293910
}
39303911
}

tests/unit/Display/ResultsTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,23 +344,23 @@ public function testSetHighlightedColumnGlobalField(): void
344344
public static function dataProviderForTestGetPartialText(): array
345345
{
346346
return [
347-
['P', 10, 'foo', [false, 'foo', 3]],
348-
['P', 1, 'foo', [true, 'f...', 3]],
349-
['F', 10, 'foo', [false, 'foo', 3]],
350-
['F', 1, 'foo', [false, 'foo', 3]],
347+
['P', 10, 'foo', 'foo'],
348+
['P', 1, 'foo', 'f...'],
349+
['F', 10, 'foo', 'foo'],
350+
['F', 1, 'foo', 'foo'],
351351
];
352352
}
353353

354354
/**
355355
* Test getPartialText
356356
*
357-
* @param string $pftext Partial or Full text
358-
* @param int $limitChars Partial or Full text
359-
* @param string $str the string to be tested
360-
* @param mixed[] $output return value of getPartialText
357+
* @param string $pftext Partial or Full text
358+
* @param int $limitChars Partial or Full text
359+
* @param string $str the string to be tested
360+
* @param string $output return value of getPartialText
361361
*/
362362
#[DataProvider('dataProviderForTestGetPartialText')]
363-
public function testGetPartialText(string $pftext, int $limitChars, string $str, array $output): void
363+
public function testGetPartialText(string $pftext, int $limitChars, string $str, string $output): void
364364
{
365365
$_SESSION['tmpval']['pftext'] = $pftext;
366366
Config::getInstance()->settings['LimitChars'] = $limitChars;

0 commit comments

Comments
 (0)