diff --git a/src/PhpSpreadsheet/Calculation/ArrayEnabled.php b/src/PhpSpreadsheet/Calculation/ArrayEnabled.php index ad61eb7d..0ad429ed 100644 --- a/src/PhpSpreadsheet/Calculation/ArrayEnabled.php +++ b/src/PhpSpreadsheet/Calculation/ArrayEnabled.php @@ -12,12 +12,15 @@ trait ArrayEnabled */ private static $arrayArgumentHelper; - private static function initialiseHelper(array $arguments): void + /** + * @param array|false $arguments Can be changed to array for Php8.1+ + */ + private static function initialiseHelper($arguments): void { if (self::$arrayArgumentHelper === null) { self::$arrayArgumentHelper = new ArrayArgumentHelper(); } - self::$arrayArgumentHelper->initialise($arguments); + self::$arrayArgumentHelper->initialise($arguments ?: []); } /** @@ -70,6 +73,14 @@ trait ArrayEnabled return ArrayArgumentProcessor::processArguments(self::$arrayArgumentHelper, $method, ...$arguments); } + /** + * @param mixed $value + */ + private static function testFalse($value): bool + { + return $value === false; + } + /** * Handles array argument processing when the function accepts multiple arguments, * but only the last few (from start) can be an array arguments. @@ -85,7 +96,7 @@ trait ArrayEnabled range($start, count($arguments) - $start), array_slice($arguments, $start) ); - if ($arrayArgumentsSubset === false) { + if (self::testFalse($arrayArgumentsSubset)) { return ['#VALUE!']; } diff --git a/src/PhpSpreadsheet/Calculation/Information/Value.php b/src/PhpSpreadsheet/Calculation/Information/Value.php index e29144b8..0ac6b669 100644 --- a/src/PhpSpreadsheet/Calculation/Information/Value.php +++ b/src/PhpSpreadsheet/Calculation/Information/Value.php @@ -87,7 +87,7 @@ class Value return ExcelError::VALUE(); } - return $value % 2 == 0; + return ((int) fmod($value, 2)) === 0; } /** @@ -112,7 +112,7 @@ class Value return ExcelError::VALUE(); } - return abs($value) % 2 == 1; + return ((int) fmod($value, 2)) !== 0; } /** diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index b4b76c57..6c3fce60 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -92,6 +92,7 @@ abstract class Coordinate } // Create absolute coordinate + $cellAddress = "$cellAddress"; if (ctype_digit($cellAddress)) { return $worksheet . '$' . $cellAddress; } elseif (ctype_alpha($cellAddress)) { diff --git a/src/PhpSpreadsheet/Helper/Dimension.php b/src/PhpSpreadsheet/Helper/Dimension.php index 136ffd7f..4e3e6680 100644 --- a/src/PhpSpreadsheet/Helper/Dimension.php +++ b/src/PhpSpreadsheet/Helper/Dimension.php @@ -58,7 +58,7 @@ class Dimension public function __construct(string $dimension) { [$size, $unit] = sscanf($dimension, '%[1234567890.]%s'); - $unit = strtolower(trim($unit)); + $unit = strtolower(trim($unit ?? '')); // If a UoM is specified, then convert the size to pixels for internal storage if (isset(self::ABSOLUTE_UNITS[$unit])) { diff --git a/src/PhpSpreadsheet/Helper/Html.php b/src/PhpSpreadsheet/Helper/Html.php index 73a3308c..4eecf99d 100644 --- a/src/PhpSpreadsheet/Helper/Html.php +++ b/src/PhpSpreadsheet/Helper/Html.php @@ -794,7 +794,7 @@ class Html $domText = preg_replace( '/\s+/u', ' ', - str_replace(["\r", "\n"], ' ', $textNode->nodeValue) + str_replace(["\r", "\n"], ' ', $textNode->nodeValue ?: '') ); $this->stringData .= $domText; $this->buildTextRun(); diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 9d02fee9..15c9f625 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -619,7 +619,7 @@ class Html extends BaseReader { foreach ($element->childNodes as $child) { if ($child instanceof DOMText) { - $domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue)); + $domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue ?: '')); if (is_string($cellContent)) { // simply append the text if the cell content is a plain text string $cellContent .= $domText; diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index d0d87c5f..791c0780 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -617,7 +617,7 @@ class Ods extends BaseReader foreach ($settings->getElementsByTagNameNS($configNs, 'config-item') as $t) { if ($t->getAttributeNs($configNs, 'name') === 'ActiveTable') { try { - $spreadsheet->setActiveSheetIndexByName($t->nodeValue); + $spreadsheet->setActiveSheetIndexByName($t->nodeValue ?: ''); } catch (Throwable $e) { // do nothing } diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index 1bc71184..2e6c8289 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php @@ -386,7 +386,7 @@ class AutoFilter /** @var string */ $ruleOperator = $rule['operator']; /** @var string */ - $cellValueString = $cellValue; + $cellValueString = $cellValue ?? ''; $retVal = false; if (is_numeric($ruleValue)) { diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index c5502a33..06c8becf 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -1279,7 +1279,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' ); }