Skip to content

Commit

Permalink
Add some return types
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Dec 9, 2023
1 parent f62245b commit 3c0350e
Show file tree
Hide file tree
Showing 51 changed files with 127 additions and 291 deletions.
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Calculation/Database/DAverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class DAverage extends DatabaseAbstract
* 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 evaluate($database, $field, $criteria): string|int|float
{
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DGet.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class DGet extends DatabaseAbstract
* 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 mixed
*/
public static function evaluate($database, $field, $criteria)
public static function evaluate($database, $field, $criteria): null|float|int|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DMax.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class DMax extends DatabaseAbstract
* 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 null|float|string
*/
public static function evaluate($database, $field, $criteria, bool $returnError = true)
public static function evaluate($database, $field, $criteria, bool $returnError = true): null|float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class DMin extends DatabaseAbstract
* 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 null|float|string
*/
public static function evaluate($database, $field, $criteria, bool $returnError = true)
public static function evaluate($database, $field, $criteria, bool $returnError = true): float|string|null
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DStDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class DStDev extends DatabaseAbstract
* 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 evaluate($database, $field, $criteria)
public static function evaluate($database, $field, $criteria): float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DStDevP.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class DStDevP extends DatabaseAbstract
* 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 evaluate($database, $field, $criteria)
public static function evaluate($database, $field, $criteria): float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DSum.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class DSum extends DatabaseAbstract
* 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 null|float|string
*/
public static function evaluate($database, $field, $criteria, bool $returnNull = false)
public static function evaluate($database, $field, $criteria, bool $returnNull = false): null|float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
9 changes: 2 additions & 7 deletions src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ abstract class DatabaseAbstract
* @param array $database
* @param null|int|string $field
* @param array $criteria
*
* @return null|float|int|string
*/
abstract public static function evaluate($database, $field, $criteria);
abstract public static function evaluate($database, $field, $criteria): null|float|int|string;

/**
* fieldExtract.
Expand Down Expand Up @@ -163,10 +161,7 @@ private static function executeQuery(array $database, string $query, array $crit
return $database;
}

/**
* @return mixed
*/
private static function processCondition(string $criterion, array $fields, array $dataValues, string $conditions)
private static function processCondition(string $criterion, array $fields, array $dataValues, string $conditions): mixed
{
$key = array_search($criterion, $fields, true);

Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ private static function initialDiff(float $startDate, float $endDate): float
* Decide whether it's time to set retVal.
*
* @param bool|int $retVal
*
* @return null|bool|int
*/
private static function replaceRetValue($retVal, string $unit, string $compare)
private static function replaceRetValue($retVal, string $unit, string $compare): null|bool|int
{
if ($retVal !== false || $unit !== $compare) {
return $retVal;
Expand Down
10 changes: 3 additions & 7 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = fa

/**
* Return result in one of three formats.
*
* @return mixed
*/
public static function returnIn3FormatsFloat(float $excelDateValue)
public static function returnIn3FormatsFloat(float $excelDateValue): float|int|DateTime
{
$retType = Functions::getReturnDateType();
if ($retType === Functions::RETURNDATE_EXCEL) {
return $excelDateValue;
}
if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
return (int) SharedDateHelper::excelToTimestamp($excelDateValue);
return SharedDateHelper::excelToTimestamp($excelDateValue);
}
// RETURNDATE_PHP_DATETIME_OBJECT

Expand Down Expand Up @@ -242,10 +240,8 @@ public static function validateNumericNull(mixed $number): int|float

/**
* Many functions accept null/false/true argument treated as 0/0/1.
*
* @return float
*/
public static function validateNotNegative(mixed $number)
public static function validateNotNegative(mixed $number): float
{
if (!is_numeric($number)) {
throw new Exception(ExcelError::VALUE());
Expand Down
9 changes: 3 additions & 6 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;

use DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
Expand Down Expand Up @@ -71,10 +72,8 @@ public static function date($startDate, $endDays, ...$dateArgs)

/**
* Use incrementing logic to determine Workday.
*
* @return mixed
*/
private static function incrementing(float $startDate, int $endDays, array $holidayArray)
private static function incrementing(float $startDate, int $endDays, array $holidayArray): float|int|DateTime
{
// Adjust the start date if it falls over a weekend
$startDoW = self::getWeekDay($startDate, 3);
Expand Down Expand Up @@ -132,10 +131,8 @@ private static function incrementingArray(float $startDate, float $endDate, arra

/**
* Use decrementing logic to determine Workday.
*
* @return mixed
*/
private static function decrementing(float $startDate, int $endDays, array $holidayArray)
private static function decrementing(float $startDate, int $endDays, array $holidayArray): float|int|DateTime
{
// Adjust the start date if it falls over a weekend
$startDoW = self::getWeekDay($startDate, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public function push(mixed $value): void

/**
* Pop the last entry from the stack.
*
* @return mixed
*/
public function pop()
public function pop(): mixed
{
return array_pop($this->stack);
}
Expand Down
16 changes: 4 additions & 12 deletions src/PhpSpreadsheet/Calculation/Engine/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ class Logger
* Flag to determine whether a debug log should be generated by the calculation engine
* If true, then a debug log will be generated
* If false, then a debug log will not be generated.
*
* @var bool
*/
private $writeDebugLog = false;
private bool $writeDebugLog = false;

/**
* Flag to determine whether a debug log should be echoed by the calculation engine
* If true, then a debug log will be echoed
* If false, then a debug log will not be echoed
* A debug log can only be echoed if it is generated.
*
* @var bool
*/
private $echoDebugLog = false;
private bool $echoDebugLog = false;

/**
* The debug log generated by the calculation engine.
Expand Down Expand Up @@ -55,10 +51,8 @@ public function setWriteDebugLog($writeDebugLog): void

/**
* Return whether calculation engine logging is enabled or disabled.
*
* @return bool
*/
public function getWriteDebugLog()
public function getWriteDebugLog(): bool
{
return $this->writeDebugLog;
}
Expand All @@ -75,10 +69,8 @@ public function setEchoDebugLog($echoDebugLog): void

/**
* Return whether echoing of debug log information is enabled or disabled.
*
* @return bool
*/
public function getEchoDebugLog()
public function getEchoDebugLog(): bool
{
return $this->echoDebugLog;
}
Expand Down
3 changes: 1 addition & 2 deletions src/PhpSpreadsheet/Calculation/Engineering/Complex.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class Complex
* If omitted, the suffix is assumed to be "i".
* Or can be an array of values
*
* @return array|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* @return array|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 COMPLEX(mixed $realNumber = 0.0, mixed $imaginary = 0.0, mixed $suffix = 'i'): array|string
Expand Down
Loading

0 comments on commit 3c0350e

Please sign in to comment.