From 09c843427f2cfa8f4bfdfbd46bd364ecd798cde7 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 12 Jun 2022 19:21:43 +0200 Subject: [PATCH] Apply some coercive type-hinting --- .../Calculation/Calculation.php | 2 +- src/PhpSpreadsheet/Calculation/Functions.php | 2 +- .../Calculation/Information/ErrorValue.php | 2 +- .../Calculation/Information/ExcelError.php | 20 +++++++++---------- src/PhpSpreadsheet/Cell/DataType.php | 4 ++-- src/PhpSpreadsheet/ReferenceHelper.php | 6 +++--- src/PhpSpreadsheet/Shared/TimeZone.php | 10 +++++----- src/PhpSpreadsheet/Writer/Html.php | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 2bba56f6..588841dc 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -3088,7 +3088,7 @@ class Calculation } // Test whether we have any language data for this language (any locale) - if (in_array($language, self::$validLocaleLanguages)) { + if (in_array($language, self::$validLocaleLanguages, true)) { // initialise language/locale settings self::$localeFunctions = []; self::$localeArgumentSeparator = ','; diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index 1cc980b8..ddd3e200 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -152,7 +152,7 @@ class Functions if ($condition === '') { return '=""'; } - if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='])) { + if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='], true)) { $condition = self::operandSpecialHandling($condition); if (is_bool($condition)) { return '=' . ($condition ? 'TRUE' : 'FALSE'); diff --git a/src/PhpSpreadsheet/Calculation/Information/ErrorValue.php b/src/PhpSpreadsheet/Calculation/Information/ErrorValue.php index cffad6a6..869350ed 100644 --- a/src/PhpSpreadsheet/Calculation/Information/ErrorValue.php +++ b/src/PhpSpreadsheet/Calculation/Information/ErrorValue.php @@ -47,7 +47,7 @@ class ErrorValue return false; } - return in_array($value, ExcelError::$errorCodes) || $value === ExcelError::CALC(); + return in_array($value, ExcelError::$errorCodes, true) || $value === ExcelError::CALC(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Information/ExcelError.php b/src/PhpSpreadsheet/Calculation/Information/ExcelError.php index 585dfdc8..88de7e54 100644 --- a/src/PhpSpreadsheet/Calculation/Information/ExcelError.php +++ b/src/PhpSpreadsheet/Calculation/Information/ExcelError.php @@ -11,7 +11,7 @@ class ExcelError /** * List of error codes. * - * @var array + * @var array */ public static $errorCodes = [ 'null' => '#NULL!', @@ -60,7 +60,7 @@ class ExcelError * * @return string #NULL! */ - public static function null() + public static function null(): string { return self::$errorCodes['null']; } @@ -72,7 +72,7 @@ class ExcelError * * @return string #NUM! */ - public static function NAN() + public static function NAN(): string { return self::$errorCodes['num']; } @@ -84,7 +84,7 @@ class ExcelError * * @return string #REF! */ - public static function REF() + public static function REF(): string { return self::$errorCodes['reference']; } @@ -100,7 +100,7 @@ class ExcelError * * @return string #N/A! */ - public static function NA() + public static function NA(): string { return self::$errorCodes['na']; } @@ -112,7 +112,7 @@ class ExcelError * * @return string #VALUE! */ - public static function VALUE() + public static function VALUE(): string { return self::$errorCodes['value']; } @@ -124,7 +124,7 @@ class ExcelError * * @return string #NAME? */ - public static function NAME() + public static function NAME(): string { return self::$errorCodes['name']; } @@ -134,7 +134,7 @@ class ExcelError * * @return string #DIV/0! */ - public static function DIV0() + public static function DIV0(): string { return self::$errorCodes['divisionbyzero']; } @@ -142,9 +142,9 @@ class ExcelError /** * CALC. * - * @return string #Not Yet Implemented + * @return string #CALC! */ - public static function CALC() + public static function CALC(): string { return '#CALC!'; } diff --git a/src/PhpSpreadsheet/Cell/DataType.php b/src/PhpSpreadsheet/Cell/DataType.php index 390dcde5..16de2a00 100644 --- a/src/PhpSpreadsheet/Cell/DataType.php +++ b/src/PhpSpreadsheet/Cell/DataType.php @@ -21,7 +21,7 @@ class DataType /** * List of error codes. * - * @var array + * @var array */ private static $errorCodes = [ '#NULL!' => 0, @@ -36,7 +36,7 @@ class DataType /** * Get list of error codes. * - * @return array + * @return array */ public static function getErrorCodes() { diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 046c5894..36c85edf 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -399,7 +399,7 @@ class ReferenceHelper return $highestColumn . $row; }, range(1, $highestRow)), function ($coordinate) use ($allCoordinates) { - return !in_array($coordinate, $allCoordinates); + return in_array($coordinate, $allCoordinates, true) === false; } ); @@ -929,7 +929,7 @@ class ReferenceHelper $coordinate = Coordinate::stringFromColumnIndex($j + 1) . $i; $worksheet->removeConditionalStyles($coordinate); if ($worksheet->cellExists($coordinate)) { - $worksheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); + $worksheet->getCell($coordinate)->setValueExplicit(null, DataType::TYPE_NULL); $worksheet->getCell($coordinate)->setXfIndex(0); } } @@ -945,7 +945,7 @@ class ReferenceHelper $coordinate = Coordinate::stringFromColumnIndex($i + 1) . $j; $worksheet->removeConditionalStyles($coordinate); if ($worksheet->cellExists($coordinate)) { - $worksheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); + $worksheet->getCell($coordinate)->setValueExplicit(null, DataType::TYPE_NULL); $worksheet->getCell($coordinate)->setXfIndex(0); } } diff --git a/src/PhpSpreadsheet/Shared/TimeZone.php b/src/PhpSpreadsheet/Shared/TimeZone.php index dabb88f2..734c076d 100644 --- a/src/PhpSpreadsheet/Shared/TimeZone.php +++ b/src/PhpSpreadsheet/Shared/TimeZone.php @@ -21,9 +21,9 @@ class TimeZone * * @return bool Success or failure */ - private static function validateTimeZone($timezoneName) + private static function validateTimeZone(string $timezoneName): bool { - return in_array($timezoneName, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC)); + return in_array($timezoneName, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC), true); } /** @@ -33,7 +33,7 @@ class TimeZone * * @return bool Success or failure */ - public static function setTimeZone($timezoneName) + public static function setTimeZone(string $timezoneName): bool { if (self::validateTimezone($timezoneName)) { self::$timezone = $timezoneName; @@ -49,7 +49,7 @@ class TimeZone * * @return string Timezone (e.g. 'Europe/London') */ - public static function getTimeZone() + public static function getTimeZone(): string { return self::$timezone; } @@ -63,7 +63,7 @@ class TimeZone * * @return int Number of seconds for timezone adjustment */ - public static function getTimeZoneAdjustment($timezoneName, $timestamp) + public static function getTimeZoneAdjustment(?string $timezoneName, $timestamp): int { $timezoneName = $timezoneName ?? self::$timezone; $dtobj = Date::dateTimeFromTimestamp("$timestamp"); diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index 3ef65928..da32025a 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -1744,7 +1744,7 @@ class Html extends BaseWriter while ($c++ < $e) { $baseCell = $this->isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell']; - if (!in_array($baseCell, $adjustedBaseCells)) { + if (!in_array($baseCell, $adjustedBaseCells, true)) { // subtract rowspan by 1 --$this->isBaseCell[$sheetIndex][$baseCell[0]][$baseCell[1]]['rowspan']; $adjustedBaseCells[] = $baseCell;