Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate calls to flattenSingleValue() that are no longer required w… #2590

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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