Review main Merged

63036[TASK] Use a reference variable to pass $this into hooks

Alexander Schnitzler CR +2 V +2 Easy +20 −10 updated 02/14/20, 20:02

Commit message

Unfortunately phpstan looses the correct type of $this
as soon as $this is passed into a hooked as a hook method
parameter without a specific type. This leads to phpstan
losing the information about available methods and properties
of $this.

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Benni Mack +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Benni Mack +1

Issues 1

Files 6

Review log 1620

  1. Alexander Schnitzler uploaded patch set 1 01/25/20, 16:57

  2. Alexander Schnitzler wrote 01/25/20, 17:03

    Topic set to phpstan
  3. TYPO3com voted on patch set 1 V -1 01/25/20, 17:07 Completed build in 09m 46s on Sat, 25 Jan, 05:07 PM Test Summary: 70581 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-40227

  4. TYPO3com voted on patch set 1 V +1 01/25/20, 17:15 Completed build in 27m 16s on Sat, 25 Jan, 05:15 PM Test Summary: 70582 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-40227

  5. Alexander Schnitzler commented on patch set 1 01/28/20, 14:30

    ping
  6. Mathias Brodala commented on patch set 1 01/28/20, 14:36

    PageLayoutController.php:683

    Without looking into the Git history one won't be able to understand what this is good for. The variable should at least explain why it exists. I also fear that this pointless assignment (at least wrt runtime) will be dropped by some code cleanup in the future.
  7. Alexander Schnitzler commented on patch set 1 01/28/20, 14:38

    PageLayoutController.php:683 Reply

    Ok, what solution do you propose instead?
  8. Benni Mack commented on patch set 1 01/28/20, 17:38

    PageLayoutController.php:683 Reply

    The idea is that it's the $parentObject, however in other systems and frameworks it is basically the emitter. so $emitter would be my preference IMHO. Btw... if PHPstan looses the info on $this, shouldn't we fix this on PHPstan's side?
  9. Alexander Schnitzler commented on patch set 1 01/29/20, 16:43

    PageLayoutController.php:683 Reply

    > The idea is that it's the $parentObject, however in other systems and frameworks it is basically the emitter. so $emitter would be my preference IMHO. I'm fine with whatever name you want. I named it $ref, because that's the argument name of the hooks, not $parent. But still, we could name it $foo if we want. > Btw... if PHPstan looses the info on $this, shouldn't we fix this on PHPstan's side? I'm not sure that it's that easy to fix it in phpstan or if it's actually a bug. What we could also do is to create an extension that properly handles callUserFunction, similar to what we need in the future with makeInstance. I just hoped we could avoid adding more dependencies to reach level 0 compatibility to be able to integrate phpstan into our bamboo builds soon.
  10. Benni Mack commented on patch set 1 01/30/20, 07:27

    PageLayoutController.php:683 Reply Unresolved

    Looks like $ref is fine then from my PoV (thanks for digging this up).
  11. Benni Mack commented on patch set 1 01/30/20, 07:28

    PageLayoutController.php:791 Unresolved

    This is actually hilarious, looking at this code. WHY on earth would anyone want to call "callUserFunction" on a method that is properly defined. Will create a separate patch to fix this!
  12. Alexander Schnitzler uploaded patch set 2 02/02/20, 17:04

  13. Alexander Schnitzler commented on patch set 2 02/02/20, 17:10

    A few words on this patch. At this very moment this is the only solution to our problem. - phpstan won't be quickly updated. It's author is already facing dozens of issues on Github. phpstan will eventually mature but today is not the time to force this. - With TYPO3 11, we will remove the possibility to pass the last variable of callUserFunc by reference which already makes phpstan work correctly. As we will enforce only objects or null in the future and as objects are passed by reference anyway, that ampersand will vanish. So, to keep things simple, let's merge this into the core and we a are very close to level 0 compatibility.
  14. TYPO3com voted on patch set 2 V +1 02/02/20, 17:14 Completed build in 10m 14s on Sun, 2 Feb, 05:14 PM Test Summary: 71246 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-40483

  15. Benni Mack uploaded patch set 3 02/14/20, 19:47

  16. Benni Mack voted on patch set 3 CR +1 02/14/20, 19:48

  17. Georg Ringer voted on patch set 3 V +2 CR +2 02/14/20, 19:48

  18. Georg Ringer merged patch set 4 02/14/20, 19:48

  19. Benni Mack voted on patch set 4 V +1 02/14/20, 19:51

  20. TYPO3com voted on patch set 3 V +1 02/14/20, 20:02 Completed build in 15m 20s on Fri, 14 Feb, 08:02 PM Test Summary: 71253 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-83