Skip to content

Commit

Permalink
Moved the ActionState class from the php-etl/action-contracts package
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Nov 15, 2023
1 parent 293359d commit 6a95147
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/ActionState.php
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

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Components\Action\ActionState::$metrics (array<string, int>) does not accept default value of type array<string, false>.

Check failure on line 12 in src/ActionState.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Components\Action\ActionState::$metrics (array<string, int>) does not accept default value of type array<string, false>.

Check failure on line 12 in src/ActionState.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Kiboko\Components\Action\ActionState::$metrics (array<string, int>) does not accept default value of type array<string, false>.
'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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Components\Action\ActionState::success() overrides method Kiboko\Contract\Action\StateInterface::success() but misses parameter #1 $step.

Check failure on line 29 in src/ActionState.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Components\Action\ActionState::success() overrides method Kiboko\Contract\Action\StateInterface::success() but misses parameter #1 $step.

Check failure on line 29 in src/ActionState.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Components\Action\ActionState::success() overrides method Kiboko\Contract\Action\StateInterface::success() but misses parameter #1 $step.
{
$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();
}
}

0 comments on commit 6a95147

Please sign in to comment.