69371[BUGFIX] Fix phpstan errors from ReturnTypeRule
Commit message
Review
-
Code review CR +2 Done
- Christian Kuhn +2
- Oli Bartsch +1
-
Verified V +2 Done
- Christian Kuhn +2
- Oli Bartsch +1
- core-ci +1 CI
Issues 1
Files 11
- typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/BackendUserSettingsProvider.php2+1 −1
- typo3/sysext/lowlevel/Classes/Database/QueryGenerator.php2+7 −7
- typo3/sysext/recordlist/Classes/Browser/DatabaseBrowser.php+1 −1
- typo3/sysext/recordlist/Classes/Browser/FileBrowser.php+1 −1
- typo3/sysext/recordlist/Classes/Browser/FolderBrowser.php+1 −1
- typo3/sysext/recordlist/Classes/Controller/AbstractLinkBrowserController.php2+3 −3
- typo3/sysext/recycler/Classes/Task/CleanerTask.php2+5 −1
- typo3/sysext/reports/Classes/Report/Status/Status.php4+2 −2
- typo3/sysext/reports/Classes/Task/SystemStatusUpdateTask.php1+1 −2
- typo3/sysext/reports/Classes/StatusProviderInterface.php+1 −1
- typo3/sysext/rte_ckeditor/Classes/Form/Resolver/RichTextNodeResolver.php+1 −1
Review log 1214
-
Daniel Goerz uploaded patch set 1 06/03/21, 18:46
-
Daniel Goerz wrote 06/03/21, 18:46
Topic set to phpstan -
core-ci voted on patch set 1 V +1 06/03/21, 18:53 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12145
-
Oli Bartsch voted on patch set 1 CR +1 06/07/21, 08:20
-
Richard Haeser voted on patch set 1 CR +1 06/07/21, 12:47
-
crell commented on patch set 1 06/07/21, 18:45
A lot of error handling avoidance in this patch. At least some of them probably should be actual error handling, rather than swallowing.BackendUserSettingsProvider.php:26If uc isn't an array (or maybe null), isn't that a much larger problem?QueryGenerator.php:1055A false return from strftime() indicates an error condition. Just casting to a string silently hides the error condition and folds it to an empty string, with no indication that there's an error. That's probably not desireable. If there is an error, we want to know about it.AbstractLinkBrowserController.php:572As above, a false from json_encode() indicates an error. This would just silence and ignore the error. That's rarely a good idea. (If it is a good idea in context, that's what comments are for.)CleanerTask.php:146Ibid.Status.php:104Please document the structure of this nested array. (Either phpstan format or English, or preferably both.)SystemStatusUpdateTask.php:94UnresolvedIbid. -
Daniel Goerz commented on patch set 1 06/07/21, 20:28
Reply
You are of course right. This discussion came up in other phpstan related patches before and I am sure it will come up again 😊 These patches are always a little bit of a tradeoff. That is because the main goal is to activate the crucial phpstan rules to force appliance of new and refactored code. TYPO3 is (in its dusty corners) full of legacy code, and therefore we have hundrets, thousands of phpstan errors per rule. These patches aim to be non-breaking (so that we can actually merge them into v11), as little intrusive as possible (so that we minimize the risk for regressions) while still trying to address every issue. That is why often errors are "swallowed". Of course in some cases we also added error handling, or at least error logging, but we cant throw Exceptions where none where thrown before because that would be breaking, and we for sure cant refactor everything in these patches. More strict patches with potential breaking behavior will be possible in 12.0 again.BackendUserSettingsProvider.php:26Reply UnresolvedThis is more a theoretical point, as uc is always an array except for this one moment during reset, where it becomes an empty string. So, I'd say this is an example of making phpstan happy for now, in the long run we should not set this property to a string but that is for another patch to do.QueryGenerator.php:1055Reply UnresolvedYou are right. However, this is an example of veeeery low impact code and this change keeps the current behavior. I'd say there is no error handling needed here, as the output already shows that the value of the field could not be converted to a date.AbstractLinkBrowserController.php:572Reply UnresolvedHard to imagine a scenario where these actually fail and where we could provide useful feedback. But maybe worth thinking about it again.CleanerTask.php:146Reply UnresolvedAlright, we'll throw an Exception here, as the scheduler handles those by default. You have to manipulate the database record manually to trigger this error but it it possible.Status.php:104Reply\TYPO3\CMS\Reports\Status[][] means it is an array containing arrays of Status Objects, right? -
Daniel Goerz uploaded patch set 2 06/07/21, 20:28
-
core-ci voted on patch set 2 V +1 06/07/21, 20:43 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12202
-
crell commented on patch set 2 06/07/21, 22:35
Reply
Roger, and understood. I know there's a lot of code I'm seeing that I'm itching to refactor heavily. :) Should any @todos be left on them, though, so we remember which ones need more refactoring once that's a thing?Status.php:104ReplyHonestly, I've never seen that double-array comment style before. It doesn't say what the key types are, though, or what to do with that structure, just that the leaves are Status objects. -
Oli Bartsch voted on patch set 2 V +1 CR +1 06/17/21, 13:39
-
Oliver Klee commented on patch set 2 06/17/21, 13:54
Status.php:104Reply UnresolvedYes, Status[][] is the same as: array<array<Status>> or array<array-key, array<array-key, Status>> We can also specify the key types (which is not possible with the [] syntax): array<int, array<int, Status>> -
Christian Kuhn voted on patch set 2 V +2 CR +2 06/17/21, 16:27
-
Christian Kuhn merged patch set 3 06/17/21, 16:27