Review main Merged

74347[BUGFIX] Allow XCLASSing of WorkspaceRecord

Oliver Klee CR +2 V +2 Normal +101 −8 updated 06/19/22, 00:51

Commit message

The factory method WorkspaceRecord::get() now uses a proper
makeInstance() call instead of new for creating new instances,
which allows XCLASSing the class and aligns object creation
to "the TYPO3 way" in that place.

Also add a regression test.

Review

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

Issues 1

Files 3

Review log 3947

Show 1922 earlier messages
  1. Oliver Klee uploaded patch set 1 04/18/22, 14:15

  2. core-ci voted on patch set 1 V +1 04/18/22, 14:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26150

  3. Benni Mack commented on patch set 1 05/13/22, 14:54

    If you can rebase this one as well, we can also continue here. Would be great.
  4. Oliver Klee uploaded patch set 2 05/13/22, 15:03

  5. Oliver Klee commented on patch set 2 05/13/22, 15:04

    Reply

    Done.
  6. core-ci voted on patch set 2 V +1 05/13/22, 15:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27181

  7. Benni Mack voted on patch set 2 CR +1 05/13/22, 15:52

  8. crell voted on patch set 2 CR +1 05/13/22, 17:25

  9. Stefan Bürk commented on patch set 2 05/19/22, 00:08

    WorkspaceRecord.php:81

    If we change this to "new self()" it is the same as making the class final. Options like make constructor final or adding a intefcace for the constructor is out of scope too. Would following alternative be okay for you ? ``` $className = static::class; return new $className($record); ``` see: https://3v4l.org/9VDMR Using new self() would always return a WorkspaceRecord instance, even if extended.
  10. Oliver Klee commented on patch set 2 05/19/22, 10:09

    WorkspaceRecord.php:81 Reply

    This approach would not solve the problem of breakage when a subclass overwrites the constructor with different parameters. There's a blog post explaining the problem and different solutions: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static In this case, I'd prefer to keep the new static(), make the constructor final, and make this main-only. What do you think? And should this be a breaking change with the corresponding marker and RST?
  11. Benni Mack commented on patch set 2 05/19/22, 10:25

    Well, if we want

    WorkspaceRecord.php:81 Reply

    hmm, then I think it would be much better to actually build a "RecordFactory" (that can be injectible) that actually then has a "getWorkspaceRecord()" instead of the static method?
  12. Oliver Klee commented on patch set 2 CR -1 05/19/22, 12:05

    We need to talk about this. Blocking for the time being.
  13. Oliver Klee marked it work in progress 05/21/22, 13:50

  14. Oliver Klee uploaded patch set 3 06/09/22, 11:40

  15. Oliver Klee marked it ready for review 06/09/22, 11:40

  16. Oliver Klee commented on patch set 3 06/09/22, 11:40

    WorkspaceRecord.php:81 Reply

    Done
  17. core-ci voted on patch set 3 V +1 06/09/22, 11:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27881

  18. Simon Schaufelberger voted on patch set 3 V +1 CR +1 06/09/22, 11:56

  19. Benni Mack voted on patch set 3 V +1 CR +1 06/09/22, 14:34

  20. crell commented on patch set 3 CR -1 06/09/22, 16:25

    I have to disagree here. GU:mI is something we're trying to reduce and eliminate usage of. Adding another call, which also makes testing harder, is counter-productive. If this really needs to be overridable, then as Benni said a factory is better. If it really needs to be extensible, then... honestly phpstan is just not helpful here and we should ignore it. Replacing one deficient design with another deficient design is not an improvement.
  21. Oliver Klee commented on patch set 3 06/09/22, 16:36

    Benni and I talked about this and agreed to use makeInstance as the immediate approach and a refactoring to a repository and data mapper (as outlined in the related issue #97754) later.
  22. Stefan Bürk commented on patch set 3 V +1 CR +1 06/09/22, 16:42

    Reply

    Was not involved in that discussion. But seeing the solution after Benni's statement, that has been my thouths too. Would not make sense to add a additionaly factory now which has to be GU:MI() here anyway in the public static method. Documented and further work is documented, and for the first time beeing I'm fine with this. But to be honest - thought between "okay for now" and "should we do it that way and directly refactor it" but came for my self to the same conclusion as Benni and Oliver. Fine as a intermediate solution. (which may change / vanish / be deprecated in v12 anyway then).
  1. Benni Mack commented on patch set 3 V 0 CR 0 06/09/22, 20:40

    after reading the comments from today. My question is then: why should we fix this? We trade a "PHPStan does not complain" against a TYPO3-invented pattern (GeneralUtility::makeInstance) which is also not-superclean? Yes, this piece of code isn't clean, but I sometimes wonder if we spend too much time on such changes, where there is no best solution with a one-liner change, but at the same time, we keep the bugs that users report out of our sight. My two cents on this particular change: Either way (keeping the old way, replacing this with static, replacing this with makeInstance) is fine with me. I honestly do not have a strong opinion here. I just find it hard to grasp how we can not come up with a consensus on this change. Such stuff drains my motivation, as we still have 2400+ other bugs to fix, and for me this feels we're not making real progress.
  2. Oliver Klee commented on patch set 3 06/10/22, 07:37

    Larry, now that you know that we have a plan and a refactoring for a refactoring, would you be willing to remove your -1 so we can get this bugfix merged?
  3. Oliver Klee commented on patch set 3 06/10/22, 13:02

    I'll try to explain the benefits of this change. :-) Currently, it is not possible to XCLASS the WorkspaceRecord class, i.e., to register a (sub)class that will be automatically be instantiated in place of the WorkspaceRecord class. This fix remedies that problem. That this also removes a PHPStan warning is only a (nice) sideeffect. The refactoring of the factory method will happen in a later change in #97754.
  4. Oli Bartsch commented on patch set 3 06/10/22, 15:30

    Could we cover this with a test to ensure no one will change this back again in the future?
  5. crell commented on patch set 3 CR 0 06/10/22, 16:04

    Unblocking because of the plan in #97754, though I'm only moving to neutral, not +1.
  6. Oliver Klee uploaded patch set 4 06/10/22, 16:55

  7. Oliver Klee commented on patch set 3 06/10/22, 16:56

    Reply

    Thanks, sure. Done.
  8. core-ci voted on patch set 4 V -1 06/10/22, 17:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27937

  9. core-ci commented on patch set 4 06/10/22, 17:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27937

  10. Oliver Klee commented on patch set 4 06/10/22, 17:17

    This is strange. On my local system the tests are green, and the failure is in a totally unrelated test. Looking into it.
  11. Oliver Klee commented on patch set 4 06/10/22, 17:58

  12. Oliver Klee rebased onto patch set 5 06/10/22, 18:19

  13. core-ci voted on patch set 5 V +1 06/10/22, 18:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27946

  14. Oliver Klee rebased onto patch set 6 06/17/22, 08:25

  15. core-ci voted on patch set 6 V +1 06/17/22, 08:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28128

  16. Simon Schaufelberger voted on patch set 6 CR +1 06/17/22, 09:50

  17. Daniel Haupt voted on patch set 6 V +1 CR +1 06/17/22, 20:28

  18. Christian Kuhn commented on patch set 6 06/18/22, 23:51

    WorkspaceRecordTest.php:4

    misses license header.

    WorkspaceRecordTest.php:13

    we don't add @covers annotations and don't measure coverage. pls drop.
  19. Christian Kuhn uploaded patch set 7 06/19/22, 00:20

  20. core-ci voted on patch set 7 V +1 06/19/22, 00:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28206

  21. Christian Kuhn commented on patch set 7 06/19/22, 00:35

    WorkspaceRecordTest.php:4 Reply

    Done

    WorkspaceRecordTest.php:13 Reply

    Done
  22. Simon Schaufelberger voted on patch set 7 V +1 CR +1 06/19/22, 00:37

  23. Christian Kuhn voted on patch set 7 V +1 CR +1 06/19/22, 00:39

  24. Stefan Bürk voted on patch set 7 V +2 CR +2 06/19/22, 00:51

  25. Stefan Bürk merged patch set 8 06/19/22, 00:51