Review main Merged

77984[TASK] Ensure type safety in YamlFileLoader

Thomas Hohn CR +2 V +2 Easy +2 −2 updated 03/01/23, 12:10

Commit message

The method getFileContents has return type string. However it contains
a call to file_get_contents, that can return a boolean in case of failure.
Added a check for if the file is readable and a cast to string when
returning the value of the call to file_get_contents.
In case of failure it will return the empty string, which will be caught
properly in the method loadAndParse. Afterwards the error handling could
be improved in loadAndParse to be more specific.

Review

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

Issues 1

Files 1

Review log 3035

Show 810 earlier messages
  1. Thomas Hohn uploaded patch set 1 02/28/23, 18:14

  2. core-ci voted on patch set 1 V +1 02/28/23, 18:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38226

  3. Thomas Hohn uploaded patch set 2 V +1 02/28/23, 18:22

  4. Stefan Bürk voted on patch set 2 V +1 CR +1 02/28/23, 18:29

  5. core-ci voted on patch set 2 V +1 02/28/23, 18:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38227

  6. Oliver Klee voted on patch set 2 CR +1 02/28/23, 20:14

  7. Oli Bartsch voted on patch set 2 V +1 CR +1 02/28/23, 20:30

  8. Simon Schaufelberger commented on patch set 2 03/01/23, 00:02

    This is basically the same as https://review.typo3.org/c/Packages/TYPO3.CMS/+/77978 but handled in a slightly different way there. which method do you prefer?
  9. Thomas Hohn uploaded patch set 3 CR +1 V +1 03/01/23, 05:04

  10. Thomas Hohn commented on patch set 3 03/01/23, 05:05

    Reply

    I would prefer to go for consistency and have it as in https://review.typo3.org/c/Packages/TYPO3.CMS/+/77978, since it makes the it more robust. There is also really no need to try to fetch the content for a file that isn't readable.
  1. core-ci voted on patch set 3 V +1 03/01/23, 05:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38243

  2. Christian Kuhn voted on patch set 3 V +1 CR +1 03/01/23, 08:33

  3. Oliver Klee voted on patch set 3 CR +1 03/01/23, 08:55

  4. Simon Schaufelberger voted on patch set 3 V +1 CR +1 03/01/23, 09:47

  5. Christian Kuhn commented on patch set 3 03/01/23, 10:06

    YamlFileLoader.php:109

    i'd say the is_readable is useless, we can rely on (string)file_get_contents($fileName) only.
  6. Benni Mack commented on patch set 3 03/01/23, 10:08

    YamlFileLoader.php:109 Reply

    I agree. probably "(string)@file_get_contents($fileName)"
  7. Christian Kuhn uploaded patch set 4 CR +1 V +1 03/01/23, 10:08

  8. Christian Kuhn commented on patch set 3 V +1 CR +1 03/01/23, 10:09

    YamlFileLoader.php:109 Reply

    Done
  9. Christian Kuhn voted on patch set 4 V +1 CR +1 03/01/23, 10:09

  10. Stefan Bürk voted on patch set 4 V +1 CR +1 03/01/23, 10:09

  11. Christian Kuhn voted on patch set 4 CR -1 03/01/23, 10:12

  12. Christian Kuhn commented on patch set 4 03/01/23, 10:14

    YamlFileLoader.php:109 Reply

    actually, it's probably better to keep the is_readable, since file_get_contents() tends to raise a "Failed to open stream: No such file or directory" warning, otherwise, see https://forge.typo3.org/issues/99926 and patch. i'll go back to version 3.
  13. Christian Kuhn uploaded patch set 5 CR +1 V +1 03/01/23, 10:15

  14. Thomas Hohn commented on patch set 4 03/01/23, 10:15

    YamlFileLoader.php:109 Reply

    Actually the is_readable($fileName) was added to avoid triggering a PHP warning in case the file doesn't exist
  15. Christian Kuhn voted on patch set 5 V +1 CR +1 03/01/23, 10:15

  16. core-ci voted on patch set 4 V +1 03/01/23, 10:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38256

  17. Christian Kuhn commented on patch set 5 03/01/23, 10:16

    YamlFileLoader.php:109 Reply

    Ack
  18. core-ci voted on patch set 5 V +1 03/01/23, 10:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38257

  19. Oliver Klee voted on patch set 5 CR +1 03/01/23, 10:25

  20. Thomas Hohn commented on patch set 5 03/01/23, 10:32

    YamlFileLoader.php:109 Reply

    So should I add it again - with a comment in the code?
  21. Thomas Hohn commented on patch set 5 03/01/23, 10:55

    YamlFileLoader.php:109 Reply

    Done
  22. Simon Schaufelberger commented on patch set 5 V +1 CR +1 03/01/23, 11:35

    just do the same thing in the LocalDriver as well
  23. Thomas Hohn commented on patch set 5 03/01/23, 11:55

    Reply

    Yes - we do it in identical ways ;-)
  24. Christian Kuhn voted on patch set 5 V +2 CR +2 03/01/23, 12:10

  25. Christian Kuhn merged patch set 6 03/01/23, 12:10