This document describes breaking changes introduced in version 3.0 and how to update your code.
- PHP 8.2+ (previously PHP 5.3+)
- PHPUnit 11 for development/testing (previously PHPUnit ^8.5)
Every method in MetaborStd now has full PHP native type declarations (parameter types and return types). If you implement these interfaces, you must update your method signatures accordingly.
// Before
public function __invoke();
// After
public function __invoke(mixed ...$args): mixed;// Before
public function getName();
// After
public function getName(): string;// Before
public function add(NamedInterface $named);
public function has($name);
public function get($name);
public function getNames();
// After
public function add(NamedInterface $named): void;
public function has(string $name): bool;
public function get(string $name): NamedInterface;
public function getNames(): array;// Before
public function toArray();
// After
public function toArray(): array;// Before
public function getMetadata();
// After
public function getMetadata(): array;// Before
public function checkCondition($subject, \ArrayAccess $context);
// After
public function checkCondition(object $subject, \ArrayAccess $context): bool;The $subject parameter is now typed as object (previously untyped).
// Before
public function getTargetState();
public function isActive($subject, \ArrayAccess $context, $event = null);
public function getEventName();
public function getConditionName();
// After
public function getTargetState(): StateInterface;
public function isActive(object $subject, \ArrayAccess $context, ?EventInterface $event = null): bool;
public function getEventName(): ?string;
public function getConditionName(): ?string;// Before
public function getEventNames();
public function getEvent($name);
public function hasEvent($name);
public function getTransitions();
// After
public function getEventNames(): \Traversable|array;
public function getEvent(string $name): EventInterface;
public function hasEvent(string $name): bool;
public function getTransitions(): \Traversable;// Before
public function getStates();
public function getState($name);
public function hasState($name);
// After
public function getStates(): \Traversable;
public function getState(string $name): StateInterface;
public function hasState(string $name): bool;// Before
public function getCurrentState();
public function triggerEvent($name, \ArrayAccess $context = null);
public function checkTransitions(\ArrayAccess $context = null);
public function getSubject();
// After
public function getCurrentState(): StateInterface;
public function triggerEvent(string $name, ?\ArrayAccess $context = null): void;
public function checkTransitions(?\ArrayAccess $context = null): void;
public function getSubject(): object;// Before
public function getCurrentStateName();
public function setCurrentStateName($stateName);
// After
public function getCurrentStateName(): string;
public function setCurrentStateName(string $stateName): void;// Before
public function detectCurrentStateName($subject);
// After
public function detectCurrentStateName(object $subject): ?string;Note: Return type is now ?string (nullable) to accommodate implementations that cannot determine the state name.
// Before
public function dispatch(EventInterface $event, array $arguments = array(), CallbackInterface $onReadyCallback = null);
public function isReady();
// After
public function dispatch(EventInterface $event, array $arguments = [], ?CallbackInterface $onReadyCallback = null): void;
public function isReady(): bool;// Before
public function getInitialState();
// After
public function getInitialState(): StateInterface;// Before
public function createStatemachine($subject);
// After
public function createStatemachine(object $subject): StatemachineInterface;// Before
public function detectProcess($subject);
// After
public function detectProcess(object $subject): ProcessInterface;// Before
public function getWeight(); // @return double
// After
public function getWeight(): float;// Before
public function getDate(); // returned \DateTime
// After
public function getDate(): \DateTimeInterface;
public function getLastStateHasChangedDate(): \DateTimeInterface;Return type changed from \DateTime to \DateTimeInterface to allow both \DateTime and \DateTimeImmutable.
// Before
public function __invoke()
{
$args = func_get_args();
return call_user_func_array($this->callable, $args);
}
// After
public function __invoke(mixed ...$args): mixed
{
return ($this->callable)(...$args);
}// Before
public function __invoke()
{
$args = func_get_args();
foreach ($this->callbacks as $callback) {
call_user_func_array($callback, $args);
}
}
// After
public function __invoke(mixed ...$args): mixed
{
foreach ($this->callbacks as $callback) {
$callback(...$args);
}
return null;
}The base Command class now has a concrete __invoke() that throws a \RuntimeException if not overridden. Subclasses must implement __invoke() to provide actual behavior.
// Before: abstract class, you had to declare __invoke abstract in subclass
abstract class MyCommand extends Command
{
public function __invoke(): void
{
// your logic
}
}
// After: same pattern still works, but the base class now has a default throwing implementation
abstract class MyCommand extends Command
{
public function __invoke(mixed ...$args): void
{
// your logic
}
}-
Update
composer.jsonto require PHP 8.2 and the new package version:{ "require": { "php": ">=8.2", "metabor/statemachine": "~3.0" } } -
Add return types to all methods implementing
MetaborStdinterfaces. Your IDE or a static analysis tool like PHPStan will show you all affected locations. -
Update
$subjecttype hints from untyped ormixedtoobjectin all classes implementingConditionInterface,FactoryInterface,ProcessDetectorInterface, andStateNameDetectorInterface. -
Update
\DateTimeto\DateTimeInterfacein any code returning dates fromTimeBasedInterfaceorLastStateHasChangedDateInterfaceimplementations. -
Update custom
Commandsubclasses to use the variadicmixed ...$argssignature for__invoke(). -
Run your test suite to verify compatibility:
composer update php vendor/bin/phpunit