diff --git a/src/ActionState.php b/src/ActionState.php new file mode 100644 index 0000000..059d3a0 --- /dev/null +++ b/src/ActionState.php @@ -0,0 +1,55 @@ + */ + private array $metrics = [ + 'started' => false, + 'success' => false, + 'failure' => false, + ]; + + public function __construct( + private readonly StateInterface $decorated, + ) { + } + + public function initialize(): void + { + $this->metrics['started'] = true; + $this->decorated->initialize(); + } + + public function success(): void + { + $this->metrics['success'] = true; + $this->decorated->success(); + } + + public function failure(int $step = 1): void + { + $this->metrics['failure'] = true; + $this->decorated->failure(); + } + + public function observeAccept(): callable + { + return fn () => $this->metrics['success']; + } + + public function observeReject(): callable + { + return fn () => $this->metrics['failure']; + } + + public function teardown(): void + { + $this->decorated->teardown(); + } +}