Review main Merged

73270[BUGFIX] Avoid PHP 8.0/8.1 error in RecordHistory

TYPO3com CR +2 V +2 Easy +4 −4 updated 02/05/22, 11:25

Commit message

When passing null as $value parameter, an exception is
thrown as the return value must be of type string. We
avoid this by adding string type-hints to the signature
of two methods and string cast the values directly in
the class constructor.

It should be investigated constructor arguments can be
tightened with another patch.

Review

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

Issues 1

Files 1

Review log 1317

  1. TYPO3com uploaded patch set 1 02/03/22, 17:47

  2. core-ci voted on patch set 1 V +1 02/03/22, 17:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22964

  3. Stefan Bürk commented on patch set 1 CR -1 02/03/22, 18:29

    on it
    Casing/typo .. must be "[BUGFIX]"

    RecordHistory.php:468

    I would avoid that here and instead add the string-cast in the constructor itself. We should check if we "may" add a correct string typehint to the method signatore, as it is proteced anyway.

    RecordHistory.php:483

    Same goes here. Move string-cast to constructor.
  4. Stefan Bürk uploaded patch set 2 02/03/22, 18:29

  5. core-ci voted on patch set 2 V +1 02/03/22, 18:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22968

  6. Oliver Klee commented on patch set 2 02/04/22, 11:24

    RecordHistory.php:81

    Although this clearly is an improvement, this still does not feel clean to me (as the parameters currently already are strings according to the PHPDoc type annotations). I see two possible ways to solve this in a cleaner way: a) make both parameter nullable, and explicitly deal with null values b) keep both parameters non-nullable, and fix the callers instead to always provide strings (and never null). What do you think, Stefan?
  7. Stefan Bürk commented on patch set 2 02/04/22, 17:30

    RecordHistory.php:81 Reply

    Thanks Oliver. Generally you are right. Also the "phpdoc" states that both arguments have to be "string", the where called with "null". Thus the original patch owner provided a patch to do the string casts in the two called methods. My thought was to solve this in two steps, with this as the first one as backportable bugfix. In contrast to the first patch version, I move the string cast here to the constructor and make the protected method string typed as a first step. Leaving the phpdoc as-is and not changing to nullable type - which would "open up" the signature instead of adapting the signature as strict type. In the end the transition must be strict type strings here. It does not make much sense to deal with nullable-strings here for these thwo arguments. I would do your point b in a dedicated patch or patches: 1. ensure core internal calls are ensured to passe string to this constructor 2. add string types to constructor arguments - not sure if this may be a breaking thing, as this class is not marked as internal. However there are more things we can make strict type in this class, and thus I would suggest that we use the patch now as a bugfix with backport and doing the strict-typing afterwards. As my original thought was. Maybe we should add a @todo here to the constructor noting this plan to ensure callee's passes strings and then strict type the constructor (along with other strict typings). Which we should do in main only, and not as bugfix backport. Would this plan be fine for you ?
  8. Oliver Klee commented on patch set 2 02/04/22, 17:48

    RecordHistory.php:81 Reply

    Yes, sounds good. Thanks!
  9. Oliver Klee voted on patch set 2 CR +1 02/04/22, 20:09

  10. Christian Kuhn uploaded patch set 3 02/05/22, 07:49

  11. Christian Kuhn commented on patch set 3 02/05/22, 07:49

    Reply

    Done

    RecordHistory.php:468 Reply

    Done

    RecordHistory.php:483 Reply

    Done
  12. Christian Kuhn voted on patch set 3 V +1 CR +1 02/05/22, 07:49

  13. core-ci voted on patch set 3 V +1 02/05/22, 08:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/23035

  14. Oliver Klee voted on patch set 3 CR +1 02/05/22, 11:07

  15. Susi Moog voted on patch set 3 V +1 CR +1 02/05/22, 11:16

  16. Christian Kuhn voted on patch set 3 V +2 CR +2 02/05/22, 11:25

  17. Christian Kuhn merged patch set 4 02/05/22, 11:25