Skip to content

Commit

Permalink
Merge pull request #1 from php-etl/feature/actions
Browse files Browse the repository at this point in the history
Added actions state management
  • Loading branch information
gplanchat authored Apr 19, 2023
2 parents 830d3f5 + 79354df commit 2f6de75
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan-5.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHPStan level 6
name: PHPStan level 5
on: push
jobs:
phpstan:
Expand Down
140 changes: 98 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions src/StateOutput/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\State\StateOutput;

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;

final class Action
{
/** @var array<string, callable> */
private array $metrics = [];
private readonly ConsoleSectionOutput $section;

public function __construct(
private readonly ConsoleOutput $output,
string $index,
string $label,
) {
$this->section = $this->output->section();
$this->section->writeln('');
$this->section->writeln(sprintf('<fg=green> % 2s. %-50s</>', $index, $label));
}

public function addMetric(string $label, callable $callback): self
{
$this->metrics[$label] = $callback;

return $this;
}

public function update(): void
{
$this->section
->writeln(' '.implode(', ', array_map(
fn (string $label, callable $callback) => sprintf('%s <fg=cyan>%d</>', $label, ($callback)()),
array_keys($this->metrics),
array_values($this->metrics),
)))
;
}
}
Loading

0 comments on commit 2f6de75

Please sign in to comment.