-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the ActionState class from the php-etl/action-contracts package
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Components\Action; | ||
|
||
use Kiboko\Contract\Action\StateInterface; | ||
|
||
final class ActionState implements StateInterface | ||
{ | ||
/** @var array<string, int> */ | ||
private array $metrics = [ | ||
Check failure on line 12 in src/ActionState.php GitHub Actions / phpstan
Check failure on line 12 in src/ActionState.php GitHub Actions / phpstan
|
||
'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 | ||
Check failure on line 29 in src/ActionState.php GitHub Actions / phpstan
Check failure on line 29 in src/ActionState.php GitHub Actions / phpstan
|
||
{ | ||
$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(); | ||
} | ||
} |