From 7901eb0b913b758106532fcdf8837041260cbd02 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 15 Feb 2022 01:29:12 +0100 Subject: [PATCH] Eliminate calls to flattenSingleValue() that are no longer required in TextData Functions when we're checking for array values as arguments (#2592) --- src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php | 4 ---- src/PhpSpreadsheet/Calculation/TextData/Concatenate.php | 3 --- src/PhpSpreadsheet/Calculation/TextData/Format.php | 7 +------ src/PhpSpreadsheet/Calculation/TextData/Helpers.php | 4 ---- src/PhpSpreadsheet/Calculation/TextData/Replace.php | 1 - src/PhpSpreadsheet/Calculation/TextData/Text.php | 3 --- 6 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php b/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php index 0e9cbf44..f1aea169 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php +++ b/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php @@ -3,7 +3,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class CaseConvert @@ -28,7 +27,6 @@ class CaseConvert return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue); } - $mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue); return StringHelper::strToLower($mixedCaseValue); @@ -52,7 +50,6 @@ class CaseConvert return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue); } - $mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue); return StringHelper::strToUpper($mixedCaseValue); @@ -76,7 +73,6 @@ class CaseConvert return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue); } - $mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue); return StringHelper::strToTitle($mixedCaseValue); diff --git a/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php b/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php index a7356f82..f23996a6 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php @@ -53,8 +53,6 @@ class Concatenate ); } - $delimiter = Functions::flattenSingleValue($delimiter); - $ignoreEmpty = Functions::flattenSingleValue($ignoreEmpty); // Loop through arguments $aArgs = Functions::flattenArray($args); foreach ($aArgs as $key => &$arg) { @@ -88,7 +86,6 @@ class Concatenate return self::evaluateArrayArguments([self::class, __FUNCTION__], $stringValue, $repeatCount); } - $repeatCount = Functions::flattenSingleValue($repeatCount); $stringValue = Helpers::extractString($stringValue); if (!is_numeric($repeatCount) || $repeatCount < 0) { diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index ea579013..b4b634fb 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -84,7 +84,6 @@ class Format try { $value = Helpers::extractFloat($value); $decimals = Helpers::extractInt($decimals, -100, 0, true); - $noCommas = Functions::flattenSingleValue($noCommas); } catch (CalcExp $e) { return $e->getMessage(); } @@ -140,7 +139,7 @@ class Format */ private static function convertValue($value) { - $value = ($value === null) ? 0 : Functions::flattenSingleValue($value); + $value = $value ?? 0; if (is_bool($value)) { if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { $value = (int) $value; @@ -213,8 +212,6 @@ class Format */ private static function getDecimalSeparator($decimalSeparator): string { - $decimalSeparator = Functions::flattenSingleValue($decimalSeparator); - return empty($decimalSeparator) ? StringHelper::getDecimalSeparator() : (string) $decimalSeparator; } @@ -223,8 +220,6 @@ class Format */ private static function getGroupSeparator($groupSeparator): string { - $groupSeparator = Functions::flattenSingleValue($groupSeparator); - return empty($groupSeparator) ? StringHelper::getThousandsSeparator() : (string) $groupSeparator; } diff --git a/src/PhpSpreadsheet/Calculation/TextData/Helpers.php b/src/PhpSpreadsheet/Calculation/TextData/Helpers.php index 423b6d3f..86c405ab 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Helpers.php @@ -22,7 +22,6 @@ class Helpers */ public static function extractString($value): string { - $value = Functions::flattenSingleValue($value); if (is_bool($value)) { return self::convertBooleanValue($value); } @@ -35,7 +34,6 @@ class Helpers */ public static function extractInt($value, int $minValue, int $gnumericNull = 0, bool $ooBoolOk = false): int { - $value = Functions::flattenSingleValue($value); if ($value === null) { // usually 0, but sometimes 1 for Gnumeric $value = (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_GNUMERIC) ? $gnumericNull : 0; @@ -59,7 +57,6 @@ class Helpers */ public static function extractFloat($value): float { - $value = Functions::flattenSingleValue($value); if ($value === null) { $value = 0.0; } @@ -78,7 +75,6 @@ class Helpers */ public static function validateInt($value): int { - $value = Functions::flattenSingleValue($value); if ($value === null) { $value = 0; } elseif (is_bool($value)) { diff --git a/src/PhpSpreadsheet/Calculation/TextData/Replace.php b/src/PhpSpreadsheet/Calculation/TextData/Replace.php index f56d9d04..c3290a2a 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Replace.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Replace.php @@ -73,7 +73,6 @@ class Replace $text = Helpers::extractString($text); $fromText = Helpers::extractString($fromText); $toText = Helpers::extractString($toText); - $instance = Functions::flattenSingleValue($instance); if ($instance === null) { return str_replace($fromText, $toText, $text); } diff --git a/src/PhpSpreadsheet/Calculation/TextData/Text.php b/src/PhpSpreadsheet/Calculation/TextData/Text.php index 7247a35b..490c43c2 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Text.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Text.php @@ -3,7 +3,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Text { @@ -72,8 +71,6 @@ class Text return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $testValue); } - $testValue = Functions::flattenSingleValue($testValue); - if (is_string($testValue)) { return $testValue; }