Skip to content

Commit 0e570a5

Browse files
authored
Merge pull request #4467 from oleibman/stan1006
More prep for Phpstan 10
2 parents e6aacf7 + 7db6e1f commit 0e570a5

File tree

90 files changed

+611
-226
lines changed

Some content is hidden

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

90 files changed

+611
-226
lines changed

phpstan-baseline.neon

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\MathTrig\\Sum\:\:sumErroringStrings\(\) should return array\|float\|int\|string but returns mixed\.$#'
5+
identifier: return.type
6+
count: 1
7+
path: src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
8+
9+
-
10+
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\MathTrig\\Sum\:\:sumIgnoringStrings\(\) should return float\|int\|string but returns mixed\.$#'
11+
identifier: return.type
12+
count: 1
13+
path: src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
14+
15+
-
16+
message: '#^Binary operation "\*" between mixed and mixed results in an error\.$#'
17+
identifier: binaryOp.invalid
18+
count: 4
19+
path: src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php
20+
21+
-
22+
message: '#^Binary operation "\-" between mixed and mixed results in an error\.$#'
23+
identifier: binaryOp.invalid
24+
count: 2
25+
path: src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php
26+
27+
-
28+
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Maximum\:\:max\(\) should return float\|int\|string but returns mixed\.$#'
29+
identifier: return.type
30+
count: 1
31+
path: src/PhpSpreadsheet/Calculation/Statistical/Maximum.php
32+
33+
-
34+
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Maximum\:\:maxA\(\) should return float\|int\|string but returns mixed\.$#'
35+
identifier: return.type
36+
count: 1
37+
path: src/PhpSpreadsheet/Calculation/Statistical/Maximum.php
38+
39+
-
40+
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Minimum\:\:min\(\) should return float\|int\|string but returns mixed\.$#'
41+
identifier: return.type
42+
count: 1
43+
path: src/PhpSpreadsheet/Calculation/Statistical/Minimum.php
44+
45+
-
46+
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Minimum\:\:minA\(\) should return float\|int\|string but returns mixed\.$#'
47+
identifier: return.type
48+
count: 1
49+
path: src/PhpSpreadsheet/Calculation/Statistical/Minimum.php
50+
51+
-
52+
message: '#^Parameter \#1 \$str of function preg_quote expects string, mixed given\.$#'
53+
identifier: argument.type
54+
count: 1
55+
path: src/PhpSpreadsheet/Calculation/TextData/Extract.php
56+
57+
-
58+
message: '#^Parameter \#1 \$str of function preg_quote expects string, mixed given\.$#'
59+
identifier: argument.type
60+
count: 1
61+
path: src/PhpSpreadsheet/Calculation/TextData/Text.php

src/PhpSpreadsheet/Calculation/Database/DGet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static function evaluate(array $database, array|null|int|string $field, a
4242
return ExcelError::NAN();
4343
}
4444

45+
/** @var array<null|float|int|string> */
4546
$row = array_pop($columnData);
4647

4748
return array_pop($row);

src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ protected static function fieldExtract(array $database, mixed $field): ?int
5353

