Skip to content

Commit

Permalink
More typing
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Dec 10, 2023
1 parent 959719a commit 2e48f15
Show file tree
Hide file tree
Showing 36 changed files with 53 additions and 213 deletions.
17 changes: 3 additions & 14 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3519,10 +3519,8 @@ public function calculateCellValue(?Cell $cell = null, bool $resetLog = true): m
* Validate and parse a formula string.
*
* @param string $formula Formula to parse
*
* @return array|bool
*/
public function parseFormula(string $formula)
public function parseFormula(string $formula): array|bool
{
// Basic validation that this is indeed a formula
// We return an empty array if not
Expand Down Expand Up @@ -5193,10 +5191,7 @@ private function executeBinaryComparisonOperation(mixed $operand1, mixed $operan
return $result;
}

/**
* @return bool|mixed
*/
private function executeNumericBinaryOperation(mixed $operand1, mixed $operand2, string $operation, Stack &$stack)
private function executeNumericBinaryOperation(mixed $operand1, mixed $operand2, string $operation, Stack &$stack): mixed
{
// Validate the two operands
if (
Expand Down Expand Up @@ -5516,9 +5511,6 @@ private function addDefaultArgumentValues(array $functionCall, array $args, arra
return $args;
}

/**
* @return null|mixed
*/
private function getArgumentDefaultValue(ReflectionParameter $methodArgument): mixed
{
$defaultValue = null;
Expand Down Expand Up @@ -5567,10 +5559,7 @@ private function addCellReference(array $args, bool $passCellReference, $functio
return $args;
}

/**
* @return mixed|string
*/
private function evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksheet $cellWorksheet, Stack $stack)
private function evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksheet $cellWorksheet, Stack $stack): mixed
{
$definedNameScope = $namedRange->getScope();
if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class Database
* includes at least one column label and at least one cell below
* the column label in which you specify a condition for the
* column.
*
* @return float|string
*/
public static function DAVERAGE(array $database, $field, array $criteria)
public static function DAVERAGE(array $database, $field, array $criteria): float|string|int
{
return Database\DAverage::evaluate($database, $field, $criteria);
}
Expand Down
15 changes: 5 additions & 10 deletions src/PhpSpreadsheet/Calculation/Engineering/BitWise.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ private static function splitNumber($number): array
* @param array|int $number2
* Or can be an array of values
*
* @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITAND($number1, $number2): array|string|int
Expand Down Expand Up @@ -72,8 +71,7 @@ public static function BITAND($number1, $number2): array|string|int
* @param array|int $number2
* Or can be an array of values
*
* @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITOR($number1, $number2): array|string|int
Expand Down Expand Up @@ -108,8 +106,7 @@ public static function BITOR($number1, $number2): array|string|int
* @param array|int $number2
* Or can be an array of values
*
* @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITXOR($number1, $number2): array|string|int
Expand Down Expand Up @@ -144,8 +141,7 @@ public static function BITXOR($number1, $number2): array|string|int
* @param array|int $shiftAmount
* Or can be an array of values
*
* @return array|float|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITLSHIFT($number, $shiftAmount): array|string|float
Expand Down Expand Up @@ -182,8 +178,7 @@ public static function BITLSHIFT($number, $shiftAmount): array|string|float
* @param array|int $shiftAmount
* Or can be an array of values
*
* @return array|float|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function BITRSHIFT($number, $shiftAmount): array|string|float
Expand Down
10 changes: 2 additions & 8 deletions src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ public static function validateNumericNullBool(mixed $number): int|float
* Validate numeric, but allow substitute for null.
*
* @param null|float|int $substitute
*
* @return float|int
*/
public static function validateNumericNullSubstitution(mixed $number, $substitute)
public static function validateNumericNullSubstitution(mixed $number, $substitute): float|int
{
$number = Functions::flattenSingleValue($number);
if ($number === null && $substitute !== null) {
Expand Down Expand Up @@ -113,12 +111,8 @@ public static function getEven(float $number): float

/**
* Return NAN or value depending on argument.
*
* @param float $result Number
*
* @return float|string
*/
public static function numberOrNan(float $result)
public static function numberOrNan(float $result): float|string
{
return is_nan($result) ? ExcelError::NAN() : $result;
}
Expand Down
3 changes: 1 addition & 2 deletions src/PhpSpreadsheet/Calculation/MathTrig/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public static function product(mixed ...$args): string|float
* @param mixed $denominator Expect float|int
* Or can be an array of values
*
* @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function quotient(mixed $numerator, mixed $denominator): array|string|int
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ function ($index) use ($cellReference): bool {
* but ignore any values in the range that are
* in hidden rows
* @param mixed[] $args A mixed data series of values
*
* @return float|string
*/
public static function evaluate(mixed $functionType, ...$args)
public static function evaluate(mixed $functionType, ...$args): float|int|string
{
$cellReference = array_pop($args);
$bArgs = Functions::flattenArrayIndexed($args);
Expand Down
8 changes: 2 additions & 6 deletions src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class Sum
* SUM(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|int|string
*/
public static function sumIgnoringStrings(mixed ...$args)
public static function sumIgnoringStrings(mixed ...$args): float|int|string
{
$returnValue = 0;

Expand All @@ -46,10 +44,8 @@ public static function sumIgnoringStrings(mixed ...$args)
* SUM(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|int|string
*/
public static function sumErroringStrings(mixed ...$args)
public static function sumErroringStrings(mixed ...$args): float|int|string|array
{
$returnValue = 0;
// Loop through the arguments
Expand Down
8 changes: 0 additions & 8 deletions src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class SumSquares
* SUMSQ(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function sumSquare(mixed ...$args): string|int|float
{
Expand Down Expand Up @@ -60,8 +58,6 @@ private static function numericNotString(mixed $item): bool
*
* @param mixed[] $matrixData1 Matrix #1
* @param mixed[] $matrixData2 Matrix #2
*
* @return float|string
*/
public static function sumXSquaredMinusYSquared(array $matrixData1, array $matrixData2): string|int|float
{
Expand All @@ -88,8 +84,6 @@ public static function sumXSquaredMinusYSquared(array $matrixData1, array $matri
*
* @param mixed[] $matrixData1 Matrix #1
* @param mixed[] $matrixData2 Matrix #2
*
* @return float|string
*/
public static function sumXSquaredPlusYSquared(array $matrixData1, array $matrixData2): string|int|float
{
Expand All @@ -116,8 +110,6 @@ public static function sumXSquaredPlusYSquared(array $matrixData1, array $matrix
*
* @param mixed[] $matrixData1 Matrix #1
* @param mixed[] $matrixData2 Matrix #2
*
* @return float|string
*/
public static function sumXMinusYSquared(array $matrixData1, array $matrixData2): string|int|float
{
Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Calculation/Statistical/AggregateBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ abstract class AggregateBase
* MS Excel does not count Booleans if passed as cell values, but they are counted if passed as literals.
* OpenOffice Calc always counts Booleans.
* Gnumeric never counts Booleans.
*
* @return int|mixed
*/
protected static function testAcceptedBoolean(mixed $arg, mixed $k): mixed
{
Expand Down
8 changes: 1 addition & 7 deletions src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Mean
* GEOMEAN(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function geometric(mixed ...$args): float|int|string
{
Expand All @@ -50,8 +48,6 @@ public static function geometric(mixed ...$args): float|int|string
* HARMEAN(value1[,value2[, ...]])
*
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function harmonic(mixed ...$args): string|float|int
{
Expand Down Expand Up @@ -93,10 +89,8 @@ public static function harmonic(mixed ...$args): string|float|int
* TRIMEAN(value1[,value2[, ...]], $discard)
*
* @param mixed $args Data values
*
* @return float|string
*/
public static function trim(mixed ...$args)
public static function trim(mixed ...$args): float|string
{
$aArgs = Functions::flattenArray($args);

Expand Down
28 changes: 7 additions & 21 deletions src/PhpSpreadsheet/Calculation/Statistical/Conditional.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ class Conditional
* @param mixed $range Data values
* @param null|array|string $condition the criteria that defines which cells will be checked
* @param mixed $averageRange Data values
*
* @return null|float|string
*/
public static function AVERAGEIF(mixed $range, null|array|string $condition, mixed $averageRange = [])
public static function AVERAGEIF(mixed $range, null|array|string $condition, mixed $averageRange = []): null|int|float|string
{
if (!is_array($range) || !is_array($averageRange) || array_key_exists(0, $range) || array_key_exists(0, $averageRange)) {
throw new CalcException('Must specify range of cells, not any kind of literal');
Expand All @@ -50,10 +48,8 @@ public static function AVERAGEIF(mixed $range, null|array|string $condition, mix
* AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2]…)
*
* @param mixed $args Pairs of Ranges and Criteria
*
* @return null|float|string
*/
public static function AVERAGEIFS(mixed ...$args)
public static function AVERAGEIFS(mixed ...$args): null|int|float|string
{
if (empty($args)) {
return 0.0;
Expand Down Expand Up @@ -106,10 +102,8 @@ public static function COUNTIF(array $range, null|array|string $condition): stri
* COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
*
* @param mixed $args Pairs of Ranges and Criteria
*
* @return int|string
*/
public static function COUNTIFS(mixed ...$args)
public static function COUNTIFS(mixed ...$args): int|string
{
if (empty($args)) {
return 0;
Expand All @@ -132,10 +126,8 @@ public static function COUNTIFS(mixed ...$args)
* MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2]…)
*
* @param mixed $args Pairs of Ranges and Criteria
*
* @return null|float|string
*/
public static function MAXIFS(mixed ...$args)
public static function MAXIFS(mixed ...$args): null|float|string
{
if (empty($args)) {
return 0.0;
Expand All @@ -156,10 +148,8 @@ public static function MAXIFS(mixed ...$args)
* MINIFS(min_range, criteria_range1, criteria1, [criteria_range2, criteria2]…)
*
* @param mixed $args Pairs of Ranges and Criteria
*
* @return null|float|string
*/
public static function MINIFS(mixed ...$args)
public static function MINIFS(mixed ...$args): null|float|string
{
if (empty($args)) {
return 0.0;
Expand All @@ -180,10 +170,8 @@ public static function MINIFS(mixed ...$args)
* SUMIF(range, criteria, [sum_range])
*
* @param array $range Data values
*
* @return null|float|string
*/
public static function SUMIF(array $range, mixed $condition, array $sumRange = [])
public static function SUMIF(array $range, mixed $condition, array $sumRange = []): null|float|string
{
$database = self::databaseFromRangeAndValue($range, $sumRange);
$condition = [[self::CONDITION_COLUMN_NAME, self::VALUE_COLUMN_NAME], [$condition, null]];
Expand All @@ -200,10 +188,8 @@ public static function SUMIF(array $range, mixed $condition, array $sumRange = [
* SUMIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2]…)
*
* @param mixed $args Pairs of Ranges and Criteria
*
* @return null|float|string
*/
public static function SUMIFS(mixed ...$args)
public static function SUMIFS(mixed ...$args): null|float|string
{
if (empty($args)) {
return 0.0;
Expand Down
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Calculation/Statistical/Deviations.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public static function sumSquares(mixed ...$args): string|float
* relatively flat distribution.
*
* @param array ...$args Data Series
*
* @return float|string
*/
public static function kurtosis(...$args): string|int|float
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ public static function negative(mixed $failures, mixed $successes, mixed $probab
* @param mixed $alpha criterion value as a float
* Or can be an array of values
*
* @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/
public static function inverse(mixed $trials, mixed $probability, mixed $alpha): array|string|int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,8 @@ public static function inverseLeftTail(mixed $probability, mixed $degrees): arra
*
* @param mixed $actual an array of observed frequencies
* @param mixed $expected an array of expected frequencies
*
* @return float|string
*/
public static function test(mixed $actual, mixed $expected)
public static function test(mixed $actual, mixed $expected): float|string
{
$rows = count($actual);
$actual = Functions::flattenArray($actual);
Expand Down
Loading

0 comments on commit 2e48f15

Please sign in to comment.