From 5d1807d3ddb28befa27ed448c96c6d1525af9483 Mon Sep 17 00:00:00 2001 From: Beno!t POLASZEK Date: Wed, 8 Nov 2023 09:19:03 +0100 Subject: [PATCH] refactor: rename recipe main method --- src/Internal/EtlBuilderTrait.php | 2 +- src/Recipe/LoggerRecipe.php | 2 +- src/Recipe/Recipe.php | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Internal/EtlBuilderTrait.php b/src/Internal/EtlBuilderTrait.php index 83f3bdb..29e1ab8 100644 --- a/src/Internal/EtlBuilderTrait.php +++ b/src/Internal/EtlBuilderTrait.php @@ -63,6 +63,6 @@ public function withRecipe(Recipe|callable $recipe): self $recipe = Recipe::fromCallable($recipe); } - return $recipe->fork($this); + return $recipe->decorate($this); } } diff --git a/src/Recipe/LoggerRecipe.php b/src/Recipe/LoggerRecipe.php index 973db4a..a8f0c14 100644 --- a/src/Recipe/LoggerRecipe.php +++ b/src/Recipe/LoggerRecipe.php @@ -48,7 +48,7 @@ public function __construct( ) { } - public function fork(EtlExecutor $executor): EtlExecutor + public function decorate(EtlExecutor $executor): EtlExecutor { return $executor ->onInit(fn (InitEvent $event) => $this->log($event, 'Initializing ETL...', ['state' => $event->state]), diff --git a/src/Recipe/Recipe.php b/src/Recipe/Recipe.php index 7fb44e7..ec45ecb 100644 --- a/src/Recipe/Recipe.php +++ b/src/Recipe/Recipe.php @@ -9,17 +9,17 @@ abstract class Recipe { - abstract public function fork(EtlExecutor $executor): EtlExecutor; + abstract public function decorate(EtlExecutor $executor): EtlExecutor; - public static function fromCallable(callable $recipe): self + final public static function fromCallable(callable $recipe): self { - return new class(Closure::fromCallable($recipe)) extends Recipe { + return new class($recipe(...)) extends Recipe { public function __construct( - private Closure $recipe, + private readonly Closure $recipe, ) { } - public function fork(EtlExecutor $executor): EtlExecutor + public function decorate(EtlExecutor $executor): EtlExecutor { return ($this->recipe)($executor); }