From abbdc716fd2362e472c714c11cbe9746d0485847 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 14 Feb 2022 22:47:07 +0100 Subject: [PATCH] Eliminate calls to flattenSingleValue() that are no longer required when we're checking for array values as arguments --- src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php | 5 ----- src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php | 2 +- src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php | 2 +- src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php | 1 - src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php | 4 ---- src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php | 2 +- src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php | 4 +--- 7 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php index 188eebc5a9..b1c1ece847 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php @@ -93,7 +93,6 @@ public static function fromYMD($year, $month, $day) */ private static function getYear($year, int $baseYear): int { - $year = Functions::flattenSingleValue($year); $year = ($year !== null) ? StringHelper::testStringAsNumeric((string) $year) : 0; if (!is_numeric($year)) { throw new Exception(Functions::VALUE()); @@ -121,8 +120,6 @@ private static function getYear($year, int $baseYear): int */ private static function getMonth($month): int { - $month = Functions::flattenSingleValue($month); - if (($month !== null) && (!is_numeric($month))) { $month = SharedDateHelper::monthStringToNumber($month); } @@ -142,8 +139,6 @@ private static function getMonth($month): int */ private static function getDay($day): int { - $day = Functions::flattenSingleValue($day); - if (($day !== null) && (!is_numeric($day))) { $day = SharedDateHelper::dayStringToNumber($day); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php index f8fe3e8ad0..47a68cf9e1 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php @@ -47,7 +47,7 @@ public static function fromString($dateValue) $dti = new DateTimeImmutable(); $baseYear = SharedDateHelper::getExcelCalendar(); - $dateValue = trim(Functions::flattenSingleValue($dateValue ?? ''), '"'); + $dateValue = trim($dateValue ?? '', '"'); // Strip any ordinals because they're allowed in Excel (English only) $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? ''; // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany) diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php index 1f4812f22c..4dd7826391 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php @@ -39,7 +39,7 @@ public static function interval($startDate, $endDate, $unit = 'D') $startDate = Helpers::getDateValue($startDate); $endDate = Helpers::getDateValue($endDate); $difference = self::initialDiff($startDate, $endDate); - $unit = strtoupper(Functions::flattenSingleValue($unit)); + $unit = strtoupper($unit); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php index e176e6e1de..f5e685f491 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php @@ -116,7 +116,6 @@ private static function adjustMinute(int &$minute, int &$hour): void */ private static function toIntWithNullBool($value): int { - $value = Functions::flattenSingleValue($value); $value = $value ?? 0; if (is_bool($value)) { $value = (int) $value; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php index 7969e4e305..d9b99f3c36 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php @@ -4,7 +4,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class TimeParts @@ -35,7 +34,6 @@ public static function hour($timeValue) } try { - $timeValue = Functions::flattenSingleValue($timeValue); Helpers::nullFalseTrueToNumber($timeValue); if (!is_numeric($timeValue)) { $timeValue = Helpers::getTimeValue($timeValue); @@ -76,7 +74,6 @@ public static function minute($timeValue) } try { - $timeValue = Functions::flattenSingleValue($timeValue); Helpers::nullFalseTrueToNumber($timeValue); if (!is_numeric($timeValue)) { $timeValue = Helpers::getTimeValue($timeValue); @@ -117,7 +114,6 @@ public static function second($timeValue) } try { - $timeValue = Functions::flattenSingleValue($timeValue); Helpers::nullFalseTrueToNumber($timeValue); if (!is_numeric($timeValue)) { $timeValue = Helpers::getTimeValue($timeValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php index 5a36f1b0d4..f57c9f005c 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php @@ -41,7 +41,7 @@ public static function fromString($timeValue) return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue); } - $timeValue = trim(Functions::flattenSingleValue($timeValue ?? ''), '"'); + $timeValue = trim($timeValue ?? '', '"'); $timeValue = str_replace(['/', '.'], '-', $timeValue); $arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: []; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php index cc51d24f67..c6ca0f8165 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php @@ -191,8 +191,6 @@ public static function day($dateValue, $style = 1) */ private static function validateStyle($style): int { - $style = Functions::flattenSingleValue($style); - if (!is_numeric($style)) { throw new Exception(Functions::VALUE()); } @@ -251,7 +249,7 @@ private static function validateMethod($method): int if ($method === null) { $method = Constants::STARTWEEK_SUNDAY; } - $method = Functions::flattenSingleValue($method); + if (!is_numeric($method)) { throw new Exception(Functions::VALUE()); }