teknoo/states
Teknoo States provides a simple, extensible finite state machine implementation for PHP. Model objects with states and transitions, define allowed changes, and trigger callbacks on entry, exit, or transition events—useful for workflows, order processing, and status management.
switch/if ladder.Enum + match or a Laravel workflow package covers the need at zero added dependency risk, or where the domain is Eloquent-anemic and the conditional logic lives in service classes — this library does not address that.Adopt when:
AbstractStandardObject, so the persistence integration earns its keep.StateMachine/HasStates seam so domain classes never import it directly.Look elsewhere when:
match are clearer and dependency-free.debug_backtrace() visibility resolution is measurable.For executives: This is a small, focused library that implements the standard State pattern for objects whose behavior changes with their state — the kind of logic that otherwise accumulates in large, error-prone conditionals. It has one runtime dependency, a permissive BSD-3-Clause license, and pairs with our static-analysis standards, so it reduces the bug surface in complex workflows. The trade-offs are real: low community adoption (a few stars, no known dependents, effectively a single maintainer) and a hard PHP 8.4+ requirement. We should treat adoption as a narrow, deliberate bet on one or two complex domain workflows — not a platform-wide standard — and validate maintenance risk before committing further.
For engineering: You get the State pattern handled: state classes with inheritance and real method visibility, automated state switching driven by property assertions and constraints, Doctrine integration for entities/documents, and a PHPStan extension so CI understands state-dispatched calls. Quality signals are strong — strict typing, PSR-12, PHPStan at max, PHPUnit 13, and a CI that fails on any deprecation or notice. Cost of entry: the builder/closure model must be learned and documented internally, and the PHPStan extension follows PHPStan internals, so expect 2–4 bump-and-fix cycles per year and a decision on whether to run the extension unloaded by default.
Recommended next step: a time-boxed spike (two sprints) against one real roadmap workflow, behind an internal seam and with parity tests against the existing conditional path. Measure (a) whether conditional sprawl is measurably removed, (b) onboarding cost for two engineers, and (c) actual upgrade/maintenance burden. Pin versions, document the idiom locally, and decide on wider rollout only at the quarter boundary.
How can I help you explore Laravel packages today?