Skip to content

Commit e221aa6

Browse files
committed
Rector ReturnUnionTypeRector
1 parent 7cffb84 commit e221aa6

File tree

128 files changed

+548
-669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+548
-669
lines changed

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,7 +3999,7 @@ private function showTypeDetails($value): ?string
39993999
/**
40004000
* @return false|string False indicates an error
40014001
*/
4002-
private function convertMatrixReferences(string $formula)
4002+
private function convertMatrixReferences(string $formula): false|string
40034003
{
40044004
static $matrixReplaceFrom = [self::FORMULA_OPEN_MATRIX_BRACE, ';', self::FORMULA_CLOSE_MATRIX_BRACE];
40054005
static $matrixReplaceTo = ['MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))'];
@@ -4102,7 +4102,7 @@ private function convertMatrixReferences(string $formula)
41024102
*
41034103
* @return array<int, mixed>|false
41044104
*/
4105-
private function internalParseFormula($formula, ?Cell $cell = null)
4105+
private function internalParseFormula($formula, ?Cell $cell = null): bool|array
41064106
{
41074107
if (($formula = $this->convertMatrixReferences(trim($formula))) === false) {
41084108
return false;
@@ -4426,6 +4426,7 @@ private function internalParseFormula($formula, ?Cell $cell = null)
44264426
} elseif ($val === Information\ExcelError::REF()) {
44274427
$stackItemReference = $val;
44284428
} else {
4429+
/** @var non-empty-string $startRowColRef */
44294430
$startRowColRef = $output[count($output) - 1]['value'] ?? '';
44304431
[$rangeWS1, $startRowColRef] = Worksheet::extractSheetTitle($startRowColRef, true);
44314432
$rangeSheetRef = $rangeWS1;
@@ -4452,7 +4453,7 @@ private function internalParseFormula($formula, ?Cell $cell = null)
44524453
$valx = $val;
44534454
$endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataColumn($valx) : AddressRange::MAX_COLUMN; // Max 16,384 columns for Excel2007
44544455
$val = "{$rangeWS2}{$endRowColRef}{$val}";
4455-
} elseif (ctype_alpha($val) && strlen($val) <= 3) {
4456+
} elseif (ctype_alpha($val) && strlen($val ?? '') <= 3) {
44564457
// Column range
44574458
$stackItemType = 'Column Reference';
44584459
$endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataRow($val) : AddressRange::MAX_ROW; // Max 1,048,576 rows for Excel2007
@@ -4789,6 +4790,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
47894790
} else {
47904791
$sheet1 = ($pCellWorksheet !== null) ? $pCellWorksheet->getTitle() : '';
47914792
}
4793+
$sheet1 ??= '';
47924794

47934795
[$sheet2, $operand2Data['reference']] = Worksheet::extractSheetTitle($operand2Data['reference'], true);
47944796
if (empty($sheet2)) {
@@ -4819,7 +4821,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
48194821
}
48204822
}
48214823

4822-
$oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference']));
4824+
$oData = array_merge(explode(':', $operand1Data['reference'] ?? ''), explode(':', $operand2Data['reference'] ?? ''));
48234825
$oCol = $oRow = [];
48244826
$breakNeeded = false;
48254827
foreach ($oData as $oDatum) {
@@ -5291,10 +5293,8 @@ private function executeArrayComparison($operand1, $operand2, string $operation,
52915293
/**
52925294
* @param mixed $operand1
52935295
* @param mixed $operand2
5294-
*
5295-
* @return mixed
52965296
*/
5297-
private function executeBinaryComparisonOperation($operand1, $operand2, string $operation, Stack &$stack, bool $recursingArrays = false)
5297+
private function executeBinaryComparisonOperation($operand1, $operand2, string $operation, Stack &$stack, bool $recursingArrays = false): array|bool
52985298
{
52995299
// If we're dealing with matrix operations, we want a matrix result
53005300
if ((is_array($operand1)) || (is_array($operand2))) {
@@ -5522,9 +5522,9 @@ public function extractCellRange(&$range = 'A1', ?Worksheet $worksheet = null, b
55225522
* @param null|Worksheet $worksheet Worksheet
55235523
* @param bool $resetLog Flag indicating whether calculation log should be reset or not
55245524
*
5525-
* @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
5525+
* @return array|string Array of values in range if range contains more than one element. Otherwise, a single value is returned.
55265526
*/
5527-
public function extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet = null, bool $resetLog = true)
5527+
public function extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet = null, bool $resetLog = true): string|array
55285528
{
55295529
// Return value
55305530
$returnValue = [];

src/PhpSpreadsheet/Calculation/Database.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,10 @@ public static function DAVERAGE($database, $field, $criteria)
7171
* the column label in which you specify a condition for the
7272
* column.
7373
*
74-
* @return int|string
75-
*
7674
* @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the
7775
* database that match the criteria.
7876
*/
79-
public static function DCOUNT($database, $field, $criteria)
77+
public static function DCOUNT($database, $field, $criteria): string|int
8078
{
8179
return Database\DCount::evaluate($database, $field, $criteria);
8280
}
@@ -107,10 +105,8 @@ public static function DCOUNT($database, $field, $criteria)
107105
* includes at least one column label and at least one cell below
108106
* the column label in which you specify a condition for the
109107
* column.
110-
*
111-
* @return int|string
112108
*/
113-
public static function DCOUNTA($database, $field, $criteria)
109+
public static function DCOUNTA($database, $field, $criteria): string|int
114110
{
115111
return Database\DCountA::evaluate($database, $field, $criteria);
116112
}

src/PhpSpreadsheet/Calculation/Database/DAverage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DAverage extends DatabaseAbstract
3232
*
3333
* @return float|string
3434
*/
35-
public static function evaluate($database, $field, $criteria)
35+
public static function evaluate($database, $field, $criteria): string|int|float
3636
{
3737
$field = self::fieldExtract($database, $field);
3838
if ($field === null) {

src/PhpSpreadsheet/Calculation/Database/DProduct.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ class DProduct extends DatabaseAbstract
2929
* includes at least one column label and at least one cell below
3030
* the column label in which you specify a condition for the
3131
* column.
32-
*
33-
* @return float|string
3432
*/
35-
public static function evaluate($database, $field, $criteria)
33+
public static function evaluate($database, $field, $criteria): string|float
3634
{
3735
$field = self::fieldExtract($database, $field);
3836
if ($field === null) {

src/PhpSpreadsheet/Calculation/Database/DVar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DVar extends DatabaseAbstract
3333
*
3434
* @return float|string (string if result is an error)
3535
*/
36-
public static function evaluate($database, $field, $criteria)
36+
public static function evaluate($database, $field, $criteria): string|float
3737
{
3838
$field = self::fieldExtract($database, $field);
3939
if ($field === null) {

src/PhpSpreadsheet/Calculation/Database/DVarP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DVarP extends DatabaseAbstract
3333
*
3434
* @return float|string (string if result is an error)
3535
*/
36-
public static function evaluate($database, $field, $criteria)
36+
public static function evaluate($database, $field, $criteria): string|float
3737
{
3838
$field = self::fieldExtract($database, $field);
3939
if ($field === null) {

src/PhpSpreadsheet/Calculation/DateTime.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ public static function DATE($year = 0, $month = 1, $day = 1)
183183
* and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148
184184
* or 12:33:20 AM
185185
*
186-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
186+
* @return array|\DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
187187
* depending on the value of the ReturnDateType flag
188188
*/
189-
public static function TIME($hour = 0, $minute = 0, $second = 0)
189+
public static function TIME($hour = 0, $minute = 0, $second = 0): string|float|int|\DateTime|array
190190
{
191191
return DateTimeExcel\Time::fromHMS($hour, $minute, $second);
192192
}
@@ -247,10 +247,10 @@ public static function DATEVALUE($dateValue)
247247
* within quotation marks that represent time.
248248
* Date information in time_text is ignored.
249249
*
250-
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
250+
* @return array|\Datetime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
251251
* depending on the value of the ReturnDateType flag
252252
*/
253-
public static function TIMEVALUE($timeValue)
253+
public static function TIMEVALUE($timeValue): string|\Datetime|int|float|array
254254
{
255255
return DateTimeExcel\TimeValue::fromString($timeValue);
256256
}
@@ -334,7 +334,7 @@ public static function DAYS($endDate = 0, $startDate = 0)
334334
*
335335
* @return array|int|string Number of days between start date and end date
336336
*/
337-
public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
337+
public static function DAYS360($startDate = 0, $endDate = 0, $method = false): string|int|array
338338
{
339339
return DateTimeExcel\Days360::between($startDate, $endDate, $method);
340340
}
@@ -370,7 +370,7 @@ public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
370370
*
371371
* @return array|float|string fraction of the year, or a string containing an error
372372
*/
373-
public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
373+
public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0): string|int|float|array
374374
{
375375
return DateTimeExcel\YearFrac::fraction($startDate, $endDate, $method);
376376
}
@@ -398,7 +398,7 @@ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
398398
*
399399
* @return array|int|string Interval between the dates
400400
*/
401-
public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs)
401+
public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs): string|int|array
402402
{
403403
return DateTimeExcel\NetworkDays::count($startDate, $endDate, ...$dateArgs);
404404
}
@@ -451,7 +451,7 @@ public static function WORKDAY($startDate, $endDays, ...$dateArgs)
451451
*
452452
* @return array|int|string Day of the month
453453
*/
454-
public static function DAYOFMONTH($dateValue = 1)
454+
public static function DAYOFMONTH($dateValue = 1): int|string|array
455455
{
456456
return DateTimeExcel\DateParts::day($dateValue);
457457
}
@@ -478,7 +478,7 @@ public static function DAYOFMONTH($dateValue = 1)
478478
*
479479
* @return array|int|string Day of the week value
480480
*/
481-
public static function WEEKDAY($dateValue = 1, $style = 1)
481+
public static function WEEKDAY($dateValue = 1, $style = 1): string|int|array
482482
{
483483
return DateTimeExcel\Week::day($dateValue, $style);
484484
}
@@ -689,7 +689,7 @@ public static function WEEKDAY($dateValue = 1, $style = 1)
689689
*
690690
* @return array|int|string Week Number
691691
*/
692-
public static function WEEKNUM($dateValue = 1, $method = /** @scrutinizer ignore-deprecated */ self::STARTWEEK_SUNDAY)
692+
public static function WEEKNUM($dateValue = 1, $method = /** @scrutinizer ignore-deprecated */ self::STARTWEEK_SUNDAY): int|string|array
693693
{
694694
return DateTimeExcel\Week::number($dateValue, $method);
695695
}
@@ -711,7 +711,7 @@ public static function WEEKNUM($dateValue = 1, $method = /** @scrutinizer ignore
711711
*
712712
* @return array|int|string Week Number
713713
*/
714-
public static function ISOWEEKNUM($dateValue = 1)
714+
public static function ISOWEEKNUM($dateValue = 1): int|string|array
715715
{
716716
return DateTimeExcel\Week::isoWeekNumber($dateValue);
717717
}
@@ -734,7 +734,7 @@ public static function ISOWEEKNUM($dateValue = 1)
734734
*
735735
* @return array|int|string Month of the year
736736
*/
737-
public static function MONTHOFYEAR($dateValue = 1)
737+
public static function MONTHOFYEAR($dateValue = 1): string|int|array
738738
{
739739
return DateTimeExcel\DateParts::month($dateValue);
740740
}
@@ -757,7 +757,7 @@ public static function MONTHOFYEAR($dateValue = 1)
757757
*
758758
* @return array|int|string Year
759759
*/
760-
public static function YEAR($dateValue = 1)
760+
public static function YEAR($dateValue = 1): string|int|array
761761
{
762762
return DateTimeExcel\DateParts::year($dateValue);
763763
}
@@ -780,7 +780,7 @@ public static function YEAR($dateValue = 1)
780780
*
781781
* @return array|int|string Hour
782782
*/
783-
public static function HOUROFDAY($timeValue = 0)
783+
public static function HOUROFDAY($timeValue = 0): string|int|array
784784
{
785785
return DateTimeExcel\TimeParts::hour($timeValue);
786786
}
@@ -803,7 +803,7 @@ public static function HOUROFDAY($timeValue = 0)
803803
*
804804
* @return array|int|string Minute
805805
*/
806-
public static function MINUTE($timeValue = 0)
806+
public static function MINUTE($timeValue = 0): string|int|array
807807
{
808808
return DateTimeExcel\TimeParts::minute($timeValue);
809809
}
@@ -826,7 +826,7 @@ public static function MINUTE($timeValue = 0)
826826
*
827827
* @return array|int|string Second
828828
*/
829-
public static function SECOND($timeValue = 0)
829+
public static function SECOND($timeValue = 0): string|int|array
830830
{
831831
return DateTimeExcel\TimeParts::second($timeValue);
832832
}

src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DateParts
2828
* If an array of numbers is passed as the argument, then the returned result will also be an array
2929
* with the same dimensions
3030
*/
31-
public static function day($dateValue)
31+
public static function day($dateValue): array|int|string
3232
{
3333
if (is_array($dateValue)) {
3434
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue);
@@ -69,7 +69,7 @@ public static function day($dateValue)
6969
* If an array of numbers is passed as the argument, then the returned result will also be an array
7070
* with the same dimensions
7171
*/
72-
public static function month($dateValue)
72+
public static function month($dateValue): array|string|int
7373
{
7474
if (is_array($dateValue)) {
7575
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue);
@@ -108,7 +108,7 @@ public static function month($dateValue)
108108
* If an array of numbers is passed as the argument, then the returned result will also be an array
109109
* with the same dimensions
110110
*/
111-
public static function year($dateValue)
111+
public static function year($dateValue): array|string|int
112112
{
113113
if (is_array($dateValue)) {
114114
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue);

src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ public static function adjustYear(string $testVal1, string $testVal2, string &$t
133133

134134
/**
135135
* Return result in one of three formats.
136-
*
137-
* @return mixed
138136
*/
139-
public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = false)
137+
public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = false): DateTime|float|int
140138
{
141139
$retType = Functions::getReturnDateType();
142140
if ($retType === Functions::RETURNDATE_PHP_DATETIME_OBJECT) {
@@ -159,11 +157,11 @@ public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = fa
159157
$dateArray['second']
160158
);
161159
if ($retType === Functions::RETURNDATE_EXCEL) {
162-
return $noFrac ? floor($excelDateValue) : (float) $excelDateValue;
160+
return $noFrac ? floor($excelDateValue) : $excelDateValue;
163161
}
164162
// RETURNDATE_UNIX_TIMESTAMP)
165163

166-
return (int) SharedDateHelper::excelToTimestamp($excelDateValue);
164+
return SharedDateHelper::excelToTimestamp($excelDateValue);
167165
}
168166

169167
/**
@@ -187,10 +185,8 @@ public static function returnIn3FormatsFloat(float $excelDateValue)
187185

188186
/**
189187
* Return result in one of three formats.
190-
*
191-
* @return mixed
192188
*/
193-
public static function returnIn3FormatsObject(DateTime $PHPDateObject)
189+
public static function returnIn3FormatsObject(DateTime $PHPDateObject): DateTime|float|int
194190
{
195191
$retType = Functions::getReturnDateType();
196192
if ($retType === Functions::RETURNDATE_PHP_DATETIME_OBJECT) {
@@ -203,7 +199,7 @@ public static function returnIn3FormatsObject(DateTime $PHPDateObject)
203199
$stamp = SharedDateHelper::PHPToExcel($PHPDateObject);
204200
$stamp = is_bool($stamp) ? ((int) $stamp) : $stamp;
205201

206-
return (int) SharedDateHelper::excelToTimestamp($stamp);
202+
return SharedDateHelper::excelToTimestamp($stamp);
207203
}
208204

209205
private static function baseDate(): int
@@ -238,10 +234,8 @@ public static function nullFalseTrueToNumber(&$number, bool $allowBool = true):
238234
* Many functions accept null argument treated as 0.
239235
*
240236
* @param mixed $number
241-
*
242-
* @return float|int
243237
*/
244-
public static function validateNumericNull($number)
238+
public static function validateNumericNull($number): int|float
245239
{
246240
$number = Functions::flattenSingleValue($number);
247241
if ($number === null) {

src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class Time
3838
* If an array of numbers is passed as the argument, then the returned result will also be an array
3939
* with the same dimensions
4040
*
41-
* @return array|mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
41+
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
4242
* depending on the value of the ReturnDateType flag
4343
* If an array of numbers is passed as the argument, then the returned result will also be an array
4444
* with the same dimensions
4545
*/
46-
public static function fromHMS($hour, $minute, $second)
46+
public static function fromHMS($hour, $minute, $second): array|string|float|int|DateTime
4747
{
4848
if (is_array($hour) || is_array($minute) || is_array($second)) {
4949
return self::evaluateArrayArguments([self::class, __FUNCTION__], $hour, $minute, $second);

0 commit comments

Comments
 (0)