5454
/** @var callable */
5555
$callable = 'strtoupper';
56-
/** @var non-empty-array $database */
57-
$fieldNames = array_map($callable, array_shift($database));
56+
$fieldNames = array_map($callable, array_shift($database)); //* @phpstan-ignore-line
5857
if (is_numeric($field)) {
5958
$field = (int) $field - 1;
6059
if ($field < 0 || $field >= count($fieldNames)) {
@@ -88,21 +87,24 @@ protected static function fieldExtract(array $database, mixed $field): ?int
8887
*/
8988
protected static function filter(array $database, array $criteria): array
9089
{
91-
/** @var array */
90+
/** @var mixed[] */
9291
$fieldNames = array_shift($database);
93-
/** @var array */
9492
$criteriaNames = array_shift($criteria);
9593

9694
// Convert the criteria into a set of AND/OR conditions with [:placeholders]
95+
/** @var string[] $criteriaNames */
9796
$query = self::buildQuery($criteriaNames, $criteria);
9897

9998
// Loop through each row of the database
99+
/** @var mixed[][] $criteriaNames */
100100
return self::executeQuery($database, $query, $criteriaNames, $fieldNames);
101101
}
102102

103103
/**
104104
* @param mixed[] $database The range of cells that makes up the list or database
105105
* @param mixed[][] $criteria
106+
*
107+
* @return mixed[]
106108
*/
107109
protected static function getFilteredColumn(array $database, ?int $field, array $criteria): array
108110
{
@@ -112,7 +114,7 @@ protected static function getFilteredColumn(array $database, ?int $field, array
112114

113115
// extract an array of values for the requested column
114116
$columnData = [];
115-
/** @var array $row */
117+
/** @var mixed[] $row */
116118
foreach ($database as $rowKey => $row) {
117119
$keys = array_keys($row);
118120
$key = $keys[$field] ?? null;

src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Date
2828
* A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
2929
* as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
3030
*
31-
* @param array|float|int|string $year The value of the year argument can include one to four digits.
31+
* @param array<mixed>|float|int|string $year The value of the year argument can include one to four digits.
3232
* Excel interprets the year argument according to the configured
3333
* date system: 1900 or 1904.
3434
* If year is between 0 (zero) and 1899 (inclusive), Excel adds that
@@ -39,7 +39,7 @@ class Date
3939
* 2008.
4040
* If year is less than 0 or is 10000 or greater, Excel returns the
4141
* #NUM! error value.
42-
* @param array|float|int|string $month A positive or negative integer representing the month of the year
42+
* @param array<mixed>|float|int|string $month A positive or negative integer representing the month of the year
4343
* from 1 to 12 (January to December).
4444
* If month is greater than 12, month adds that number of months to
4545
* the first month in the year specified. For example, DATE(2008,14,2)
@@ -48,7 +48,7 @@ class Date
4848
* number of months, plus 1, from the first month in the year
4949
* specified. For example, DATE(2008,-3,2) returns the serial number
5050
* representing September 2, 2007.
51-
* @param array|float|int|string $day A positive or negative integer representing the day of the month
51+
* @param array<mixed>|float|int|string $day A positive or negative integer representing the day of the month
5252
* from 1 to 31.
5353
* If day is greater than the number of days in the month specified,
5454
* day adds that number of days to the first day in the month. For
@@ -59,7 +59,7 @@ class Date
5959
* example, DATE(2008,1,-15) returns the serial number representing
6060
* December 16, 2007.
6161
*
62-
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
62+
* @return array<mixed>|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
6363
* depending on the value of the ReturnDateType flag
6464
* If an array of numbers is passed as the argument, then the returned result will also be an array
6565
* with the same dimensions

src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DateParts
2424
* PHP DateTime object, or a standard date string
2525
* Or can be an array of date values
2626
*
27-
* @return array|int|string Day of the month
27+
* @return array<mixed>|int|string Day of the month
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
*/
@@ -65,7 +65,7 @@ public static function day(mixed $dateValue): array|int|string
6565
* PHP DateTime object, or a standard date string
6666
* Or can be an array of date values
6767
*
68-
* @return array|int|string Month of the year
68+
* @return array<mixed>|int|string Month of the year
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
*/
@@ -104,7 +104,7 @@ public static function month(mixed $dateValue): array|string|int
104104
* PHP DateTime object, or a standard date string
105105
* Or can be an array of date values
106106
*
107-
* @return array|int|string Year
107+
* @return array<mixed>|int|string Year
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
*/

src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DateValue
2525
* Excel Function:
2626
* DATEVALUE(dateValue)
2727
*
28-
* @param null|array|bool|float|int|string $dateValue Text that represents a date in a Microsoft Excel date format.
28+
* @param null|array<mixed>|bool|float|int|string $dateValue Text that represents a date in a Microsoft Excel date format.
2929
* For example, "1/30/2008" or "30-Jan-2008" are text strings within
3030
* quotation marks that represent dates. Using the default date
3131
* system in Excel for Windows, date_text must represent a date from
@@ -35,7 +35,7 @@ class DateValue
3535
* #VALUE! error value if date_text is out of this range.
3636
* Or can be an array of date values
3737
*
38-
* @return array|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
38+
* @return array<mixed>|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
3939
* depending on the value of the ReturnDateType flag
4040
* If an array of numbers is passed as the argument, then the returned result will also be an array
4141
* with the same dimensions
@@ -86,6 +86,7 @@ public static function fromString(null|array|string|int|bool|float $dateValue):
8686
return self::finalResults($PHPDateArray, $dti, $baseYear);
8787
}
8888

89+
/** @param mixed[] $t1 */
8990
private static function t1ToString(array $t1, DateTimeImmutable $dti, bool $yearFound): string
9091
{
9192
if (count($t1) == 2) {
@@ -108,6 +109,8 @@ private static function t1ToString(array $t1, DateTimeImmutable $dti, bool $year
108109

109110
/**
110111
* Parse date.
112+
*
113+
* @return mixed[]
111114
*/
112115
private static function setUpArray(string $dateValue, DateTimeImmutable $dti): array
113116
{
@@ -132,20 +135,24 @@ private static function setUpArray(string $dateValue, DateTimeImmutable $dti): a
132135
/**
133136
* Final results.
134137
*
138+
* @param mixed[] $PHPDateArray
139+
*
135140
* @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object,
136141
* depending on the value of the ReturnDateType flag
137142
*/
138143
private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti, int $baseYear): string|float|int|DateTime
139144
{
140145
$retValue = ExcelError::Value();
141146
if (Helpers::dateParseSucceeded($PHPDateArray)) {
147+
/** @var array{year: int, month: int, day: int, hour: int, minute: int, second: int} $PHPDateArray */
142148
// Execute function
143149
Helpers::replaceIfEmpty($PHPDateArray['year'], $dti->format('Y'));
144150
if ($PHPDateArray['year'] < $baseYear) {
145151
return ExcelError::VALUE();
146152
}
147153
Helpers::replaceIfEmpty($PHPDateArray['month'], $dti->format('m'));
148154
Helpers::replaceIfEmpty($PHPDateArray['day'], $dti->format('d'));
155+
/** @var array{year: int, month: int, day: int, hour: int, minute: int, second: int} $PHPDateArray */
149156
$PHPDateArray['hour'] = 0;
150157
$PHPDateArray['minute'] = 0;
151158
$PHPDateArray['second'] = 0;
@@ -161,6 +168,7 @@ private static function finalResults(array $PHPDateArray, DateTimeImmutable $dti
161168
return $retValue;
162169
}
163170

171+
/** @param mixed[] $array */
164172
private static function getInt(array $array, string $index): int
165173
{
166174
return (array_key_exists($index, $array) && is_numeric($array[$index])) ? (int) $array[$index] : 0;

src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class Days
2020
* Excel Function:
2121
* DAYS(endDate, startDate)
2222
*
23-
* @param array|DateTimeInterface|float|int|string $endDate Excel date serial value (float),
23+
* @param array<mixed>|DateTimeInterface|float|int|string $endDate Excel date serial value (float),
2424
* PHP date timestamp (integer), PHP DateTime object, or a standard date string
2525
* Or can be an array of date values
26-
* @param array|DateTimeInterface|float|int|string $startDate Excel date serial value (float),
26+
* @param array<mixed>|DateTimeInterface|float|int|string $startDate Excel date serial value (float),
2727
* PHP date timestamp (integer), PHP DateTime object, or a standard date string
2828
* Or can be an array of date values
2929
*
30-
* @return array|int|string Number of days between start date and end date or an error
30+
* @return array<mixed>|int|string Number of days between start date and end date or an error
3131
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
3232
* will also be an array with matching dimensions
3333
*/

src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Days360
4040
* same month.
4141
* Or can be an array of methods
4242
*
43-
* @return array|int|string Number of days between start date and end date
43+
* @return array<mixed>|int|string Number of days between start date and end date
4444
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
4545
* will also be an array with matching dimensions
4646
*/

src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class Difference
2222
* @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
2323
* or a standard date string
2424
* Or can be an array of date values
25-
* @param array|string $unit Or can be an array of unit values
25+
* @param array<mixed>|string $unit Or can be an array of unit values
2626
*
27-
* @return array|int|string Interval between the dates
27+
* @return array<mixed>|int|string Interval between the dates
2828
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
2929
* will also be an array with matching dimensions
3030
*/

src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public static function adjustYear(string $testVal1, string $testVal2, string &$t
131131

132132
/**
133133
* Return result in one of three formats.
134+
*
135+
* @param array{year: int, month: int, day: int, hour: int, minute: int, second: int} $dateArray
134136
*/
135137
public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = false): DateTime|float|int
136138
{
@@ -268,11 +270,16 @@ public static function silly1900(DateTime $PHPDateObject, string $mod = '-1 day'
268270
}
269271
}
270272

273+
/** @return array{year: int, month: int, day: int, hour: int, minute: int, second: int} */
271274
public static function dateParse(string $string): array
272275
{
273-
return self::forceArray(date_parse($string));
276+
/** @var array{year: int, month: int, day: int, hour: int, minute: int, second: int} */
277+
$temp = self::forceArray(date_parse($string));
278+
279+
return $temp;
274280
}
275281

282+
/** @param mixed[] $dateArray */
276283
public static function dateParseSucceeded(array $dateArray): bool
277284
{
278285
return $dateArray['error_count'] === 0;
@@ -282,7 +289,9 @@ public static function dateParseSucceeded(array $dateArray): bool
282289
* Despite documentation, date_parse probably never returns false.
283290
* Just in case, this routine helps guarantee it.
284291
*
285-
* @param array|false $dateArray
292+
* @param array<mixed>|false $dateArray
293+
*
294+
* @return mixed[]
286295
*/
287296
private static function forceArray(array|bool $dateArray): array
288297
{

0 commit comments

Comments
 (0)