Review main Merged

80704[BUGFIX] Correct type check for stream resource

Mathias Bolt Lesniak CR +2 V +2 Easy +22 −1 updated 08/28/23, 10:11

Commit message

The constructor of `\TYPO3\CMS\Core\Http\Request` now correctly
accepts resources of the type "stream" as $body argument.

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 2

Files 2

Review log 1722

  1. Mathias Bolt Lesniak uploaded patch set 1 08/27/23, 07:18

  2. core-ci voted on patch set 1 V +1 08/27/23, 07:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45865

  3. Oliver Klee commented on patch set 1 08/27/23, 08:17

    Have you checked if the main branch is affected as well? (If it is, you would need to set “Releases: main, 12.4” in the commit message and create the change for the main branch. The merger then takes care of the 12.4 backport.)
  4. Oliver Klee commented on patch set 1 08/27/23, 09:27

    RequestTest.php:144

    Let's make the test name more specific. ("works" is not very specific.) My suggestion: `constructorForValidBodyDoesNotCrash`

    RequestTest.php:144

    `$body` should get a type declaration.
  5. Mathias Bolt Lesniak uploaded patch set 2 V +1 08/27/23, 21:50

  6. Mathias Bolt Lesniak commented on patch set 2 08/27/23, 21:57

    Reply

    Done. Thanks.

    RequestTest.php:144 Reply

    That would not follow the convention set by the other tests, like `public function constructorRaisesExceptionForInvalidBody($body): void`. I would also argue that adding a type declaration would defeat the purpose of the test, which is to test the constructor of the `Request` class. That constructor doesn't have any type declaration for $body. Adding a type declaration for $body the `Request` class is possibly beyond the scope of this bug. (I don't know.) It would also affect a few other classes.

    RequestTest.php:144 Reply

    Good point. I changed it to `constructorDoesNotRaiseExceptionForValidBody` in Patchset 2. This is closer to the `constructorRaisesExceptionForInvalidBody` method name I'm basing it on.
  7. core-ci voted on patch set 2 V +1 08/27/23, 21:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45868

  8. Oliver Klee commented on patch set 2 08/28/23, 08:17

    RequestTest.php:144 Reply

    My best guess is that the other tests are from a time when type declarations in PHP were very limited. It certainly is not a convention. New code should have type declarations (where it's technically possible), and those type declarations should be as strict as possible (with additional `@param`/`@return` annotations if those help make the type more specific).

    RequestTest.php:144 Reply

    Done
  9. Oliver Klee commented on patch set 2 08/28/23, 08:18

    RequestTest.php:144 Reply

    And I'm referring only to adding a type declaration to the test method here, not the tested method (the constructor) or the other tests.
  10. Christian Kuhn commented on patch set 2 08/28/23, 09:24

    RequestTest.php:144 Reply

    php does not allow type hinting "resource". As such, a type hint for $body is impossible since the DP has a test case using resource (from fopen()).
  11. Mathias Bolt Lesniak uploaded patch set 3 V +1 08/28/23, 09:31

  12. Christian Kuhn updated the commit message in patch set 4 08/28/23, 09:35

  13. Mathias Bolt Lesniak commented on patch set 3 08/28/23, 09:36

    RequestTest.php:144 Reply

    Haha. I discovered that now. But I added an annotation - as well as an additional data set for $body being null, since I had missed it previously.
  14. Christian Kuhn voted on patch set 4 V +1 CR +1 08/28/23, 09:36

  15. core-ci voted on patch set 3 V -1 08/28/23, 09:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45882

  16. core-ci voted on patch set 4 V -1 08/28/23, 09:42 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45883

  17. Christian Kuhn uploaded patch set 5 CR +1 V +1 08/28/23, 09:51

  18. Christian Kuhn voted on patch set 5 V +1 CR +1 08/28/23, 09:51

  19. Oliver Klee voted on patch set 5 V +1 CR +1 08/28/23, 09:57

  20. core-ci voted on patch set 5 V +1 08/28/23, 09:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45884

  21. Christian Kuhn voted on patch set 5 V +2 CR +2 08/28/23, 10:11

  22. Christian Kuhn merged patch set 6 08/28/23, 10:11