Skip to content

Commit

Permalink
A few more native param types
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Dec 12, 2023
1 parent 161d82d commit f1772bf
Show file tree
Hide file tree
Showing 39 changed files with 50 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DAverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DAverage extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria): string|int|float
public static function evaluate(array $database, array|null|int|string $field, array $criteria): string|int|float
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DCount extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria, bool $returnError = true): string|int
public static function evaluate(array $database, array|null|int|string $field, array $criteria, bool $returnError = true): string|int
{
$field = self::fieldExtract($database, $field);
if ($returnError && $field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DCountA.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DCountA extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria): string|int
public static function evaluate(array $database, array|null|int|string $field, array $criteria): string|int
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DGet.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DGet extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria): null|float|int|string
public static function evaluate(array $database, array|null|int|string $field, array $criteria): null|float|int|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DMax.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DMax extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria, bool $returnError = true): null|float|string
public static function evaluate(array $database, array|null|int|string $field, array $criteria, bool $returnError = true): null|float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DMin extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria, bool $returnError = true): float|string|null
public static function evaluate(array $database, array|null|int|string $field, array $criteria, bool $returnError = true): float|string|null
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DProduct extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria): string|float
public static function evaluate(array $database, array|null|int|string $field, array $criteria): string|float
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DStDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DStDev extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria): float|string
public static function evaluate(array $database, array|null|int|string $field, array $criteria): float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DStDevP.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DStDevP extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria): float|string
public static function evaluate(array $database, array|null|int|string $field, array $criteria): float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DSum.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DSum extends DatabaseAbstract
* the column label in which you specify a condition for the
* column.
*/
public static function evaluate(array $database, $field, array $criteria, bool $returnNull = false): null|float|string
public static function evaluate(array $database, array|null|int|string $field, array $criteria, bool $returnNull = false): null|float|string
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DVar.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DVar extends DatabaseAbstract
*
* @return float|string (string if result is an error)
*/
public static function evaluate(array $database, $field, array $criteria): string|float
public static function evaluate(array $database, array|null|int|string $field, array $criteria): string|float
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Database/DVarP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DVarP extends DatabaseAbstract
*
* @return float|string (string if result is an error)
*/
public static function evaluate(array $database, $field, array $criteria): string|float
public static function evaluate(array $database, array|null|int|string $field, array $criteria): string|float
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

