Skip to content

Strengthen typing #3718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
922314c
Rector ReturnTypeFromStrictNativeCallRector and ReturnTypeFromStrictS…
PowerKiKi Sep 7, 2023
14d402e
Rector AddMethodCallBasedStrictParamTypeRector
PowerKiKi Sep 7, 2023
1b05dfa
Rector AddParamTypeBasedOnPHPUnitDataProviderRector
PowerKiKi Sep 7, 2023
58cfc10
Stricter type for returning false
PowerKiKi Sep 7, 2023
18a2e65
GD can never be `resource` anymore since PHP 8.0
PowerKiKi Sep 7, 2023
ec4098c
Strict mode for all tests
PowerKiKi Sep 7, 2023
c51e1a0
Happy Stan
PowerKiKi Sep 7, 2023
e2e922d
Rector AddParamTypeFromPropertyTypeRector
PowerKiKi Sep 7, 2023
61740d0
Rector AddReturnTypeDeclarationBasedOnParentClassMethodRector
PowerKiKi Sep 7, 2023
8026199
Rector BoolReturnTypeFromStrictScalarReturnsRector
PowerKiKi Sep 7, 2023
4b0da60
Rector ParamTypeByMethodCallTypeRector
PowerKiKi Sep 7, 2023
ef5762e
Rector PropertyTypeFromStrictSetterGetterRector
PowerKiKi Sep 7, 2023
358898f
Rector ReturnTypeFromReturnDirectArrayRector
PowerKiKi Sep 7, 2023
e041c26
Rector ReturnTypeFromReturnNewRector
PowerKiKi Sep 8, 2023
155fc7d
Rector ReturnTypeFromStrictFluentReturnRector
PowerKiKi Sep 8, 2023
b7d5160
Strangely Stan complains about this
PowerKiKi Sep 8, 2023
de85aa2
Rector ReturnTypeFromStrictNativeCallRector
PowerKiKi Sep 8, 2023
619a6b4
Rector ReturnTypeFromStrictNewArrayRector
PowerKiKi Sep 8, 2023
129871c
PHP is complaining about non-existing `BaseReader::listWorksheetInfo()``
PowerKiKi Sep 8, 2023
f13a8da
Rector ReturnTypeFromStrictParamRector
PowerKiKi Sep 8, 2023
7cffb84
Rector ReturnTypeFromStrictTypedCallRector
PowerKiKi Sep 8, 2023
e221aa6
Rector ReturnUnionTypeRector
PowerKiKi Sep 11, 2023
915bb7e
Rector StrictArrayParamDimFetchRector
PowerKiKi Sep 11, 2023
29cddd9
Rector StrictStringParamConcatRector
PowerKiKi Sep 11, 2023
53cd757
Rector TypedPropertyFromStrictConstructorRector
PowerKiKi Sep 11, 2023
b35dd8d
Rector TypedPropertyFromStrictConstructorRector
PowerKiKi Sep 12, 2023
0e6f413
Rector TypedPropertyFromStrictGetterMethodReturnTypeRector
PowerKiKi Sep 12, 2023
80b4ae2
Rector TypedPropertyFromStrictSetUpRector
PowerKiKi Sep 12, 2023
8ff38e5
Clean up FQCN
PowerKiKi Sep 12, 2023
6160dc9
phpcs
PowerKiKi Sep 12, 2023
627f76a
Merge branch 'master' into powerkiki
PowerKiKi Sep 12, 2023
1b27d9c
Stronger typing for newly introduced methods
PowerKiKi Sep 12, 2023
bf46298
Update changelog
PowerKiKi Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).

## Unreleased - TBD

### MINOR BREAKING CHANGE

- Typing was strengthened by leveraging native typing. While this should not change any behavior, it might need minor
adaption of your code if you use static analysis tools such as PHPStan or
Psalm. [PR #3718](https://github.com/PHPOffice/PhpSpreadsheet/pull/3718)

### Added

- Split screens (Xlsx and Xml only, not 100% complete). [Issue #3601](https://github.com/PHPOffice/PhpSpreadsheet/issues/3601) [PR #3622](https://github.com/PHPOffice/PhpSpreadsheet/pull/3622)
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ parameters:
processTimeout: 300.0
checkMissingIterableValueType: false
ignoreErrors:
- '~^Parameter \#1 \$im(age)? of function (imagedestroy|imageistruecolor|imagealphablending|imagesavealpha|imagecolortransparent|imagecolorsforindex|imagesavealpha|imagesx|imagesy|imagepng|imagecolorat) expects (GdImage|resource), GdImage\|resource given\.$~'
- '~^Parameter \#2 \$src_im(age)? of function imagecopy expects (GdImage|resource), GdImage\|resource given\.$~'
# Accept a bit anything for assert methods
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'
- '~^Method PhpOffice\\PhpSpreadsheetTests\\.*\:\:test.*\(\) has parameter \$args with no type specified\.$~'
121 changes: 37 additions & 84 deletions src/PhpSpreadsheet/Calculation/Calculation.php

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions src/PhpSpreadsheet/Calculation/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Database
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -71,12 +71,10 @@ public static function DAVERAGE($database, $field, $criteria)
* the column label in which you specify a condition for the
* column.
*
* @return int|string
*
* @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the
* database that match the criteria.
*/
public static function DCOUNT($database, $field, $criteria)
public static function DCOUNT($database, $field, $criteria): string|int
{
return Database\DCount::evaluate($database, $field, $criteria);
}
Expand All @@ -97,7 +95,7 @@ public static function DCOUNT($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand All @@ -107,10 +105,8 @@ public static function DCOUNT($database, $field, $criteria)
* includes at least one column label and at least one cell below
* the column label in which you specify a condition for the
* column.
*
* @return int|string
*/
public static function DCOUNTA($database, $field, $criteria)
public static function DCOUNTA($database, $field, $criteria): string|int
{
return Database\DCountA::evaluate($database, $field, $criteria);
}
Expand All @@ -132,7 +128,7 @@ public static function DCOUNTA($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -167,7 +163,7 @@ public static function DGET($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -202,7 +198,7 @@ public static function DMAX($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -236,7 +232,7 @@ public static function DMIN($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -271,7 +267,7 @@ public static function DPRODUCT($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -306,7 +302,7 @@ public static function DSTDEV($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -340,7 +336,7 @@ public static function DSTDEVP($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -375,7 +371,7 @@ public static function DSUM($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down Expand Up @@ -410,7 +406,7 @@ public static function DVAR($database, $field, $criteria)
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Database/DAverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DAverage extends DatabaseAbstract
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand All @@ -32,7 +32,7 @@ class DAverage extends DatabaseAbstract
*
* @return float|string
*/
public static function evaluate($database, $field, $criteria)
public static function evaluate($database, $field, $criteria): string|int|float
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Calculation/Database/DCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class DCount extends DatabaseAbstract
* includes at least one column label and at least one cell below
* the column label in which you specify a condition for the
* column.
*
* @return int|string
*/
public static function evaluate($database, $field, $criteria, bool $returnError = true)
public static function evaluate($database, $field, $criteria, bool $returnError = true): string|int
{
$field = self::fieldExtract($database, $field);
if ($returnError && $field === null) {
Expand Down
6 changes: 2 additions & 4 deletions src/PhpSpreadsheet/Calculation/Database/DCountA.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DCountA extends DatabaseAbstract
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand All @@ -29,10 +29,8 @@ class DCountA extends DatabaseAbstract
* includes at least one column label and at least one cell below
* the column label in which you specify a condition for the
* column.
*
* @return int|string
*/
public static function evaluate($database, $field, $criteria)
public static function evaluate($database, $field, $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 @@ -19,7 +19,7 @@ class DGet extends DatabaseAbstract
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
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 @@ -20,7 +20,7 @@ class DMax extends DatabaseAbstract
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
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 @@ -20,7 +20,7 @@ class DMin extends DatabaseAbstract
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand Down
6 changes: 2 additions & 4 deletions src/PhpSpreadsheet/Calculation/Database/DProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DProduct extends DatabaseAbstract
* A database is a list of related data in which rows of related
* information are records, and columns of data are fields. The
* first row of the list contains labels for each column.
* @param int|string $field Indicates which column is used in the function. Enter the
* @param null|int|string $field Indicates which column is used in the function. Enter the
* column label enclosed between double quotation marks, such as
* "Age" or "Yield," or a number (without quotation marks) that
* represents the position of the column within the list: 1 for
Expand All @@ -29,10 +29,8 @@ class DProduct extends DatabaseAbstract
* includes at least one column label and at least one cell below
* the column label in which you specify a condition for the
* column.
*
* @return float|string
*/
public static function evaluate($database, $field, $criteria)
public static function evaluate($database, $field, $criteria): string|float
{
$field = self::fieldExtract($database, $field);
if ($field === null) {
Expand Down
Loading