Skip to content

Skip parameters with unresolved, test-only or conflicting evidence; nullable entity setters - #58

Merged
TomasVotruba merged 1 commit into
mainfrom
safer-call-site-types
Nov 15, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
safer-call-site-types

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Running on Mautic 8.x added 862 types, and CI broke badly: 1050 PHPUnit errors and 318 PHPStan errors. Literal call sites alone are not enough evidence. Variables passed null, the DI container and forms called methods argtyper never saw, and child classes overrode newly typed methods.

Now a parameter stays untyped when:

  • any call site passes an unresolved value (a variable)
  • a call on an unresolved receiver ($x->m(), parent::m()) passes another type - these are now recorded by method name only
  • its only call sites are in tests (test/tests dirs) - e.g. a service constructor that tests feed 'id', while the container passes null
  • its default value has another type - int $code = '200' was a fatal error
  • its @param doc type is wider (bool|Exception, object)
  • the body checks it with instanceof or === false

Methods are skipped when:

  • a parent's trait declares them - FOS ControllerTrait::view() broke 36 API controllers
  • a child class, an anonymous class or an implementation overrides them - this fixes PHPStan's "Removing parent param type is forbidden"

Two more changes:

  • a call on a child class ($this->m() where a parent declares m) now counts for the parent method
  • setters (set*) of Doctrine entities, found by #[ORM\Entity] or @ORM\Entity, always get a nullable type, since forms and hydrators may pass null

On Mautic 8.x this goes from 862 to 174 types. Every class loads, and PHPStan reports nothing but stale baseline entries.

…ullable entity setters

Typing from literal call sites alone broke Mautic at runtime: variables passed
null, the DI container and forms called methods argtyper never saw, and child
classes overrode the newly typed methods.

- an unresolved argument (a variable) blocks the parameter
- calls on an unresolved receiver count by method name and must agree
- a call on a child class counts for the parent method it inherits
- call sites only in tests do not add a type
- a default value of another type blocks the parameter
- a wider @PARAM doc type, instanceof or === false in the body block it
- trait methods count as ancestors, and methods a child class, anonymous
  class or implementation overrides are skipped
- setters of Doctrine entities always get a nullable type
@TomasVotruba
TomasVotruba merged commit e64e941 into main Nov 15, 2026
4 checks passed
@TomasVotruba
TomasVotruba deleted the safer-call-site-types branch November 15, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant