Review main Merged

85853[TASK] Add AbstractMethodImplementationMatcher to extension scanner

Garvin Hicking CR +2 V +2 Hard +358 −0 updated 09/12/24, 09:04

Commit message

The Extension Scanner of the EXT:install module allows to scan
custom extensions based on several static code analysis rules.

Most of these rules depend on analyzing code to see if deprecated
or removed methods are called, or if argument names change,
annotations/attributes get removed and so on.

This patch adds a `AbstractMethodImplementationMatcher` matcher which
can analyze definitions of specific methods within an extended abstract
class that need to be migrated.

A good example for this is the change in Fluid ViewHelpers deprecating
the "renderStatic" method, which could previously not be matched.

Because ViewHelpers themself do not execute a `renderStatic`
method, any custom ViewHelper implementing `renderStatic`
would not be revealed in the Extension Scanner before.

The Matcher receives a configuration like:

```
return [
 'TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::renderStatic'
   => [
        'restFiles' => [
          'Deprecation-104789-RenderStaticForFluidViewHelpers.rst',
      ],
   ],
];
```

and based on this, iterates every custom code to check if
any class inherits from this
`TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper` abstract,
and then checks for a given method name (here `renderStatic`).
Both static (`::`) and "local" ( `->`) methods can
be configured for matching.

These matches will be reported as strong matches.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Simon Praetorius +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Simon Praetorius +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 2

Files 5

Review log 2636

Show 711 earlier messages
  1. Garvin Hicking uploaded patch set 1 09/03/24, 11:37

  2. Garvin Hicking uploaded patch set 2 09/03/24, 11:40

  3. Garvin Hicking commented on patch set 2 09/03/24, 11:41

    NOTE: To test this, please adapt `typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodDefinitionMatcher.php` and enter an existing ReST file name there. Check out the screenshot in the issue how a match looks like.
  4. core-ci voted on patch set 1 V -1 09/03/24, 11:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64661

  5. core-ci voted on patch set 2 V -1 09/03/24, 12:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64662

  6. Garvin Hicking uploaded patch set 3 V -1 09/03/24, 12:18

    Use a dummy for ReST matching
  7. core-ci voted on patch set 3 V -1 09/03/24, 12:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64665

  8. Garvin Hicking uploaded patch set 4 V -1 09/03/24, 12:46

    Proper type usage
  9. core-ci voted on patch set 4 V -1 09/03/24, 13:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64668

  10. Garvin Hicking uploaded patch set 5 V -1 09/03/24, 13:53

    Adjust to merged fluid patch
  11. Garvin Hicking commented on patch set 5 09/03/24, 13:53

    Reply

    With the merge of https://review.typo3.org/c/Packages/TYPO3.CMS/+/85837 the ReST file is not properly aligned.
  1. Garvin Hicking commented on patch set 5 09/03/24, 13:54

    Reply

    s/not/now/
  2. core-ci voted on patch set 5 V -1 09/03/24, 13:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64670

  3. core-ci commented on patch set 5 09/03/24, 17:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64670

  4. Simon Praetorius commented on patch set 5 09/03/24, 17:31

    MethodDefinitionMatcher.php:29

    How about naming it `AbstractMethodImplementationMatcher`? Other than that: LGTM!
  5. Garvin Hicking uploaded patch set 6 V -1 09/04/24, 13:20

  6. Garvin Hicking commented on patch set 6 09/04/24, 13:20

    MethodDefinitionMatcher.php:29 Reply

    Done
  7. core-ci voted on patch set 6 V -1 09/04/24, 13:27 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64757

  8. Garvin Hicking uploaded patch set 7 V -1 09/04/24, 13:28

  9. core-ci voted on patch set 7 V +1 09/04/24, 13:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64758

  10. Garvin Hicking updated the commit message in patch set 8 V +1 09/04/24, 13:39

  11. core-ci voted on patch set 8 V +1 09/04/24, 13:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64759

  12. Simon Praetorius commented on patch set 8 09/04/24, 13:52

    AbstractMethodImplementationMatcherTest.php:76

    I think a slash is missing here (and below as well)
  13. Garvin Hicking uploaded patch set 9 V +1 09/04/24, 14:01

  14. Garvin Hicking commented on patch set 9 09/04/24, 14:01

    AbstractMethodImplementationMatcherTest.php:76 Reply

    Done
  15. core-ci voted on patch set 9 V +1 09/04/24, 14:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64766

  16. Simon Praetorius voted on patch set 9 CR +1 V +1 09/04/24, 14:13

  17. Simon Schaufelberger commented on patch set 9 09/11/24, 09:51

    AbstractMethodImplementationMatcher.php:106

    too much nesting going on here. please use early return instead
  18. Simon Schaufelberger commented on patch set 9 09/11/24, 09:53

    AbstractMethodImplementationMatcher.php:106 Reply

    in Rector we use shouldSkip method for that to combine this checks
  19. Garvin Hicking commented on patch set 9 09/11/24, 09:54

    AbstractMethodImplementationMatcher.php:106 Reply

    Thanks for checking this out. I respectfully disagree, this is in line with the way all the other matchers do that, and I'd rather have similar code than one element stand out. See typo3/sysext/install/Classes/ExtensionScanner/Php/GeneratorClassesResolver.php for example.
  20. Simon Schaufelberger commented on patch set 9 09/11/24, 09:54

    AbstractMethodImplementationMatcher.php:106 Reply

    ``` if ($this->shouldSkip($node)) { return null; } ```
  21. Garvin Hicking commented on patch set 9 09/11/24, 10:24

    AbstractMethodImplementationMatcher.php:106 Reply

    Acknowledged
  22. Garvin Hicking commented on patch set 9 09/11/24, 10:25

    AbstractMethodImplementationMatcher.php:106 Reply

    If you want, you could address this in a follow-up patch and introduce such a method consistently for all matchers? I'd like to keep this out of scope for this PR.
  23. Simon Schaufelberger commented on patch set 9 CR +1 V +1 09/11/24, 10:39

    AbstractMethodImplementationMatcher.php:106 Reply

    ok
  24. Garvin Hicking voted on patch set 9 CR +2 V +2 09/12/24, 09:04

  25. Garvin Hicking merged patch set 10 09/12/24, 09:04