Review main Merged

80100[TASK] Improve return type annotations for GU explode methods

Oliver Klee CR +2 V +2 Easy +7 −8 updated 07/25/23, 14:11

Commit message

This particularly helps PHPStan in extensions that call those methods
detect unnecessary checks for empty strings if
`GU::trimExplode` is called with `$removeEmptyValues = true`.

Used command:

> ./Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 2

Files 2

Review log 1822

  1. Oliver Klee uploaded patch set 1 07/20/23, 08:42

  2. core-ci voted on patch set 1 V -1 07/20/23, 08:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44336

  3. Oliver Klee uploaded patch set 2 V -1 07/20/23, 10:47

  4. Oliver Klee uploaded patch set 3 07/20/23, 10:48

  5. core-ci voted on patch set 3 V +1 07/20/23, 10:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44342

  6. core-ci voted on patch set 2 V +1 07/20/23, 10:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44341

  7. Alexander Schnitzler commented on patch set 3 V +1 CR +1 07/20/23, 12:35

    GeneralUtility.php:799

    Do we actuall need the return description `Exploded values`?
  8. Oliver Klee commented on patch set 3 07/20/23, 12:40

    GeneralUtility.php:799 Reply

    I left it in so it's consistent with the old `@param`, and in order to keep this change as small as possible. I'd be completely fine with removing it - whatever helps this change get merged. :-)
  9. Stefan Bürk commented on patch set 3 07/21/23, 21:19

    I would drop 11.5 here. 11.5 has a second argument, and therefore the return array may not be like stated now. It's conflicting anyway.

    GeneralUtility.php:745

    I would say combine the change with this todo directly in one change.
  10. Oliver Klee commented on patch set 3 07/24/23, 08:29

    Reply

    Particularly the change to `trimExplode`is of great value for extension authors who use PHPStan. So I'd really love to at least get that part backported down to 11.5. (I can split up the changes if that helps.) Should I split this change up? (I can also take care of the backports if this helps.)

    GeneralUtility.php:745 Reply

    I'm a big fan of the "one kind of change per PR/change" principle. So I'd like to move the rewrite of `intExplode` (and the other array-related GU methods) to a separate change (and preferably after I've added native type declarations to these methods).
  11. Stefan Bürk commented on patch set 3 07/24/23, 08:46

    Reply

    At least comment which should be the correct phpstan docblock annotation for v11 would help. Note: in v11 it could be that because of the limit argument (3rd) it is not ensured that the return values are always a int even with "removeEmptyValues = true" ``` public static function intExplode ($delimiter, $string, $removeEmptyValues = false, $limit = 0) ```
  12. Stefan Bürk commented on patch set 3 07/24/23, 08:48

    Reply

    An still, this may be breaking in sense of phpstan (also only ci related). Not sure if we really should to that for a version which is in more or less security priorty mode or shifting to this and disturb extensions developer after a such long time into a LTS version.
  13. Oliver Klee commented on patch set 3 07/24/23, 09:05

    Concerning the V11 backport, we only should take this change, but not the other:
    For the backport to V11, we only should take this change (and the PHPStan baseline update), but not the change to `intExplode`: ```php * @return list<string> Exploded values * @phpstan-return ($removeEmptyValues is true ? list<non-empty-string> : list<string>) Exploded values */ public static function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0): array ```
  14. Oliver Klee commented on patch set 3 07/25/23, 12:48

    Reply

    Ack
  15. Oliver Klee commented on patch set 3 07/25/23, 12:49

    Reply

    Chatted about this. Marking as resolved.
  16. Oliver Klee uploaded patch set 4 CR +1 V +1 07/25/23, 12:57

  17. Oliver Klee uploaded patch set 5 07/25/23, 12:58

  18. Oliver Klee commented on patch set 5 07/25/23, 12:59

    Sorry, pushed the wrong change by accident.
  19. core-ci voted on patch set 5 V +1 07/25/23, 13:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44531

  20. Christian Kuhn voted on patch set 5 V +2 CR +2 07/25/23, 13:35

  21. Christian Kuhn merged patch set 6 07/25/23, 13:35

  22. Stefan Bürk commented on patch set 6 V +1 CR +1 07/25/23, 14:11

    post +1