Skip to content

Commit 3eedf9e

Browse files
committed
Better Typing in Test Members
Change "mixed" declarations to more accurate types in test members; in particular, change those that would be flagged if we were to run Phpstan at level 9 (we currently run level 8). I may or may not follow up with source code (over 700 level-9 problems remain for src), but, as with strict typing, there is no reason to avoid the effort for test members. It was necessary to update some doc blocks in src to accommodate this change. However, no executable code is touched.
1 parent 43481c9 commit 3eedf9e

File tree

130 files changed

+372
-253
lines changed

Some content is hidden

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

130 files changed

+372
-253
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$finder = PhpCsFixer\Finder::create()
44
->exclude('vendor')
55
->notPath('src/PhpSpreadsheet/Writer/ZipStream3.php')
6-
->name('/(\.php|^generate-document|^generate-locales)$/')
6+
->name('/(\.php|^generate-document|^generate-locales|^check-phpdoc-types)$/')
77
->in(__DIR__);
88

99
$config = new PhpCsFixer\Config();

.phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<file>infra</file>
99
<file>bin/generate-document</file>
1010
<file>bin/generate-locales</file>
11+
<file>bin/check-phpdoc-types</file>
1112

1213
<exclude-pattern>samples/Header.php</exclude-pattern>
1314
<exclude-pattern>*/tests/Core/*/*Test\.(inc|css|js)$</exclude-pattern>

bin/check-phpdoc-types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*/
1111
function checkPhpDocTypes(): void
1212
{
13-
$content = `git diff --cached` ?? `git diff` ?? `git show HEAD`;
14-
preg_match_all('~^\+ +\* @(param|var) (mixed|string|int|float|bool|null|array|\?|\|)+( \$\w+)?$~m', $content, $parameters);
15-
preg_match_all('~^\+ +\* @return (mixed|string|int|float|bool|null|array|void|\?|\|)+$~m', $content, $returns);
13+
$content = shell_exec('git diff --cached') ?? shell_exec('git diff') ?? shell_exec('git show HEAD');
14+
preg_match_all('~^\+ +\* @(param|var) (mixed|string|int|float|bool|null|array|\?|\|)+( \$\w+)?$~m', "$content", $parameters);
15+
preg_match_all('~^\+ +\* @return (mixed|string|int|float|bool|null|array|void|\?|\|)+$~m', "$content", $returns);
1616

1717
$errors = [
1818
...$parameters[0],
@@ -21,7 +21,7 @@ function checkPhpDocTypes(): void
2121

2222
if ($errors) {
2323
echo 'PHP native types must be used instead of PHPDoc types (without comments), for the following lines:' . PHP_EOL . PHP_EOL;
24-
echo join(PHP_EOL, $errors) . PHP_EOL;
24+
echo implode(PHP_EOL, $errors) . PHP_EOL;
2525
exit(1);
2626
}
2727
}

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ parameters:
1212
- infra/
1313
- bin/generate-document
1414
- bin/generate-locales
15+
- bin/check-phpdoc-types
1516
excludePaths:
1617
- src/PhpSpreadsheet/Chart/Renderer/JpGraph.php
1718
- src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php

src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Date
2727
* A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
2828
* as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
2929
*
30-
* @param array|int|string $year The value of the year argument can include one to four digits.
30+
* @param array|float|int|string $year The value of the year argument can include one to four digits.
3131
* Excel interprets the year argument according to the configured
3232
* date system: 1900 or 1904.
3333
* If year is between 0 (zero) and 1899 (inclusive), Excel adds that
@@ -63,7 +63,7 @@ class Date
6363
* If an array of numbers is passed as the argument, then the returned result will also be an array
6464
* with the same dimensions
6565
*/
66-
public static function fromYMD(array|int|string $year, array|float|int|string $month, array|float|int|string $day): mixed
66+
public static function fromYMD(array|float|int|string $year, array|float|int|string $month, array|float|int|string $day): mixed
6767
{
6868
if (is_array($year) || is_array($month) || is_array($day)) {
6969
return self::evaluateArrayArguments([self::class, __FUNCTION__], $year, $month, $day);

src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DateValue
2424
* Excel Function:
2525
* DATEVALUE(dateValue)
2626
*
27-
* @param null|array|int|string $dateValue Text that represents a date in a Microsoft Excel date format.
27+
* @param null|array|bool|float|int|string $dateValue Text that represents a date in a Microsoft Excel date format.
2828
* For example, "1/30/2008" or "30-Jan-2008" are text strings within
2929
* quotation marks that represent dates. Using the default date
3030
* system in Excel for Windows, date_text must represent a date from
@@ -39,7 +39,7 @@ class DateValue
3939
* If an array of numbers is passed as the argument, then the returned result will also be an array
4040
* with the same dimensions
4141
*/
42-
public static function fromString(null|array|string|int|bool $dateValue): mixed
42+
public static function fromString(null|array|string|int|bool|float $dateValue): mixed
4343
{
4444
if (is_array($dateValue)) {
4545
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue);

src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TimeValue
2525
* Excel Function:
2626
* TIMEVALUE(timeValue)
2727
*
28-
* @param null|array|string $timeValue A text string that represents a time in any one of the Microsoft
28+
* @param null|array|bool|int|string $timeValue A text string that represents a time in any one of the Microsoft
2929
* Excel time formats; for example, "6:45 PM" and "18:45" text strings
3030
* within quotation marks that represent time.
3131
* Date information in time_text is ignored.

src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static function isoWeekNumber(mixed $dateValue): array|int|string
137137
* Excel Function:
138138
* WEEKDAY(dateValue[,style])
139139
*
140-
* @param null|array|float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer),
140+
* @param null|array|bool|float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer),
141141
* PHP DateTime object, or a standard date string
142142
* Or can be an array of date values
143143
* @param mixed $style A number that determines the type of return value

src/PhpSpreadsheet/Calculation/Engineering/Compare.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class Compare
2020
* functions you calculate the count of equal pairs. This function is also known as the
2121
* Kronecker Delta function.
2222
*
23-
* @param array|float $a the first number
23+
* @param array|bool|float|int|string $a the first number
2424
* Or can be an array of values
25-
* @param array|float $b The second number. If omitted, b is assumed to be zero.
25+
* @param array|bool|float|int|string $b The second number. If omitted, b is assumed to be zero.
2626
* Or can be an array of values
2727
*
2828
* @return array|int|string (string in the event of an error)
2929
* If an array of numbers is passed as an argument, then the returned result will also be an array
3030
* with the same dimensions
3131
*/
32-
public static function DELTA(array|float|bool|string $a, array|float|bool|string $b = 0.0): array|string|int
32+
public static function DELTA(array|float|bool|string|int $a, array|float|bool|string|int $b = 0.0): array|string|int
3333
{
3434
if (is_array($a) || is_array($b)) {
3535
return self::evaluateArrayArguments([self::class, __FUNCTION__], $a, $b);
@@ -55,16 +55,16 @@ public static function DELTA(array|float|bool|string $a, array|float|bool|string
5555
* Use this function to filter a set of values. For example, by summing several GESTEP
5656
* functions you calculate the count of values that exceed a threshold.
5757
*
58-
* @param array|float $number the value to test against step
58+
* @param array|bool|float|int|string $number the value to test against step
5959
* Or can be an array of values
60-
* @param null|array|float $step The threshold value. If you omit a value for step, GESTEP uses zero.
60+
* @param null|array|bool|float|int|string $step The threshold value. If you omit a value for step, GESTEP uses zero.
6161
* Or can be an array of values
6262
*
6363
* @return array|int|string (string in the event of an error)
6464
* If an array of numbers is passed as an argument, then the returned result will also be an array
6565
* with the same dimensions
6666
*/
67-
public static function GESTEP(array|float|bool|string $number, $step = 0.0): array|string|int
67+
public static function GESTEP(array|float|bool|string|int $number, $step = 0.0): array|string|int
6868
{
6969
if (is_array($number) || is_array($step)) {
7070
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $step);

src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ConvertBinary extends ConvertBase
1515
* Excel Function:
1616
* BIN2DEC(x)
1717
*
18-
* @param array|string $value The binary number (as a string) that you want to convert. The number
18+
* @param array|bool|float|int|string $value The binary number (as a string) that you want to convert. The number
1919
* cannot contain more than 10 characters (10 bits). The most significant
2020
* bit of number is the sign bit. The remaining 9 bits are magnitude bits.
2121
* Negative numbers are represented using two's-complement notation.
@@ -58,14 +58,14 @@ public static function toDecimal($value)
5858
* Excel Function:
5959
* BIN2HEX(x[,places])
6060
*
61-
* @param array|string $value The binary number (as a string) that you want to convert. The number
61+
* @param array|bool|float|int|string $value The binary number (as a string) that you want to convert. The number
6262
* cannot contain more than 10 characters (10 bits). The most significant
6363
* bit of number is the sign bit. The remaining 9 bits are magnitude bits.
6464
* Negative numbers are represented using two's-complement notation.
6565
* If number is not a valid binary number, or if number contains more than
6666
* 10 characters (10 bits), BIN2HEX returns the #NUM! error value.
6767
* Or can be an array of values
68-
* @param array|int $places The number of characters to use. If places is omitted, BIN2HEX uses the
68+
* @param null|array|float|int|string $places The number of characters to use. If places is omitted, BIN2HEX uses the
6969
* minimum number of characters necessary. Places is useful for padding the
7070
* return value with leading 0s (zeros).
7171
* If places is not an integer, it is truncated.
@@ -111,14 +111,14 @@ public static function toHex($value, $places = null): array|string
111111
* Excel Function:
112112
* BIN2OCT(x[,places])
113113
*
114-
* @param array|string $value The binary number (as a string) that you want to convert. The number
114+
* @param array|bool|float|int|string $value The binary number (as a string) that you want to convert. The number
115115
* cannot contain more than 10 characters (10 bits). The most significant
116116
* bit of number is the sign bit. The remaining 9 bits are magnitude bits.
117117
* Negative numbers are represented using two's-complement notation.
118118
* If number is not a valid binary number, or if number contains more than
119119
* 10 characters (10 bits), BIN2OCT returns the #NUM! error value.
120120
* Or can be an array of values
121-
* @param array|int $places The number of characters to use. If places is omitted, BIN2OCT uses the
121+
* @param null|array|float|int|string $places The number of characters to use. If places is omitted, BIN2OCT uses the
122122
* minimum number of characters necessary. Places is useful for padding the
123123
* return value with leading 0s (zeros).
124124
* If places is not an integer, it is truncated.

0 commit comments

Comments
 (0)