abstract class DatabaseAbstract
{
abstract public static function evaluate(array $database, null|int|string $field, array $criteria): null|float|int|string;
abstract public static function evaluate(array $database, array|null|int|string $field, array $criteria): null|float|int|string;

/**
* fieldExtract.
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Date
* A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
* as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
*
* @param array|int $year The value of the year argument can include one to four digits.
* @param array|int|string $year The value of the year argument can include one to four digits.
* Excel interprets the year argument according to the configured
* date system: 1900 or 1904.
* If year is between 0 (zero) and 1899 (inclusive), Excel adds that
Expand All @@ -38,7 +38,7 @@ class Date
* 2008.
* If year is less than 0 or is 10000 or greater, Excel returns the
* #NUM! error value.
* @param array|int $month A positive or negative integer representing the month of the year
* @param array|float|int|string $month A positive or negative integer representing the month of the year
* from 1 to 12 (January to December).
* If month is greater than 12, month adds that number of months to
* the first month in the year specified. For example, DATE(2008,14,2)
Expand All @@ -47,7 +47,7 @@ class Date
* number of months, plus 1, from the first month in the year
* specified. For example, DATE(2008,-3,2) returns the serial number
* representing September 2, 2007.
* @param array|int $day A positive or negative integer representing the day of the month
* @param array|float|int|string $day A positive or negative integer representing the day of the month
* from 1 to 31.
* If day is greater than the number of days in the month specified,
* day adds that number of days to the first day in the month. For
Expand All @@ -63,7 +63,7 @@ class Date
* If an array of numbers is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function fromYMD($year, $month, $day): mixed
public static function fromYMD(array|int|string $year, array|float|int|string $month, array|float|int|string $day): mixed
{
if (is_array($year) || is_array($month) || is_array($day)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $year, $month, $day);
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DateValue
* Excel Function:
* DATEVALUE(dateValue)
*
* @param null|array|string $dateValue Text that represents a date in a Microsoft Excel date format.
* @param null|array|int|string $dateValue Text that represents a date in a Microsoft Excel date format.
* For example, "1/30/2008" or "30-Jan-2008" are text strings within
* quotation marks that represent dates. Using the default date
* system in Excel for Windows, date_text must represent a date from
Expand All @@ -39,7 +39,7 @@ class DateValue
* If an array of numbers is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function fromString($dateValue): mixed
public static function fromString(null|array|string|int|bool $dateValue): mixed
{
if (is_array($dateValue)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue);
Expand All @@ -52,7 +52,7 @@ public static function fromString($dateValue): mixed

$dti = new DateTimeImmutable();
$baseYear = SharedDateHelper::getExcelCalendar();
$dateValue = trim($dateValue ?? '', '"');
$dateValue = trim((string) $dateValue, '"');
// Strip any ordinals because they're allowed in Excel (English only)
$dateValue = (string) preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue);
// Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Days
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
* will also be an array with matching dimensions
*/
public static function between($endDate, $startDate)
public static function between(array|DateTimeInterface|float|int|string $endDate, array|DateTimeInterface|float|int|string $startDate): array|int|string
{
if (is_array($endDate) || is_array($startDate)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $endDate, $startDate);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Days360
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
* will also be an array with matching dimensions
*/
public static function between($startDate = 0, $endDate = 0, $method = false): array|string|int
public static function between(mixed $startDate = 0, mixed $endDate = 0, mixed $method = false): array|string|int
{
if (is_array($startDate) || is_array($endDate) || is_array($method)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $startDate, $endDate, $method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Difference
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
* will also be an array with matching dimensions
*/
public static function interval(mixed $startDate, mixed $endDate, $unit = 'D')
public static function interval(mixed $startDate, mixed $endDate, array|string $unit = 'D')
{
if (is_array($startDate) || is_array($endDate) || is_array($unit)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $startDate, $endDate, $unit);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Helpers
*
* @return bool TRUE if the year is a leap year, otherwise FALSE
*/
public static function isLeapYear($year): bool
public static function isLeapYear(int|string $year): bool
{
return (($year % 4) === 0) && (($year % 100) !== 0) || (($year % 400) === 0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Month
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function adjust(mixed $dateValue, $adjustmentMonths)
public static function adjust(mixed $dateValue, array|string|bool|float|int $adjustmentMonths)
{
if (is_array($dateValue) || is_array($adjustmentMonths)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $adjustmentMonths);
Expand Down Expand Up @@ -77,7 +77,7 @@ public static function adjust(mixed $dateValue, $adjustmentMonths)
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function lastDay(mixed $dateValue, $adjustmentMonths)
public static function lastDay(mixed $dateValue, array|float|int|bool|string $adjustmentMonths): mixed
{
if (is_array($dateValue) || is_array($adjustmentMonths)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $adjustmentMonths);
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class Time
* Excel Function:
* TIME(hour,minute,second)
*
* @param array|int $hour A number from 0 (zero) to 32767 representing the hour.
* @param null|array|bool|float|int|string $hour A number from 0 (zero) to 32767 representing the hour.
* Any value greater than 23 will be divided by 24 and the remainder
* will be treated as the hour value. For example, TIME(27,0,0) =
* TIME(3,0,0) = .125 or 3:00 AM.
* @param array|int $minute A number from 0 to 32767 representing the minute.
* @param null|array|bool|float|int|string $minute A number from 0 to 32767 representing the minute.
* Any value greater than 59 will be converted to hours and minutes.
* For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM.
* @param array|int $second A number from 0 to 32767 representing the second.
* @param null|array|bool|float|int|string $second A number from 0 to 32767 representing the second.
* Any value greater than 59 will be converted to hours, minutes,
* and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148
* or 12:33:20 AM
Expand All @@ -43,7 +43,7 @@ class Time
* If an array of numbers is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function fromHMS($hour, $minute, $second): array|string|float|int|DateTime
public static function fromHMS(array|int|float|bool|null|string $hour, array|int|float|bool|null|string $minute, array|int|float|bool|null|string $second): array|string|float|int|DateTime
{
if (is_array($hour) || is_array($minute) || is_array($second)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $hour, $minute, $second);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TimeValue
* If an array of numbers is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function fromString($timeValue): array|string|Datetime|int|float
public static function fromString(null|array|string|int|bool $timeValue): array|string|Datetime|int|float
{
if (is_array($timeValue)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Week
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function number(mixed $dateValue, $method = Constants::STARTWEEK_SUNDAY): array|int|string
public static function number(mixed $dateValue, array|int|string|null $method = Constants::STARTWEEK_SUNDAY): array|int|string
{
if (is_array($dateValue) || is_array($method)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $method);
Expand Down Expand Up @@ -150,7 +150,7 @@ public static function isoWeekNumber(mixed $dateValue): array|int|string
* If an array of values is passed as the argument, then the returned result will also be an array
* with the same dimensions
*/
public static function day($dateValue, mixed $style = 1): array|string|int
public static function day(null|array|float|int|string|bool $dateValue, mixed $style = 1): array|string|int
{
if (is_array($dateValue) || is_array($style)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $style);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class WorkDay
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
* will also be an array with matching dimensions
*/
public static function date($startDate, $endDays, ...$dateArgs)
public static function date(mixed $startDate, array|int|string $endDays, mixed ...$dateArgs): mixed
{
if (is_array($startDate) || is_array($endDays)) {
return self::evaluateArrayArgumentsSubset(
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class YearFrac
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
* will also be an array with matching dimensions
*/
public static function fraction(mixed $startDate, mixed $endDate, $method = 0): array|string|int|float
public static function fraction(mixed $startDate, mixed $endDate, array|int|string|null $method = 0): array|string|int|float
{
if (is_array($startDate) || is_array($endDate) || is_array($method)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $startDate, $endDate, $method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function rows(array $arguments): array
private function columns(array $arguments): array
{
return array_map(
function ($argument): int {
function (mixed $argument): int {
return is_array($argument) && is_array($argument[array_keys($argument)[0]])
? count($argument[array_keys($argument)[0]])
: 1;
Expand Down
Loading

0 comments on commit f1772bf

Please sign in to comment.