Review main Merged

88506[TASK] Update to PHPStan 2.1.7 with adjusted baseline

Garvin Hicking CR +2 V +2 Normal +9 −65 updated 03/06/25, 18:01

Commit message

Update to PHPStan 2.1.7, which has improved native type
inference and no longer complains about certain hinting via
`@var`. These have been reworked to be actually removed,
as the native inference is preferable.

Executed commands:

```
Build/Scripts/runTests.sh -s composer require --dev \
	phpstan/phpstan:^2.1.7
Build/Scripts/runTests.sh -s phpstanGenerateBaseline
```

Details:
-------

* typo3/sysext/backend/Classes/Preview/StandardPreviewRendererResolver.php:61

`$previewRendererClassName` is natively ensured to be a string now
(technically `$tca['ctrl']['previewRenderer']` could be set to a
non-string)

* typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.php:329

`$row` is advertised to be only `false`, but no guarantee for this.
Using an `is_array()` check here safeguards it better and can use
native inference.

* typo3/sysext/core/Tests/Unit/Context/SecurityAspectTest.php:50

Removed test altogether, now just checking for a guaranteed member
property. Was also already touched with #105741 and deemed little
helpful.

* typo3/sysext/extbase/Classes/Reflection/ClassSchema.php:356

Type-hint should be valid and can be kept.

* typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php:(106|111|121)
* typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php:(97|102|112||196|201|211)

Unsure to which it would apply, but annotations are likely valid.

* typo3/sysext/install/Classes/Configuration/FeatureManager.php:53

Due to the `instanceof` check, the type hint can be natively inferred
and be removed.

* typo3/sysext/install/Classes/Configuration/FeatureManager.php:82&116

Can be removed due to return type/return type-hint inference.

Note: Backports to 13.4 and 12.4 will be slightly different.

Review

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

Issues 2

Files 7

Review log 1619

  1. Garvin Hicking uploaded patch set 1 03/06/25, 08:20

  2. core-ci voted on patch set 1 V +1 03/06/25, 08:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/75207

  3. Oliver Klee commented on patch set 1 03/06/25, 08:49

    StandardPreviewRendererResolver.php:60

    ```suggestion if (is_string($previewRendererClassName) && $previewRendererClassName !== '') { ```
  4. Garvin Hicking commented on patch set 2 V +1 03/06/25, 08:51

    Published edit on patch set 1.
  5. Garvin Hicking commented on patch set 2 03/06/25, 08:51

    StandardPreviewRendererResolver.php:60 Reply

    Thanks, that's better :-)
  6. core-ci voted on patch set 2 V +1 03/06/25, 08:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/75208

  7. Oliver Klee voted on patch set 2 CR +1 V +1 03/06/25, 08:58

  8. Oliver Klee updated the commit message in patch set 3 CR +1 V +1 03/06/25, 08:59

  9. Oliver Klee voted on patch set 3 CR +1 V +1 03/06/25, 09:00

  10. core-ci voted on patch set 3 V +1 03/06/25, 09:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/75209

  11. Benjamin Franzke commented on patch set 3 03/06/25, 10:35

    StandardPreviewRendererResolver.php:60

    👍

    AbstractTreeView.php:329

    Imho `!is_array` is actually not needed and would would probably have been enough to remove `/** @var array $row */`, because phpstan now transform `array|false` to `array` automatically, no?
  12. Benjamin Franzke commented on patch set 3 03/06/25, 11:09

    That's not correct. It is resolved to `array|false` and narrowed down do `array` (due to the phpstan upgrade), because `false` is excluded implicitly due to the condition in `while()`.
  13. Garvin Hicking commented on patch set 3 03/06/25, 11:17

    AbstractTreeView.php:329 Reply

    I checked the getDataNext return type hint that says @return array|bool shouldnt that be bool|false instead then? I only checked until that point.
  14. Garvin Hicking commented on patch set 3 03/06/25, 11:20

    AbstractTreeView.php:329 Reply

    (my intent was to prevent "true" getting in here inside the while())
  15. Oliver Klee commented on patch set 3 03/06/25, 11:32

    AbstractTreeView.php:329 Reply

    The return type annotation for `getDataNext` should indeed be `array|false`.
  16. Benjamin Franzke commented on patch set 3 CR +1 V +1 03/06/25, 12:05

    Reply

    nvm

    AbstractTreeView.php:329 Reply

    ack, can be fixed now or later, I don't care/mind
  17. Garvin Hicking commented on patch set 3 03/06/25, 13:22

    I have adapted the 12+13 backports. It would have proven to take too much time to to move the RepositoryTest methods from unit to functionals, so I've instead gone another route to just check for a not-null object response in these two tests. Please see if this is acceptable, IMO this is better than just including it in a phpstan baseline?

    AbstractTreeView.php:329 Reply

    Thanks. Since my IDE doesn't really allow to follow `$res->fetchAssociative` to the full doctrine DBAL onion layering, I'll go the "safe" and less time-consuming route and not change the annotation to array|false, but instead use the `is_array()` gating for a possible "true" (even though unlikely), hope that's fine for everybody.
  18. Benjamin Franzke voted on patch set 3 CR +2 V +2 03/06/25, 18:01

  19. Benjamin Franzke merged patch set 4 03/06/25, 18:01