Commit Graph

4243 Commits

Author SHA1 Message Date
Adrien Crivelli 7712d5561b Check PHPDoc types of the PR's last commit 2023-09-13 10:06:58 +08:00
Adrien Crivelli ebda3fdda1 Drop dead code 2023-09-13 10:06:58 +08:00
Adrien Crivelli bb6ae9ce7d Prevent adding PHPDoc types instead of native types
PHPDoc types can sometimes be entirely expressed as PHP native types. It
is better because it avoids code duplication and enables type runtime
check.

This will help us slowly migrate away from PHPDoc typing to PHP native typing.
2023-09-13 10:06:58 +08:00
Adrien Crivelli 2a9f2f57b9 Rector MixedTypeRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli f4c1519869 Rector ChangeSwitchToMatchRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli de658b44e1 Rector RemoveUnusedVariableInCatchRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli f6f1e27f98 Rector ClassOnObjectRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli e65e46db43 Rector StringableForToStringRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli b881309496 Rector StrContainsRector, StrStartsWithRector, StrEndsWithRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli bf462986f2 Update changelog 2023-09-12 13:59:19 +08:00
Adrien Crivelli 1b27d9c95d Stronger typing for newly introduced methods 2023-09-12 11:24:02 +08:00
Adrien Crivelli 627f76a803 Merge branch 'master' into powerkiki 2023-09-12 11:07:32 +08:00
Adrien Crivelli 6160dc98a1 phpcs 2023-09-12 11:05:52 +08:00
Adrien Crivelli 8ff38e5856 Clean up FQCN 2023-09-12 10:59:18 +08:00
Adrien Crivelli 80b4ae2bbd Rector TypedPropertyFromStrictSetUpRector 2023-09-12 10:48:13 +08:00
Adrien Crivelli 0e6f413fde Rector TypedPropertyFromStrictGetterMethodReturnTypeRector 2023-09-12 10:35:30 +08:00
Adrien Crivelli b35dd8d268 Rector TypedPropertyFromStrictConstructorRector 2023-09-12 09:22:10 +08:00
Adrien Crivelli 53cd757506 Rector TypedPropertyFromStrictConstructorRector 2023-09-12 00:31:28 +08:00
Adrien Crivelli 29cddd9aa6 Rector StrictStringParamConcatRector 2023-09-11 21:53:39 +08:00
Adrien Crivelli 915bb7eb76 Rector StrictArrayParamDimFetchRector 2023-09-11 21:37:17 +08:00
Adrien Crivelli e221aa61be Rector ReturnUnionTypeRector 2023-09-11 10:21:01 +08:00
Adrien Crivelli 7cffb844c0 Rector ReturnTypeFromStrictTypedCallRector 2023-09-08 17:07:44 +08:00
Adrien Crivelli f13a8da463 Rector ReturnTypeFromStrictParamRector 2023-09-08 13:19:44 +08:00
Adrien Crivelli 129871c1cf PHP is complaining about non-existing BaseReader::listWorksheetInfo()`
But only on GitHub Actions, not in local...

This makes zero sense at all ¯\_(ツ)_/¯
2023-09-08 12:23:57 +08:00
Adrien Crivelli 619a6b4e6c Rector ReturnTypeFromStrictNewArrayRector 2023-09-08 12:08:47 +08:00
Adrien Crivelli de85aa2935 Rector ReturnTypeFromStrictNativeCallRector 2023-09-08 11:46:39 +08:00
Adrien Crivelli b7d51606c9 Strangely Stan complains about this 2023-09-08 11:26:37 +08:00
Adrien Crivelli 155fc7d7b1 Rector ReturnTypeFromStrictFluentReturnRector 2023-09-08 11:24:21 +08:00
Adrien Crivelli e041c26cb7 Rector ReturnTypeFromReturnNewRector 2023-09-08 10:37:49 +08:00
oleibman 52f5b24b6d Inconsistency Between Actual and Declared Type - Minor Break (#3715)
* Inconsistency Between Actual and Declared Type - Minor Break

Fix #3711. User set a cell value to float (implicitly by default value binder), then used `setDataType` to change its type to string. This caused a problem for Xlsx Writer, which uses the string cell values as an index into a Shared String array. However, as the cell actually contained a floating point value, Php treated it as an integer index; such a treatment is both deprecated, and leads to invalid values in the spreadsheet.

The use case for `setDataType` is not strong. The user always has the option to use `setValueExplicit` if the type is important. Setting a type afterwards, i.e. irrespective of the value, seems like a peculiar action. Indeed, there are no tests whatever for such use in the unit test suite.

There are two possible approaches to fixing this problem. The first is to add casts to the 3 or 4 places in Writer Xlsx which might be affected by this problem (hoping that you've found them all and realizing that similar changes might be needed for other Writers). The second is to change `setDataType` to call `setValueExplicit` using the current value of the cell, thereby possibly changing the cell value. I have gone with the second option - it seems like a much more logical approach, and guarantees that the content of the cell will always be consistent with its declared type. It is, however, a breaking change; if, for example, you have a cell with a string or numeric value and specify `boolean` to `setDataType`, the cell's value will change to `true` or `false` with no way to get back to the original.

* Strict Types for New Tests

Consistent with work being done in PR #3718.

* Improve Test

Better match to original issue.

* Typo
2023-09-07 18:38:08 -07:00
oleibman 0d1c9e4e0e ListWorksheetInfo/Names for Html/Csv/Slk (#3709)
* ListWorksheetInfo/Names for Html/Csv/Slk

Fix #3706. ListWorksheetInfo is implemented for all Readers except Html. For most (not all), ListWorksheetInfo is more efficient than reading the spreadsheet. I can't think of a way to make that so for Html, but that shouldn't be a reason to leave it unimplemented.

ListWorksheetNames is not implemented for Html, Csv, or Slk. It isn't terribly useful for those formats, but that isn't a reason to omit it. The requester's use case consists of using IOFactory to create a reader for a file of unknown format and determining the first sheet name. That seems legitimate, but it is currently not possible without extra user code if the file is Html, Csv, or Slk; this PR will make it possible.

When Excel opens a Slk or Csv file, the sheet name is based on the file name. PhpSpreadsheet does this for Slk, but it uses a default name for Csv. I am not interested in creating a break for that behavior, but I have added a new boolean property `sheetNameIsFileName` with a setter to Csv Reader. The requester actually mentioned that possibility in our discussion, although it is not essential to the request.

As an adjunct to the issue, the requester wishes to use the worksheet name in `setLoadSheetsOnly`. That is already possible for Html, Csv, and Slk, but that particular property is ignored for those formats. I do not see a reason to change that behavior. This treatment is now explicitly noted in the documentation for property `loadSheetsOnly`.

There had been no tests for what happens when `loadSheetsOnly` is specified but no sheets match the criteria for the formats for which this makes sense (Xlsx, Xls, Ods, Gnumeric, Xml). The behavior was not consistent - some formats threw an Exception while others continued with a single empty worksheet. All cases attempt to set the active sheet, and they will now all throw identical Exceptions when they attempt to do so in this situation. Tests are added for each.

There also had been no tests for `loadSheetsOnly` returning more than one sheet. One is added.

* Update LoadSheetsOnlyTest.php

Add strict types to this new test, consistent with work being done in PR #3718.

* Update LoadSheetsOnlyTest.php

Add strict types to this new test, consistent with work being done in PR #3718.
2023-09-07 18:29:45 -07:00
Adrien Crivelli 358898f4b0 Rector ReturnTypeFromReturnDirectArrayRector 2023-09-08 00:48:36 +08:00
Adrien Crivelli ef5762ec7f Rector PropertyTypeFromStrictSetterGetterRector 2023-09-08 00:40:49 +08:00
Adrien Crivelli 4b0da60ec4 Rector ParamTypeByMethodCallTypeRector 2023-09-08 00:18:38 +08:00
Adrien Crivelli 8026199841 Rector BoolReturnTypeFromStrictScalarReturnsRector 2023-09-07 23:23:38 +08:00
Adrien Crivelli 61740d0b17 Rector AddReturnTypeDeclarationBasedOnParentClassMethodRector 2023-09-07 23:04:13 +08:00
Adrien Crivelli e2e922d7af Rector AddParamTypeFromPropertyTypeRector 2023-09-07 22:59:07 +08:00
Adrien Crivelli c51e1a07aa Happy Stan 2023-09-07 22:47:00 +08:00
Adrien Crivelli ec4098c8fd Strict mode for all tests
While we might never be able to have 100% of our code strict, we can at
the very least do it for all of our tests. This ensures that our tests
are using our API with the types as intended by the test author, and not
silently be cast to what our API requires.
2023-09-07 17:44:56 +08:00
Adrien Crivelli 18a2e65372 GD can never be resource anymore since PHP 8.0 2023-09-07 17:16:40 +08:00
Adrien Crivelli 58cfc10a00 Stricter type for returning false 2023-09-07 17:01:18 +08:00
Adrien Crivelli 1b05dfab8b Rector AddParamTypeBasedOnPHPUnitDataProviderRector
And quite a bit more manual changes. The idea is that typing of our
tests can be a bit more loose, so we assume PHPDoc is mostly correct. If
that happens to be wrong, it should be caught by the tests themselves.
2023-09-07 17:00:24 +08:00
Adrien Crivelli 14d402ec93 Rector AddMethodCallBasedStrictParamTypeRector 2023-09-07 12:35:23 +08:00
Adrien Crivelli 922314c69e Rector ReturnTypeFromStrictNativeCallRector and ReturnTypeFromStrictScalarReturnExprRector 2023-09-07 12:35:22 +08:00
Adrien Crivelli bd633b1147 Tests work in any timezone 2023-09-07 10:16:48 +08:00
Adrien Crivelli 1ac6bf9d04 Drop unused code 2023-09-06 22:58:14 +08:00
Adrien Crivelli 27e9ed46af Latest phpDocumentor for PHP 8 compat 2023-09-06 22:58:14 +08:00
Adrien Crivelli f131ca30e6 Drop PHP 7.4 support
This is according to our formal, published, policy to only support
EOL PHP after 6 months.

See https://phpspreadsheet.readthedocs.io/en/latest/#php-version-support

Also share the exact same dev deps across all PHP version for GitHub
Actions so runs are faster, much most importantly they are stable and
predictable. And we decide manually when we want to migrate to PHPUnit
10.

Fixes #3634
Closes #3710
2023-09-06 22:51:47 +08:00
oleibman 7288b4de3d WIP Table Destructor (#3707)
There is a circular reference between Worksheet and Table, which can lead to a memory leak. I tried to break this connection in the Worksheet destructor earlier, but this seemed to cause some sort of error with Phpunit 10 on Github, an error that I am unable to duplicate in my local environments. This PR will allow me to explore the problem to see if I can come up with any useful diagnostic data. If I get to a combination that works, I will consider merging it.
2023-09-02 20:49:49 -07:00
oleibman 49a04bdf63 Use Column Style When Row Dimension Exists Without Style (#3688)
* Use Column Style When Row Dimension Exists Without Style

Fix #3534. For new cells, style is set to Row Dimension Style when Row Dimension exists (even if Row Dimension Style does not exist), else Column Dimension Style when Column Dimension exists. However it should be set to Row Dimension Style when Row Dimension exists *and* Row Dimension Style exists, else ...

* Address Issue 3533

If cell is defined in xml, it uses neither row nor column style. If style is omitted in cell definition, default style is used.

* Update CHANGELOG.md
2023-09-02 20:38:29 -07:00