Skip to content

Commit 2f6de75

Browse files
authored
Merge pull request #1 from php-etl/feature/actions
Added actions state management
2 parents 830d3f5 + 79354df commit 2f6de75

File tree

4 files changed

+152
-48
lines changed

4 files changed

+152
-48
lines changed

.github/workflows/phpstan-5.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHPStan level 6
1+
name: PHPStan level 5
22
on: push
33
jobs:
44
phpstan:

composer.lock

Lines changed: 98 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/StateOutput/Action.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\State\StateOutput;
6+
7+
use Symfony\Component\Console\Output\ConsoleOutput;
8+
use Symfony\Component\Console\Output\ConsoleSectionOutput;
9+
10+
final class Action
11+
{
12+
/** @var array<string, callable> */
13+
private array $metrics = [];
14+
private readonly ConsoleSectionOutput $section;
15+
16+
public function __construct(
17+
private readonly ConsoleOutput $output,
18+
string $index,
19+
string $label,
20+
) {
21+
$this->section = $this->output->section();
22+
$this->section->writeln('');
23+
$this->section->writeln(sprintf('<fg=green> % 2s. %-50s</>', $index, $label));
24+
}
25+
26+
public function addMetric(string $label, callable $callback): self
27+
{
28+
$this->metrics[$label] = $callback;
29+
30+
return $this;
31+
}
32+
33+
public function update(): void
34+
{
35+
$this->section
36+
->writeln(' '.implode(', ', array_map(
37+
fn (string $label, callable $callback) => sprintf('%s <fg=cyan>%d</>', $label, ($callback)()),
38+
array_keys($this->metrics),
39+
array_values($this->metrics),
40+
)))
41+
;
42+
}
43+
}

0 commit comments

Comments
 (0)