Review main Merged

81261[FEATURE] Deprecate and replace Abstractfile::FILETYPE_* with enum

Thomas Hohn CR +2 V +2 Hard +406 −239 updated 10/25/24, 08:00

Commit message

Deprecate the following constants in:
* `\TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_UNKNOWN`
* `\TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_TEXT`
* `\TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_IMAGE`
* `\TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_AUDIO`
* `\TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_VIDEO`
* `\TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_APPLICATION`

Instead a new native backed enum `\TYPO3\CMS\Core\Resource\FileType`
is added as a drop-in replacement.

Review

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

Issues 1

Files 19

Review log 3851

Show 1926 earlier messages
  1. Thomas Hohn uploaded patch set 1 09/27/23, 09:31

  2. core-ci voted on patch set 1 V -1 09/27/23, 09:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47221

  3. Thomas Hohn uploaded patch set 2 V -1 09/27/23, 09:53

  4. core-ci voted on patch set 2 V +1 09/27/23, 10:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47223

  5. Andreas Kienast commented on patch set 2 CR -1 09/27/23, 12:48

    AbstractFile.php:291

    FileType::TEXT

    Deprecation-102032-AbstractFileConstants.rst:29

    How? I think you mean that the extension scanner finds usages.

    Deprecation-102032-AbstractFileConstants.rst:50

    `APPLICATION`

    Deprecation-102032-AbstractFileConstants.rst:52

    Drop these, please. The main change is in EXT:core only.

    Deprecation-102032-AbstractFileConstants.rst:52

    `FullyScanned`, I guess.
  6. Thomas Hohn uploaded patch set 3 CR -1 V +1 09/27/23, 12:59

  7. Thomas Hohn commented on patch set 2 09/27/23, 12:59

    AbstractFile.php:291 Reply

    Done

    Deprecation-102032-AbstractFileConstants.rst:29 Reply

    Done

    Deprecation-102032-AbstractFileConstants.rst:50 Reply

    Done

    Deprecation-102032-AbstractFileConstants.rst:52 Reply

    Done

    Deprecation-102032-AbstractFileConstants.rst:52 Reply

    Done
  8. core-ci voted on patch set 3 V +1 09/27/23, 13:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47242

  9. Oliver Klee commented on patch set 3 V +1 09/27/23, 13:46

    Looks very good code-wise! I have commented a few smaller things concerning annotations and tests.

    AbstractFile.php:106

    For the `@deprecated` annotations, please also always list when the deprecated thing will be remove, e.g., ", will be removed in TYPO3 14"

    FileMetadataVisibleFieldsTest.php:54

    Instead of having the loop, I'd suggest to use a data provider instead. That would provide these benefits: - you see the labels of the data sets when the tests are run - the other cases in the test are still executed if one of the cases fails (In general, loops in tests are a considered a code smell that indicates that the code structure could be improved.)

    FileMetadataVisibleFieldsTest.php:55

    Can we use the positive check instead, i.e., `assertTrue`, so the test is as specific as possible?
  10. Thomas Hohn uploaded patch set 4 V +1 09/27/23, 15:36

  11. Thomas Hohn commented on patch set 3 09/27/23, 15:36

    AbstractFile.php:106 Reply

    Done

    Indexer.php:322 Reply

    Done

    FileMetadataVisibleFieldsTest.php:54 Reply

    I hope I did it the correct way ;-)

    FileMetadataVisibleFieldsTest.php:55 Reply

    Done
  12. Thomas Hohn commented on patch set 4 09/27/23, 15:36

    FileMetadataVisibleFieldsTest.php:54 Reply

    Done
  13. core-ci voted on patch set 4 V +1 09/27/23, 15:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47255

  14. Oliver Klee commented on patch set 4 09/27/23, 16:06

    FileMetadataVisibleFieldsTest.php:61

    `@return array<string, array{0: non-empty-string}` (if you add the labels as proposed below)

    FileMetadataVisibleFieldsTest.php:83

    I propose adding labels to the data provider items (using the keys of the outer array), e.g., like this: ```php 'categories' => ['categories'], ``` Then PHPUnit will display the label instead of the numeric ID of the data set that is currently used for the test.
  15. Thomas Hohn uploaded patch set 5 V +1 09/28/23, 04:04

  16. Thomas Hohn commented on patch set 4 09/28/23, 04:04

    FileMetadataVisibleFieldsTest.php:61 Reply

    Done

    FileMetadataVisibleFieldsTest.php:83 Reply

    Done
  17. core-ci voted on patch set 5 V -1 09/28/23, 04:16 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47266

  18. Thomas Hohn uploaded patch set 6 V -1 09/28/23, 04:34

  19. core-ci voted on patch set 6 V +1 09/28/23, 04:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47267

  20. Oliver Klee commented on patch set 6 V +1 CR +1 09/28/23, 06:57

    Neat! Thanks for this refactoring/cleanup! <3
  21. Andreas Kienast commented on patch set 6 CR -1 09/29/23, 07:21

    AbstractFile.php:289

    I propose to use `match()` over `switch`: ``` $this->properties['type'] = match (strtolower($fileType)) { 'text' => FileType::TEXT->value, 'image' => FileType::IMAGE->value, 'audio' => FileType::AUDIO->value, 'video' => FileType::VIDEO->value, 'application', 'software' => FileType::APPLICATION->value, default => FileType::UNKNOWN->value, }; ``` Also, I think it would make sense to return the enum instead (at a later point), but this would be breaking, of course.

    Indexer.php:327

    Also here, `match()` over `switch`: ``` $type = match (strtolower($fileType)) { 'text' => FileType::TEXT->value, 'image' => FileType::IMAGE->value, 'audio' => FileType::AUDIO->value, 'video' => FileType::VIDEO->value, 'application', 'software' => FileType::APPLICATION->value, default => FileType::UNKNOWN->value, }; ```

    Deprecation-102032-AbstractFileConstants.rst:14

    ``` :php:`ìnt` ```

    Deprecation-102032-AbstractFileConstants.rst:36

    This sentence is incomplete. Perhaps "[...] are affected."

    Feature-102032-FileType.rst:23

    We need an empty line before the list, otherwise the rendered doc is broken.

    FileMetadataVisibleFieldsTest.php:32

    Why is this empty?

    FileMetadataVisibleFieldsTest.php:47

    This test is now dead. The whole foreach doesn't do anything as the `$this->fileMetadataFields` array is empty.

    FileMetadataVisibleFieldsTest.php:63

    Please suffix a data provider with `DataProvider`
  22. Andreas Kienast commented on patch set 6 09/29/23, 07:22

    FileMetadataVisibleFieldsTest.php:63 Reply

    Also, the return type declaration is missing.
  23. Thomas Hohn commented on patch set 6 09/29/23, 08:11

    FileMetadataVisibleFieldsTest.php:47 Reply

    So I would need to fill the $this->fileMetadataFields array again - but hust with the file types and fix the other stuff?
  24. Thomas Hohn uploaded patch set 7 CR +1 V +1 10/02/23, 13:23

  25. Thomas Hohn commented on patch set 7 10/02/23, 13:25

    AbstractFile.php:289 Reply

    Done

    Indexer.php:327 Reply

    Done

    Deprecation-102032-AbstractFileConstants.rst:14 Reply

    Done

    Deprecation-102032-AbstractFileConstants.rst:36 Reply

    Done

    Feature-102032-FileType.rst:23 Reply

    Done
  26. core-ci voted on patch set 7 V +1 10/02/23, 13:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47350

  1. Thomas Hohn uploaded patch set 8 V +1 10/02/23, 13:58

  2. core-ci voted on patch set 8 V +1 10/02/23, 14:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47351

  3. Chris Müller commented on patch set 8 10/02/23, 14:45

    Feature-102032-FileType.rst:21

    ::php: -> :php:
  4. Thomas Hohn uploaded patch set 9 V +1 10/02/23, 19:05

  5. Thomas Hohn uploaded patch set 10 10/02/23, 19:11

  6. Thomas Hohn commented on patch set 9 10/02/23, 19:11

    Feature-102032-FileType.rst:21 Reply

    Done

    FileMetadataVisibleFieldsTest.php:32 Reply

    Removed now

    FileMetadataVisibleFieldsTest.php:47 Reply

    Done

    FileMetadataVisibleFieldsTest.php:63 Reply

    Done
  7. core-ci voted on patch set 9 V +1 10/02/23, 19:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47358

  8. Thomas Hohn commented on patch set 10 10/02/23, 19:15

    FileMetadataVisibleFieldsTest.php:32 Reply

    Done
  9. core-ci voted on patch set 10 V +1 10/02/23, 19:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47359

  10. Oliver Klee voted on patch set 10 V +1 CR +1 10/03/23, 15:36

  11. Benni Mack commented on patch set 10 10/12/23, 07:30

    AbstractFile.php:73

    what about this property?

    AbstractFile.php:289

    can we move this in the Enum?

    Indexer.php:323

    I think we should move this method in the Enum. then having a (int)FileType::tryFromMimeType($mimeType) in the code above
  12. Thomas Hohn uploaded patch set 11 CR +1 V +1 10/12/23, 15:08

  13. core-ci voted on patch set 11 V +1 10/12/23, 15:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47724

  14. Thomas Hohn commented on patch set 11 10/12/23, 15:31

    AbstractFile.php:73 Reply

    Done

    AbstractFile.php:289 Reply

    Done

    Indexer.php:323 Reply

    Done
  15. Oliver Klee commented on patch set 12 V +1 10/12/23, 15:37

    Published edit on patch set 11.
  16. Oliver Klee voted on patch set 12 V +1 CR +1 10/12/23, 15:37

  17. core-ci voted on patch set 12 V +1 10/12/23, 15:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47725

  18. Benni Mack uploaded patch set 13 CR +1 V +1 10/17/23, 19:21

  19. Benni Mack voted on patch set 13 V +1 CR +1 10/17/23, 19:22

  20. Oliver Klee voted on patch set 13 V +1 CR +1 10/17/23, 19:28

  21. core-ci voted on patch set 13 V +1 10/17/23, 19:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47882

  22. Benni Mack voted on patch set 13 V +2 CR +2 10/17/23, 19:32

  23. Benni Mack merged patch set 14 10/17/23, 19:32

  24. Benjamin Franzke commented on patch set 14 10/25/24, 06:56

    Deprecation-102032-AbstractFileConstants.rst:43

    Post -1 This change is annoying and half-baked: Replacing a constant by an enum and then using the enum value all over the place neglects the advantages of an enum. Sorry, this should have never been merged in this state. It's an intermediate "solution" with no benefit. TCA should have been adapted (yea that's complicated, but don't change things just to change them, improve them!) to accept the plain enum, not the value. After all, with the current state there is *ZERO* technical benefit in dropping the constant values, as we're using values all over the place anyway. That means extension authors have to change extensions for *ZERO* benefit. Change for the sake of change.
  25. Benni Mack commented on patch set 14 10/25/24, 08:00

    Deprecation-102032-AbstractFileConstants.rst:43 Reply

    Yes. You are right, as I stumbled over this multiple times in the past year. Thanks for mentioning this again. Unfortunately this is now (way) too late, but I will keep this in mind for all future changes in this area.