Review main Merged

77788[TASK] Use `list` as return type annotation for `GU::*Explode` methods

Elias Häußler CR +2 V +2 Easy +2 −2 updated 02/13/23, 09:12

Commit message

The `GU::revExplode` and `GU::trimExplode` methods return lists of
elements. Thus, we can safely annotate them as `list` instead of `array`
to allow better static code analysis. The annotation for
`GU::intExplode` is not changed at the moment since this method behaves
differently.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Oliver Klee +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Oliver Klee +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 2123

  1. Elias Häußler uploaded patch set 1 02/08/23, 14:05

  2. Oliver Klee commented on patch set 1 CR -1 02/08/23, 14:16

    I had started something similar in https://review.typo3.org/c/Packages/TYPO3.CMS/+/75083 and would rebase my change once this change gets merged.

    GeneralUtility.php:837

    For return types, we should be as specific as possible. In this case, it should be array<int, int>, and for revExplode and trimExplode, it should be array<int, string>.
  3. core-ci voted on patch set 1 V +1 02/08/23, 14:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37373

  4. Oliver Klee commented on patch set 1 02/08/23, 14:22

    Also, I'd be interested to learn how `list` would allow better static code analysis than `array`. (This is not a rhetorical question - I really would like to know.)
  5. Oliver Klee commented on patch set 1 CR +1 02/08/23, 17:59

    Reply

    I've found some documentation: https://phpstan.org/writing-php-code/phpdoc-types#lists > Lists are arrays with sequential integer keys starting at 0.

    GeneralUtility.php:837 Reply

    Now that I know what `list` actually means, this indeed is better than `array`.
  6. Oliver Hader voted on patch set 1 V +1 CR +1 02/08/23, 19:11

  7. Nikita Hovratov commented on patch set 1 CR -1 02/09/23, 09:43

    GeneralUtility.php:844

    As empty values are unset here, it sometimes does not return a pure sequential list.
  8. Nikita Hovratov commented on patch set 1 02/09/23, 09:47

    GeneralUtility.php:856

    And here even it does add a string, that's why phpstan is complaining.
  9. Oliver Klee commented on patch set 1 02/09/23, 10:09

    GeneralUtility.php:844 Reply

    Ah, indeed. Then the return value needs to be array<int, int>.

    GeneralUtility.php:856 Reply

    I know. :-( I talked to Stefan Bürk about this. The part with the limit is not fully documented and contradicts the rest of the documented functionality of this method. This is why I'd like to deprecate the limit parameter before the 12LTS release. I'd suggest to keep the additional PHPStan warning in the meantime.
  10. Nikita Hovratov commented on patch set 1 02/09/23, 10:20

    GeneralUtility.php:856 Reply

    yes, do it! I've never used it so far and it does actually make no sense in this method.
  11. Nikita Hovratov commented on patch set 1 02/09/23, 10:21

    GeneralUtility.php:844 Reply

    we could also add a `array_values` at the end, but I don't know if there are any implications by doing so.
  12. Oliver Klee commented on patch set 1 02/09/23, 13:14

    GeneralUtility.php:844 Reply

    Done (as a pre-patch): https://review.typo3.org/c/Packages/TYPO3.CMS/+/77802 As this is a change of behavior, I've marked the pre-patch as main-only, which then would make this change here main-only, tool.
  13. Oliver Klee commented on patch set 1 02/09/23, 14:49

    GeneralUtility.php:856 Reply

  14. Stefan Bürk commented on patch set 1 02/09/23, 20:41

    GeneralUtility.php:856 Reply

    As discussed with Oliver back than, personally I'm against it. I used the limit a lot, and expected it. Sure, I could replace that with plain php methods to achieve the same result in agency code (or at least the person taking over my code there). Given the name, despite the docblock, I always expected a "intExplode()" to behave like the "php explode()" method, as long as `$limit` is an option. So deprecating it would be the only way, as it cannot be dropped directly without change in behaviour and thus breaking. So I rather would not vote - neither on the deprecation nor on that patch. But this makes only sense, if the limit arguement has been removed. Which will not happen until v13.
  15. Oliver Klee commented on patch set 1 CR 0 02/09/23, 21:51

    Then I propose we change this change to only affect trimExplode and revExplode so we can at least get those changes in. What do you think?
  16. Oliver Klee commented on patch set 1 02/11/23, 19:00

    Elias, would you be okay with limiting this change to revExplode and trimExplode? If so, would you like to do the change, or should I do it?
  17. Elias Häußler commented on patch set 1 02/13/23, 06:56

    Reply

    Thanks for all your feedback and sorry for the late reply. Will take care of it now.
  18. Elias Häußler uploaded patch set 2 CR +1 V +1 02/13/23, 07:57

  19. Elias Häußler commented on patch set 2 02/13/23, 07:58

    Reply

    Done

    GeneralUtility.php:856 Reply

    Done
  20. core-ci voted on patch set 2 V +1 02/13/23, 08:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37631

  21. Oliver Klee voted on patch set 2 V +1 CR +1 02/13/23, 09:02

  22. Christian Kuhn voted on patch set 2 V +2 CR +2 02/13/23, 09:12

  23. Christian Kuhn merged patch set 3 02/13/23, 09:12