PHP8.1 Deprecation Passing Null to String Function (#2137)

For each of the files in this PR, one or more statements can pass a null to string functions like strlower. This is deprecated in PHP8.1, and, when deprecated messages are enabled, causes many tests to error out. In every case, use coercion to pass null string rather than null.
This commit is contained in:
oleibman 2021-06-05 06:14:23 -07:00 committed by GitHub
parent 19724e3217
commit a340240a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 12 additions and 12 deletions

View File

@ -27,7 +27,7 @@ abstract class DatabaseAbstract
*/
protected static function fieldExtract(array $database, $field): ?int
{
$field = strtoupper(Functions::flattenSingleValue($field));
$field = strtoupper(Functions::flattenSingleValue($field ?? ''));
if ($field === '') {
return null;
}

View File

@ -37,7 +37,7 @@ class 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)

View File

@ -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) ?: [];

View File

@ -26,7 +26,7 @@ class Extract
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}
return mb_substr($value, 0, $chars, 'UTF-8');
return mb_substr($value ?? '', 0, $chars, 'UTF-8');
}
/**
@ -50,7 +50,7 @@ class Extract
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}
return mb_substr($value, --$start, $chars, 'UTF-8');
return mb_substr($value ?? '', --$start, $chars, 'UTF-8');
}
/**
@ -72,6 +72,6 @@ class Extract
$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');
}
}

View File

@ -20,7 +20,7 @@ class Text
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}
return mb_strlen($value, 'UTF-8');
return mb_strlen($value ?? '', 'UTF-8');
}
/**

View File

@ -914,7 +914,7 @@ class Html extends BaseReader
*/
public function getStyleColor($value)
{
if (strpos($value, '#') === 0) {
if (strpos($value ?? '', '#') === 0) {
return substr($value, 1);
}

View File

@ -115,7 +115,7 @@ class PageSettings
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;
}

View File

@ -502,7 +502,7 @@ class StringHelper
*/
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');
}
/**

View File

@ -1256,7 +1256,7 @@ class Worksheet extends WriterPart
$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'
);
}

View File

@ -341,7 +341,7 @@ class FunctionsTest extends TestCase
->disableOriginalConstructor()
->getMock();
$remoteCell->method('isFormula')
->willReturn(substr($value, 0, 1) == '=');
->willReturn(substr($value ?? '', 0, 1) == '=');
$remoteSheet = $this->getMockBuilder(Worksheet::class)
->disableOriginalConstructor()