Skip to content

Commit

Permalink
Eliminate calls to flattenSingleValue() that are no longer required w…
Browse files Browse the repository at this point in the history
…hen we're checking for array values as arguments (#2590)
  • Loading branch information
Mark Baker committed Feb 14, 2022
1 parent aff9783 commit 7e996a7
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
Expand Up @@ -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)
Expand Down
Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
Expand Up @@ -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) ?: [];
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 7e996a7

Please sign in to comment.