Eliminate calls to flattenSingleValue() that are no longer required in TextData Functions when we're checking for array values as arguments (#2592)

This commit is contained in:
Mark Baker 2022-02-15 01:29:12 +01:00 committed by GitHub
parent 70c12d2b05
commit 7901eb0b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1 additions and 21 deletions

View File

@ -3,7 +3,6 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class CaseConvert class CaseConvert
@ -28,7 +27,6 @@ class CaseConvert
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue); return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
} }
$mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue);
$mixedCaseValue = Helpers::extractString($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue);
return StringHelper::strToLower($mixedCaseValue); return StringHelper::strToLower($mixedCaseValue);
@ -52,7 +50,6 @@ class CaseConvert
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue); return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
} }
$mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue);
$mixedCaseValue = Helpers::extractString($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue);
return StringHelper::strToUpper($mixedCaseValue); return StringHelper::strToUpper($mixedCaseValue);
@ -76,7 +73,6 @@ class CaseConvert
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue); return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $mixedCaseValue);
} }
$mixedCaseValue = Functions::flattenSingleValue($mixedCaseValue);
$mixedCaseValue = Helpers::extractString($mixedCaseValue); $mixedCaseValue = Helpers::extractString($mixedCaseValue);
return StringHelper::strToTitle($mixedCaseValue); return StringHelper::strToTitle($mixedCaseValue);

View File

@ -53,8 +53,6 @@ class Concatenate
); );
} }
$delimiter = Functions::flattenSingleValue($delimiter);
$ignoreEmpty = Functions::flattenSingleValue($ignoreEmpty);
// Loop through arguments // Loop through arguments
$aArgs = Functions::flattenArray($args); $aArgs = Functions::flattenArray($args);
foreach ($aArgs as $key => &$arg) { foreach ($aArgs as $key => &$arg) {
@ -88,7 +86,6 @@ class Concatenate
return self::evaluateArrayArguments([self::class, __FUNCTION__], $stringValue, $repeatCount); return self::evaluateArrayArguments([self::class, __FUNCTION__], $stringValue, $repeatCount);
} }
$repeatCount = Functions::flattenSingleValue($repeatCount);
$stringValue = Helpers::extractString($stringValue); $stringValue = Helpers::extractString($stringValue);
if (!is_numeric($repeatCount) || $repeatCount < 0) { if (!is_numeric($repeatCount) || $repeatCount < 0) {

View File

@ -84,7 +84,6 @@ class Format
try { try {
$value = Helpers::extractFloat($value); $value = Helpers::extractFloat($value);
$decimals = Helpers::extractInt($decimals, -100, 0, true); $decimals = Helpers::extractInt($decimals, -100, 0, true);
$noCommas = Functions::flattenSingleValue($noCommas);
} catch (CalcExp $e) { } catch (CalcExp $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -140,7 +139,7 @@ class Format
*/ */
private static function convertValue($value) private static function convertValue($value)
{ {
$value = ($value === null) ? 0 : Functions::flattenSingleValue($value); $value = $value ?? 0;
if (is_bool($value)) { if (is_bool($value)) {
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) {
$value = (int) $value; $value = (int) $value;
@ -213,8 +212,6 @@ class Format
*/ */
private static function getDecimalSeparator($decimalSeparator): string private static function getDecimalSeparator($decimalSeparator): string
{ {
$decimalSeparator = Functions::flattenSingleValue($decimalSeparator);
return empty($decimalSeparator) ? StringHelper::getDecimalSeparator() : (string) $decimalSeparator; return empty($decimalSeparator) ? StringHelper::getDecimalSeparator() : (string) $decimalSeparator;
} }
@ -223,8 +220,6 @@ class Format
*/ */
private static function getGroupSeparator($groupSeparator): string private static function getGroupSeparator($groupSeparator): string
{ {
$groupSeparator = Functions::flattenSingleValue($groupSeparator);
return empty($groupSeparator) ? StringHelper::getThousandsSeparator() : (string) $groupSeparator; return empty($groupSeparator) ? StringHelper::getThousandsSeparator() : (string) $groupSeparator;
} }

View File

@ -22,7 +22,6 @@ class Helpers
*/ */
public static function extractString($value): string public static function extractString($value): string
{ {
$value = Functions::flattenSingleValue($value);
if (is_bool($value)) { if (is_bool($value)) {
return self::convertBooleanValue($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 public static function extractInt($value, int $minValue, int $gnumericNull = 0, bool $ooBoolOk = false): int
{ {
$value = Functions::flattenSingleValue($value);
if ($value === null) { if ($value === null) {
// usually 0, but sometimes 1 for Gnumeric // usually 0, but sometimes 1 for Gnumeric
$value = (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_GNUMERIC) ? $gnumericNull : 0; $value = (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_GNUMERIC) ? $gnumericNull : 0;
@ -59,7 +57,6 @@ class Helpers
*/ */
public static function extractFloat($value): float public static function extractFloat($value): float
{ {
$value = Functions::flattenSingleValue($value);
if ($value === null) { if ($value === null) {
$value = 0.0; $value = 0.0;
} }
@ -78,7 +75,6 @@ class Helpers
*/ */
public static function validateInt($value): int public static function validateInt($value): int
{ {
$value = Functions::flattenSingleValue($value);
if ($value === null) { if ($value === null) {
$value = 0; $value = 0;
} elseif (is_bool($value)) { } elseif (is_bool($value)) {

View File

@ -73,7 +73,6 @@ class Replace
$text = Helpers::extractString($text); $text = Helpers::extractString($text);
$fromText = Helpers::extractString($fromText); $fromText = Helpers::extractString($fromText);
$toText = Helpers::extractString($toText); $toText = Helpers::extractString($toText);
$instance = Functions::flattenSingleValue($instance);
if ($instance === null) { if ($instance === null) {
return str_replace($fromText, $toText, $text); return str_replace($fromText, $toText, $text);
} }

View File

@ -3,7 +3,6 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\TextData; namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Text class Text
{ {
@ -72,8 +71,6 @@ class Text
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $testValue); return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $testValue);
} }
$testValue = Functions::flattenSingleValue($testValue);
if (is_string($testValue)) { if (is_string($testValue)) {
return $testValue; return $testValue;
} }