Merge conflict Gerrit cannot merge this change. It needs a rebase onto main.

Review main Work in progress Stale

92589[TASK] Replace unneeded instanceof on xxx|null. Use a null check instead

Simon Schaufelberger CR -2 V -1 Normal +55 −68 updated 09/02/26, 20:59

Commit message

This is a pre-patch for #108652 which will require a null check instead
of using instanceof.

The migration has been done with a custom Rector rule that can be found
in the forge issue with very few manual adjustments to simplify some
if-conditions.

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 3
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/89/92589/3 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/89/92589/3 && git cherry-pick FETCH_HEAD

Review

  • Code review CR -2 Blocked
    • Benjamin Franzke -2
  • Verified V -1 Blocked
    • core-ci -1 CI

Relation chain 2

  1. 92589 [TASK] Replace unneeded instanceof on xxx|null. Use a null check instead This change

  2. main 92349[TASK] Replace deprecated usage for custom phpstan rule and add tests This change is based on it Merge conflict Simon Schaufelberger CR 0 V -1 → 14.3 Hard +404 −1

    The chain has patch set 9 of 11, the changes above it need a rebase.

Issues 2

Files 41

Show 21 more files

Review log 1518

  1. Simon Schaufelberger uploaded patch set 1 01/30/26, 13:33

  2. core-ci voted on patch set 1 V -1 01/30/26, 13:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/94668

  3. Simon Schaufelberger uploaded patch set 2 V -1 01/30/26, 13:52

  4. core-ci voted on patch set 2 V +1 01/30/26, 13:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/94671

  5. Garvin Hicking commented on patch set 2 01/30/26, 21:43

    I must say I kind of like having it in the code to implicitly see which type is expected there. Also it could be forward compatible in case something could be an interface but we want specific type checks? This feels too broad and dangerous to me.
  6. Simon Schaufelberger commented on patch set 2 01/30/26, 22:29

    Reply

    I don't want to start any discussion here. The original phpstan rule came from https://review.typo3.org/c/Packages/TYPO3.CMS/+/80859 and in https://review.typo3.org/c/Packages/TYPO3.CMS/+/92349?tab=comments Stefan already starte a new discussion. So instead of starting a third discussion here, please comment on the one from https://review.typo3.org/c/Packages/TYPO3.CMS/+/92349?tab=comments.
  7. Garvin Hicking commented on patch set 2 01/30/26, 22:40

    Reply

    Hmkay, but why spawn multiple patches already if there's discussion? Anyways, I just dislike this specific patch here, and have not checked out the others ones. Will try to see what's up.
  8. Simon Schaufelberger commented on patch set 2 01/30/26, 23:22

    Reply

    This is just the change that stefan requested in the phpstan rule and that would result in the change of these files here, that's why it's a pre-patch.
  9. Garvin Hicking commented on patch set 2 CR -1 01/31/26, 10:02

    checking

    Reply Unresolved

    Thanks, I see. Let me go through each instance, I have the feeling there are several that are really 100% perfectly fine, but spotted a few where I want to check the incoming data if it might be possible to come from consumer PSR-Events/Hooks or from files without strict types.
  10. Garvin Hicking commented on patch set 2 01/31/26, 10:16

    SiteConfigurationController.php:553 Unresolved

    this is a place I still find helpful/userful, since it's not strictly type safe and only deduced from a type hint, not a type declaration. $allSites comes from SiteConfigurationController->saveAction and there from siteConfiguration->resolveAllExistingSitesRaw(). Now this is hyperbole theoretical, but if at some point we introduce a PSR-event to manipulate the array or even some new Object that is not a Site but something else, we'll have to chew through all places where distinctions need to be made. IMO it would then help to have (at least a few) instances of "instanceof Site" checks that would directly hint me at this. So my thought is, at places where we have arrays or just PHPdoc typehints, we should not remove this instanceof.

    SiteConfigurationController.php:571 Unresolved

    same here
  11. Garvin Hicking commented on patch set 2 01/31/26, 12:30

    UploadDeleteCheckboxViewHelper.php:69 Unresolved

    Not safe here

    HtmlViewHelper.php:84 Unresolved

    If I read this correctly the enforced return type is only "object" and it's not safe we'll have a ServerRequestInterface? Needs thorough checking.

    FormRuntime.php:399 Unresolved

    Only type hinted, not safe

    FileDeclaration.php:123 Unresolved

    This is only type-hinted and not type declared, I'd leave it out
  12. Garvin Hicking commented on patch set 2 01/31/26, 13:55

    Reply

    done with my inspections, see comments.

    DefaultTcaSchema.php:839 Unresolved

    unsure due to array, needs investigation

    Icon.php:241

    Only type-hinted, maybe not safe

    ImageProcessingInstructions.php:54 Unresolved

    I think in the past working here I've come across cases where this was a stdObject. Needs thorough investigation.

    ImageProcessingInstructions.php:134 Unresolved

    same

    TcaSchema.php:261 Unresolved

    needs safe investigation due to array, I would leave it

    Typo3DbQueryParser.php:133 Unresolved

    only type-hinted, not type-safe
  13. Benjamin Franzke commented on patch set 2 CR -2 04/02/26, 11:31

    Icon.php:241 Reply

    Ack and Thanks! It is important we do not trust doctypes here. You mentioned this in a lot of cases, which brings me to the following question: Why are all these changes applied by that rector rule at all @simonschaufi+typo3@gmail.com? I've explicitly and on purpose disabled treating doctypes as certain when I introduced this phpstan rule in: > 80859: [TASK] Add phpstan check for unneeded pseudo uncertain instanceof usage | https://review.typo3.org/c/Packages/TYPO3.CMS/+/80859 See https://review.typo3.org/c/Packages/TYPO3.CMS/+/80859/4/Build/phpstan/phpstan.neon#14 We should *only* "prepare" to fix cases than are *actually* found by (whatever) improvement we apply to that rule. That means I'm against applying changes because of rector results. Please only include changes in here that will be marked as invalid with https://forge.typo3.org/issues/108652 Also: To be able to review this change, that referenced change needs to be ready. (relation chain seems swapped and not up to date) Applying -2 here, not because I want to block anything, but because this is really important to avoid introducing hard-to-trace regressions. Ping me in Slack if I miss to respond to changes, please.
  14. Benni Mack updated the commit message in patch set 3 CR -1 V +1 04/22/26, 06:45

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  15. core-ci voted on patch set 3 V -1 04/22/26, 11:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100783

  16. Benni Mack commented on patch set 3 09/02/26, 19:44

    Icon.php:241 Reply

    I don't know the current state here, but I suggest to either abandon this change or put this change into WIP for the time being
  17. Simon Schaufelberger commented on patch set 3 09/02/26, 20:59

    Icon.php:241 Reply Unresolved

    As mentioned in the commit message, this is a pre-patch and shows what must be changed for the phpstan rule change. I'll mark this as WIP as I still need to talk with Stefan Bürk about this change.
  18. Simon Schaufelberger marked it work in progress 09/02/26, 20:59