Apply some coercive type-hinting

This commit is contained in:
MarkBaker 2022-06-12 19:21:43 +02:00
parent 67f87c87c2
commit 09c843427f
8 changed files with 24 additions and 24 deletions

View File

@ -3088,7 +3088,7 @@ class Calculation
} }
// Test whether we have any language data for this language (any locale) // 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 // initialise language/locale settings
self::$localeFunctions = []; self::$localeFunctions = [];
self::$localeArgumentSeparator = ','; self::$localeArgumentSeparator = ',';

View File

@ -152,7 +152,7 @@ class Functions
if ($condition === '') { if ($condition === '') {
return '=""'; return '=""';
} }
if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='])) { if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='], true)) {
$condition = self::operandSpecialHandling($condition); $condition = self::operandSpecialHandling($condition);
if (is_bool($condition)) { if (is_bool($condition)) {
return '=' . ($condition ? 'TRUE' : 'FALSE'); return '=' . ($condition ? 'TRUE' : 'FALSE');

View File

@ -47,7 +47,7 @@ class ErrorValue
return false; return false;
} }
return in_array($value, ExcelError::$errorCodes) || $value === ExcelError::CALC(); return in_array($value, ExcelError::$errorCodes, true) || $value === ExcelError::CALC();
} }
/** /**

View File

@ -11,7 +11,7 @@ class ExcelError
/** /**
* List of error codes. * List of error codes.
* *
* @var array * @var array<string, string>
*/ */
public static $errorCodes = [ public static $errorCodes = [
'null' => '#NULL!', 'null' => '#NULL!',
@ -60,7 +60,7 @@ class ExcelError
* *
* @return string #NULL! * @return string #NULL!
*/ */
public static function null() public static function null(): string
{ {
return self::$errorCodes['null']; return self::$errorCodes['null'];
} }
@ -72,7 +72,7 @@ class ExcelError
* *
* @return string #NUM! * @return string #NUM!
*/ */
public static function NAN() public static function NAN(): string
{ {
return self::$errorCodes['num']; return self::$errorCodes['num'];
} }
@ -84,7 +84,7 @@ class ExcelError
* *
* @return string #REF! * @return string #REF!
*/ */
public static function REF() public static function REF(): string
{ {
return self::$errorCodes['reference']; return self::$errorCodes['reference'];
} }
@ -100,7 +100,7 @@ class ExcelError
* *
* @return string #N/A! * @return string #N/A!
*/ */
public static function NA() public static function NA(): string
{ {
return self::$errorCodes['na']; return self::$errorCodes['na'];
} }
@ -112,7 +112,7 @@ class ExcelError
* *
* @return string #VALUE! * @return string #VALUE!
*/ */
public static function VALUE() public static function VALUE(): string
{ {
return self::$errorCodes['value']; return self::$errorCodes['value'];
} }
@ -124,7 +124,7 @@ class ExcelError
* *
* @return string #NAME? * @return string #NAME?
*/ */
public static function NAME() public static function NAME(): string
{ {
return self::$errorCodes['name']; return self::$errorCodes['name'];
} }
@ -134,7 +134,7 @@ class ExcelError
* *
* @return string #DIV/0! * @return string #DIV/0!
*/ */
public static function DIV0() public static function DIV0(): string
{ {
return self::$errorCodes['divisionbyzero']; return self::$errorCodes['divisionbyzero'];
} }
@ -142,9 +142,9 @@ class ExcelError
/** /**
* CALC. * CALC.
* *
* @return string #Not Yet Implemented * @return string #CALC!
*/ */
public static function CALC() public static function CALC(): string
{ {
return '#CALC!'; return '#CALC!';
} }

View File

@ -21,7 +21,7 @@ class DataType
/** /**
* List of error codes. * List of error codes.
* *
* @var array * @var array<string, int>
*/ */
private static $errorCodes = [ private static $errorCodes = [
'#NULL!' => 0, '#NULL!' => 0,
@ -36,7 +36,7 @@ class DataType
/** /**
* Get list of error codes. * Get list of error codes.
* *
* @return array * @return array<string, int>
*/ */
public static function getErrorCodes() public static function getErrorCodes()
{ {

View File

@ -399,7 +399,7 @@ class ReferenceHelper
return $highestColumn . $row; return $highestColumn . $row;
}, range(1, $highestRow)), }, range(1, $highestRow)),
function ($coordinate) use ($allCoordinates) { 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; $coordinate = Coordinate::stringFromColumnIndex($j + 1) . $i;
$worksheet->removeConditionalStyles($coordinate); $worksheet->removeConditionalStyles($coordinate);
if ($worksheet->cellExists($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); $worksheet->getCell($coordinate)->setXfIndex(0);
} }
} }
@ -945,7 +945,7 @@ class ReferenceHelper
$coordinate = Coordinate::stringFromColumnIndex($i + 1) . $j; $coordinate = Coordinate::stringFromColumnIndex($i + 1) . $j;
$worksheet->removeConditionalStyles($coordinate); $worksheet->removeConditionalStyles($coordinate);
if ($worksheet->cellExists($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); $worksheet->getCell($coordinate)->setXfIndex(0);
} }
} }

View File

@ -21,9 +21,9 @@ class TimeZone
* *
* @return bool Success or failure * @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 * @return bool Success or failure
*/ */
public static function setTimeZone($timezoneName) public static function setTimeZone(string $timezoneName): bool
{ {
if (self::validateTimezone($timezoneName)) { if (self::validateTimezone($timezoneName)) {
self::$timezone = $timezoneName; self::$timezone = $timezoneName;
@ -49,7 +49,7 @@ class TimeZone
* *
* @return string Timezone (e.g. 'Europe/London') * @return string Timezone (e.g. 'Europe/London')
*/ */
public static function getTimeZone() public static function getTimeZone(): string
{ {
return self::$timezone; return self::$timezone;
} }
@ -63,7 +63,7 @@ class TimeZone
* *
* @return int Number of seconds for timezone adjustment * @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; $timezoneName = $timezoneName ?? self::$timezone;
$dtobj = Date::dateTimeFromTimestamp("$timestamp"); $dtobj = Date::dateTimeFromTimestamp("$timestamp");

View File

@ -1744,7 +1744,7 @@ class Html extends BaseWriter
while ($c++ < $e) { while ($c++ < $e) {
$baseCell = $this->isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell']; $baseCell = $this->isSpannedCell[$sheetIndex][$rowIndex][$c]['baseCell'];
if (!in_array($baseCell, $adjustedBaseCells)) { if (!in_array($baseCell, $adjustedBaseCells, true)) {
// subtract rowspan by 1 // subtract rowspan by 1
--$this->isBaseCell[$sheetIndex][$baseCell[0]][$baseCell[1]]['rowspan']; --$this->isBaseCell[$sheetIndex][$baseCell[0]][$baseCell[1]]['rowspan'];
$adjustedBaseCells[] = $baseCell; $adjustedBaseCells[] = $baseCell;