Skip to content

Commit 5faaf26

Browse files
authored
Merge pull request #3872 from PHPOffice/powerkiki
Remove all `mixed` in return type where possible
2 parents 936805a + 013e5cc commit 5faaf26

22 files changed

+64
-38
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ parameters:
2323
parallel:
2424
processTimeout: 300.0
2525
checkMissingIterableValueType: false
26+
checkGenericClassInNonGenericObjectType: false
2627
ignoreErrors:
2728
# Accept a bit anything for assert methods
2829
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static function getLocaleBoolean(string $index): string
195195
* Excel constant string translations to their PHP equivalents
196196
* Constant conversion from text name/value to actual (datatyped) value.
197197
*
198-
* @var array<string, mixed>
198+
* @var array<string, null|bool>
199199
*/
200200
private static array $excelConstants = [
201201
'TRUE' => true,
@@ -208,7 +208,7 @@ public static function keyInExcelConstants(string $key): bool
208208
return array_key_exists($key, self::$excelConstants);
209209
}
210210

211-
public static function getExcelConstants(string $key): mixed
211+
public static function getExcelConstants(string $key): bool|null
212212
{
213213
return self::$excelConstants[$key];
214214
}

src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static function executeQuery(array $database, string $query, array $crit
156156
return $database;
157157
}
158158

159-
private static function processCondition(string $criterion, array $fields, array $dataValues, string $conditions): mixed
159+
private static function processCondition(string $criterion, array $fields, array $dataValues, string $conditions): string
160160
{
161161
$key = array_search($criterion, $fields, true);
162162

src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
44

5+
use DateTime;
56
use DateTimeImmutable;
67
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
78

@@ -21,10 +22,10 @@ class Current
2122
* Excel Function:
2223
* TODAY()
2324
*
24-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
25+
* @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
2526
* depending on the value of the ReturnDateType flag
2627
*/
27-
public static function today(): mixed
28+
public static function today(): DateTime|float|int|string
2829
{
2930
$dti = new DateTimeImmutable();
3031
$dateArray = Helpers::dateParse($dti->format('c'));
@@ -46,10 +47,10 @@ public static function today(): mixed
4647
* Excel Function:
4748
* NOW()
4849
*
49-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
50+
* @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
5051
* depending on the value of the ReturnDateType flag
5152
*/
52-
public static function now(): mixed
53+
public static function now(): DateTime|float|int|string
5354
{
5455
$dti = new DateTimeImmutable();
5556
$dateArray = Helpers::dateParse($dti->format('c'));

src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
44

5+
use DateTime;
56
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
67
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
78
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
@@ -58,12 +59,12 @@ class Date
5859
* example, DATE(2008,1,-15) returns the serial number representing
5960
* December 16, 2007.
6061
*
61-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
62+
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
6263
* depending on the value of the ReturnDateType flag
6364
* If an array of numbers is passed as the argument, then the returned result will also be an array
6465
* with the same dimensions
6566
*/
66-
public static function fromYMD(array|float|int|string $year, array|float|int|string $month, array|float|int|string $day): mixed
67+
public static function fromYMD(array|float|int|string $year, array|float|int|string $month, array|float|int|string $day): float|int|DateTime|string|array
6768
{
6869
if (is_array($year) || is_array($month) || is_array($day)) {
6970
return self::evaluateArrayArguments([self::class, __FUNCTION__], $year, $month, $day);

src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
44

5+
use DateTime;
56
use DateTimeImmutable;
67
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
78
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
@@ -34,12 +35,12 @@ class DateValue
3435
* #VALUE! error value if date_text is out of this range.
3536
* Or can be an array of date values
3637
*
37-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
38+
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
3839
* depending on the value of the ReturnDateType flag
3940
* If an array of numbers is passed as the argument, then the returned result will also be an array
4041
* with the same dimensions
4142
*/
42-
public static function fromString(null|array|string|int|bool|float $dateValue): mixed
43+
public static function fromString(null|array|string|int|bool|float $dateValue): array|string|float|int|DateTime
4344
{
4445
if (is_array($dateValue)) {
4546
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue);
@@ -131,10 +132,10 @@ private static function setUpArray(string $dateValue, DateTimeImmutable $dti): a
131132
/**
132133
* Final results.
133134
*
134-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
135+
* @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
135136
* depending on the value of the ReturnDateType flag
136137
*/
137-
private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear): mixed
138+
private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear): string|float|int|DateTime
138139
{
139140
$retValue = ExcelError::Value();
140141
if (Helpers::dateParseSucceeded($PHPDateArray)) {

src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ public static function getDateValue(mixed $dateValue, bool $allowBool = true): f
5858
/**
5959
* getTimeValue.
6060
*
61-
* @return mixed Excel date/time serial value, or string if error
61+
* @return float|string Excel date/time serial value, or string if error
6262
*/
63-
public static function getTimeValue(string $timeValue): mixed
63+
public static function getTimeValue(string $timeValue): string|float
6464
{
6565
$saveReturnDateType = Functions::getReturnDateType();
6666
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
67+
/** @var float|string $timeValue */
6768
$timeValue = TimeValue::fromString($timeValue);
6869
Functions::setReturnDateType($saveReturnDateType);
6970

@@ -238,6 +239,8 @@ public static function validateNumericNull(mixed $number): int|float
238239

239240
/**
240241
* Many functions accept null/false/true argument treated as 0/0/1.
242+
*
243+
* @phpstan-assert float $number
241244
*/
242245
public static function validateNotNegative(mixed $number): float
243246
{

src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public static function adjust(mixed $dateValue, array|string|bool|float|int $adj
7373
* a negative value yields a past date.
7474
* Or can be an array of adjustment values
7575
*
76-
* @return array|mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
76+
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
7777
* depending on the value of the ReturnDateType flag
7878
* If an array of values is passed as the argument, then the returned result will also be an array
7979
* with the same dimensions
8080
*/
81-
public static function lastDay(mixed $dateValue, array|float|int|bool|string $adjustmentMonths): mixed
81+
public static function lastDay(mixed $dateValue, array|float|int|bool|string $adjustmentMonths): array|string|DateTime|float|int
8282
{
8383
if (is_array($dateValue) || is_array($adjustmentMonths)) {
8484
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $adjustmentMonths);

src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class WorkDay
3131
* Or can be an array of int values
3232
* @param null|mixed $dateArgs An array of dates (such as holidays) to exclude from the calculation
3333
*
34-
* @return array|mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
34+
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
3535
* depending on the value of the ReturnDateType flag
3636
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
3737
* will also be an array with matching dimensions
3838
*/
39-
public static function date(mixed $startDate, array|int|string $endDays, mixed ...$dateArgs): mixed
39+
public static function date(mixed $startDate, array|int|string $endDays, mixed ...$dateArgs): array|float|int|DateTime|string
4040
{
4141
if (is_array($startDate) || is_array($endDays)) {
4242
return self::evaluateArrayArgumentsSubset(

src/PhpSpreadsheet/Calculation/Functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static function flattenArrayIndexed($array): array
277277
*
278278
* @param mixed $value Array or scalar value
279279
*/
280-
public static function flattenSingleValue(mixed $value = ''): mixed
280+
public static function flattenSingleValue(mixed $value): mixed
281281
{
282282
while (is_array($value)) {
283283
$value = array_shift($value);

0 commit comments

Comments
 (0)