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

PHP8.1 Deprecation Passing Null to String Function #2137

Merged
merged 3 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract public static function evaluate($database, $field, $criteria);
*/
protected static function fieldExtract(array $database, $field): ?int
{
$field = strtoupper(Functions::flattenSingleValue($field));
$field = strtoupper(Functions::flattenSingleValue($field ?? ''));
if ($field === '') {
return null;
}
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 @@ -37,7 +37,7 @@ public static function fromString($dateValue)
{
$dti = new DateTimeImmutable();
$baseYear = SharedDateHelper::getExcelCalendar();
$dateValue = trim(Functions::flattenSingleValue($dateValue), '"');
$dateValue = trim(Functions::flattenSingleValue($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
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TimeValue
*/
public static function fromString($timeValue)
{
$timeValue = trim(Functions::flattenSingleValue($timeValue), '"');
$timeValue = trim(Functions::flattenSingleValue($timeValue ?? ''), '"');
$timeValue = str_replace(['/', '.'], '-', $timeValue);

$arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: [];
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Calculation/TextData/Extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function left($value = '', $chars = 1): string
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}

return mb_substr($value, 0, $chars, 'UTF-8');
return mb_substr($value ?? '', 0, $chars, 'UTF-8');
}

/**
Expand All @@ -50,7 +50,7 @@ public static function mid($value = '', $start = 1, $chars = null): string
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}

return mb_substr($value, --$start, $chars, 'UTF-8');
return mb_substr($value ?? '', --$start, $chars, 'UTF-8');
}

/**
Expand All @@ -72,6 +72,6 @@ public static function right($value = '', $chars = 1): string
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}

return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8');
return mb_substr($value ?? '', mb_strlen($value ?? '', 'UTF-8') - $chars, $chars, 'UTF-8');
}
}
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/TextData/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function length($value = ''): int
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}

return mb_strlen($value, 'UTF-8');
return mb_strlen($value ?? '', 'UTF-8');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ private function applyInlineStyle(&$sheet, $row, $column, $attributeArray): void
*/
public function getStyleColor($value)
{
if (strpos($value, '#') === 0) {
if (strpos($value ?? '', '#') === 0) {
return substr($value, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xml/PageSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function printSetup(SimpleXMLElement $xmlX, stdClass $printDefaults): st

private function setLayout(stdClass $printDefaults, SimpleXMLElement $pageSetupAttributes): void
{
$printDefaults->orientation = (string) strtolower($pageSetupAttributes->Orientation) ?: PageSetup::ORIENTATION_PORTRAIT;
$printDefaults->orientation = (string) strtolower($pageSetupAttributes->Orientation ?? '') ?: PageSetup::ORIENTATION_PORTRAIT;
$printDefaults->horizontalCentered = (bool) $pageSetupAttributes->CenterHorizontal ?: false;
$printDefaults->verticalCentered = (bool) $pageSetupAttributes->CenterVertical ?: false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Shared/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public static function strToUpper($pValue)
*/
public static function strToLower($pValue)
{
return mb_convert_case($pValue, MB_CASE_LOWER, 'UTF-8');
return mb_convert_case($pValue ?? '', MB_CASE_LOWER, 'UTF-8');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ private function writeCellFormula(XMLWriter $objWriter, string $cellValue, Cell
$objWriter,
$this->getParentWriter()->getOffice2003Compatibility() === false,
'v',
($this->getParentWriter()->getPreCalculateFormulas() && !is_array($calculatedValue) && substr($calculatedValue, 0, 1) !== '#')
($this->getParentWriter()->getPreCalculateFormulas() && !is_array($calculatedValue) && substr($calculatedValue ?? '', 0, 1) !== '#')
? StringHelper::formatNumber($calculatedValue) : '0'
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function testIsFormula($expectedResult, $reference, $value = 'undefined')
->disableOriginalConstructor()
->getMock();
$remoteCell->method('isFormula')
->willReturn(substr($value, 0, 1) == '=');
->willReturn(substr($value ?? '', 0, 1) == '=');

$remoteSheet = $this->getMockBuilder(Worksheet::class)
->disableOriginalConstructor()
Expand Down