event-sourcing-phpstan-extension

A PHPStan extension for the patchlevel/event-sourcing library. It teaches PHPStan how aggregates work so that static analysis stays accurate on event sourced code, and it catches a common mistake before it ever reaches runtime.

Features

  • Property initialization for aggregate roots and child aggregates, so PHPStan does not report false uninitialized property errors.
  • Recording in apply methods is reported as an error, because recording events while replaying them leads to duplicated events.

Installation

composer require --dev patchlevel/event-sourcing-phpstan-extension

Register the extension in your phpstan.neon:

includes:
    - vendor/patchlevel/event-sourcing-phpstan-extension/extension.neon

That is all the configuration the extension needs. Both rules are active as soon as the file is included.

Integration

New to the extension? The getting started guide walks you through enabling it and seeing both rules in action.