Skip to content

Commit

Permalink
Merge pull request #2882 from PHPOffice/Datatype-Stricter-Typing
Browse files Browse the repository at this point in the history
Apply some coercive type-hinting
  • Loading branch information
MarkBaker authored Jun 12, 2022
2 parents 67f87c8 + 09c8434 commit 7b7d3bc
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,7 @@ public function setLocale(string $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
self::$localeFunctions = [];
self::$localeArgumentSeparator = ',';
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function ifCondition($condition)
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');
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Information/ErrorValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function isError($value = '')
return false;
}

return in_array($value, ExcelError::$errorCodes) || $value === ExcelError::CALC();
return in_array($value, ExcelError::$errorCodes, true) || $value === ExcelError::CALC();
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/PhpSpreadsheet/Calculation/Information/ExcelError.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ExcelError
/**
* List of error codes.
*
* @var array
* @var array<string, string>
*/
public static $errorCodes = [
'null' => '#NULL!',
Expand Down Expand Up @@ -60,7 +60,7 @@ public static function type($value = '')
*
* @return string #NULL!
*/
public static function null()
public static function null(): string
{
return self::$errorCodes['null'];
}
Expand All @@ -72,7 +72,7 @@ public static function null()
*
* @return string #NUM!
*/
public static function NAN()
public static function NAN(): string
{
return self::$errorCodes['num'];
}
Expand All @@ -84,7 +84,7 @@ public static function NAN()
*
* @return string #REF!
*/
public static function REF()
public static function REF(): string
{
return self::$errorCodes['reference'];
}
Expand All @@ -100,7 +100,7 @@ public static function REF()
*
* @return string #N/A!
*/
public static function NA()
public static function NA(): string
{
return self::$errorCodes['na'];
}
Expand All @@ -112,7 +112,7 @@ public static function NA()
*
* @return string #VALUE!
*/
public static function VALUE()
public static function VALUE(): string
{
return self::$errorCodes['value'];
}
Expand All @@ -124,7 +124,7 @@ public static function VALUE()
*
* @return string #NAME?
*/
public static function NAME()
public static function NAME(): string
{
return self::$errorCodes['name'];
}
Expand All @@ -134,17 +134,17 @@ public static function NAME()
*
* @return string #DIV/0!
*/
public static function DIV0()
public static function DIV0(): string
{
return self::$errorCodes['divisionbyzero'];
}

/**
* CALC.
*
* @return string #Not Yet Implemented
* @return string #CALC!
*/
public static function CALC()
public static function CALC(): string
{
return '#CALC!';
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Cell/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DataType
/**
* List of error codes.
*
* @var array
* @var array<string, int>
*/
private static $errorCodes = [
'#NULL!' => 0,
Expand All @@ -36,7 +36,7 @@ class DataType
/**
* Get list of error codes.
*
* @return array
* @return array<string, int>
*/
public static function getErrorCodes()
{
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function insertNewBefore(
return $highestColumn . $row;
}, range(1, $highestRow)),
function ($coordinate) use ($allCoordinates) {
return !in_array($coordinate, $allCoordinates);
return in_array($coordinate, $allCoordinates, true) === false;
}
);

Expand Down Expand Up @@ -929,7 +929,7 @@ private function clearColumnStrips(int $highestRow, int $beforeColumn, int $numb
$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);
}
}
Expand All @@ -945,7 +945,7 @@ private function clearRowStrips(string $highestColumn, int $beforeColumn, int $b
$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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/PhpSpreadsheet/Shared/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -33,7 +33,7 @@ private static function validateTimeZone($timezoneName)
*
* @return bool Success or failure
*/
public static function setTimeZone($timezoneName)
public static function setTimeZone(string $timezoneName): bool
{
if (self::validateTimezone($timezoneName)) {
self::$timezone = $timezoneName;
Expand All @@ -49,7 +49,7 @@ public static function setTimeZone($timezoneName)
*
* @return string Timezone (e.g. 'Europe/London')
*/
public static function getTimeZone()
public static function getTimeZone(): string
{
return self::$timezone;
}
Expand All @@ -63,7 +63,7 @@ public static function getTimeZone()
*
* @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");
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ private function calculateSpansOmitRows($sheet, $sheetIndex, $candidateSpannedRo
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;
Expand Down

0 comments on commit 7b7d3bc

Please sign in to comment.