Skip to content

Commit

Permalink
Deprecating the Pipeline class from this package
Browse files Browse the repository at this point in the history
This package will disappear
  • Loading branch information
gplanchat committed Nov 21, 2023
1 parent 97869c4 commit 5e72978
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 120 deletions.
58 changes: 5 additions & 53 deletions src/MemoryState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,10 @@

namespace Kiboko\Component\State;

use Kiboko\Contract\Pipeline\StateInterface;
trigger_deprecation('php-etl/console-state', '0.3', 'The "%s" class is deprecated, use "%s" instead.', 'Kiboko\\Component\\State\\MemoryState', 'Kiboko\\Component\\Runtime\\Pipeline\\Step\\MemoryState');

final class MemoryState implements StateInterface
{
private array $metrics = [];
/*
* @deprecated since Satellite 0.2, use Kiboko\Component\Runtime\Pipeline\Step\MemoryState instead.
*/
class_alias('Kiboko\\Component\\Runtime\\Pipeline\\Step\\MemoryState', 'Kiboko\\Component\\State\\MemoryState');

public function __construct(
private readonly ?StateInterface $decorated = null,
) {
}

public function initialize(int $start = 0): void
{
$this->metrics = [
'accept' => 0,
'reject' => 0,
'error' => 0,
];

$this->decorated?->initialize($start);
}

public function accept(int $step = 1): void
{
$this->metrics['accept'] += $step;
$this->decorated?->accept($step);
}

public function reject(int $step = 1): void
{
$this->metrics['reject'] += $step;
$this->decorated?->reject($step);
}

public function error(int $step = 1): void
{
$this->metrics['error'] += $step;
$this->decorated?->error($step);
}

public function observeAccept(): callable
{
return fn () => $this->metrics['accept'];
}

public function observeReject(): callable
{
return fn () => $this->metrics['reject'];
}

public function teardown(): void
{
$this->decorated?->teardown();
}
}
35 changes: 5 additions & 30 deletions src/StateOutput/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,9 @@

namespace Kiboko\Component\State\StateOutput;

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
trigger_deprecation('php-etl/console-state', '0.3', 'The "%s" class is deprecated, use "%s" instead.', 'Kiboko\\Component\\State\\StateOutput\\Pipeline', \Kiboko\Component\Runtime\Pipeline\Pipeline::class);

Check failure on line 7 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 7 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 7 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 7 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 7 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

final class Pipeline
{
/** @var list<PipelineStep> */
private array $steps = [];
private readonly ConsoleSectionOutput $section;

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

public function withStep(string $label): PipelineStep
{
return $this->steps[] = new PipelineStep($this->output, \count($this->steps) + 1, $label);
}

public function update(): void
{
foreach ($this->steps as $step) {
$step->update();
}
}
}
/*
* @deprecated since Satellite 0.2, use Kiboko\Component\Runtime\Pipeline\Pipeline instead.
*/
class_alias(\Kiboko\Component\Runtime\Pipeline\Pipeline::class, 'Kiboko\\Component\\State\\StateOutput\\Pipeline');

Check failure on line 12 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 12 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 12 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 12 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.

Check failure on line 12 in src/StateOutput/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Pipeline not found.
42 changes: 5 additions & 37 deletions src/StateOutput/PipelineStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,9 @@

namespace Kiboko\Component\State\StateOutput;

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
trigger_deprecation('php-etl/console-state', '0.3', 'The "%s" class is deprecated, use "%s" instead.', 'Kiboko\\Component\\State\\StateOutput\\Pipeline', \Kiboko\Component\Runtime\Pipeline\Step\Step::class);

Check failure on line 7 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 7 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 7 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 7 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 7 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

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

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

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

return $this;
}

public function update(): void
{
$this->section->clear(1);
$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),
)))
;
}
}
/*
* @deprecated since Satellite 0.2, use Kiboko\Component\Runtime\Pipeline\Step\Step instead.
*/
class_alias(\Kiboko\Component\Runtime\Pipeline\Step\Step::class, 'Kiboko\\Component\\State\\StateOutput\\Pipeline');

Check failure on line 12 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 12 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 12 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 12 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

Check failure on line 12 in src/StateOutput/PipelineStep.php

View workflow job for this annotation

GitHub Actions / phpstan

Class Kiboko\Component\Runtime\Pipeline\Step\Step not found.

0 comments on commit 5e72978

Please sign in to comment.