Review main Merged

69371[BUGFIX] Fix phpstan errors from ReturnTypeRule

Daniel Goerz CR +2 V +2 Easy +24 −21 updated 06/17/21, 16:27

Commit message

EXT:lowlevel
EXT:recordlist
EXT:recycler
EXT:reports
EXT:rte_ckeditor

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

Review log 1214

  1. Daniel Goerz uploaded patch set 1 06/03/21, 18:46

  2. Daniel Goerz wrote 06/03/21, 18:46

    Topic set to phpstan
  3. 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

  4. Oli Bartsch voted on patch set 1 CR +1 06/07/21, 08:20

  5. Richard Haeser voted on patch set 1 CR +1 06/07/21, 12:47

  6. 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:26

    If uc isn't an array (or maybe null), isn't that a much larger problem?

    QueryGenerator.php:1055

    A 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:572

    As 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:146

    Ibid.

    Status.php:104

    Please document the structure of this nested array. (Either phpstan format or English, or preferably both.)

    SystemStatusUpdateTask.php:94 Unresolved

    Ibid.
  7. 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:26 Reply Unresolved

    This 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:1055 Reply Unresolved

    You 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:572 Reply Unresolved

    Hard to imagine a scenario where these actually fail and where we could provide useful feedback. But maybe worth thinking about it again.

    CleanerTask.php:146 Reply Unresolved

    Alright, 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:104 Reply

    \TYPO3\CMS\Reports\Status[][] means it is an array containing arrays of Status Objects, right?
  8. Daniel Goerz uploaded patch set 2 06/07/21, 20:28

  9. 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

  10. 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:104 Reply

    Honestly, 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.
  11. Oli Bartsch voted on patch set 2 V +1 CR +1 06/17/21, 13:39

  12. Oliver Klee commented on patch set 2 06/17/21, 13:54

    Status.php:104 Reply Unresolved

    Yes, 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>>
  13. Christian Kuhn voted on patch set 2 V +2 CR +2 06/17/21, 16:27

  14. Christian Kuhn merged patch set 3 06/17/21, 16:27