Skip to content

Commit

Permalink
Fix: Do not chain if not required (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek authored Nov 13, 2023
1 parent b5c9d9f commit 59a7b05
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Internal/EtlBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use BenTools\ETL\Transformer\ChainTransformer;
use BenTools\ETL\Transformer\TransformerInterface;

use function count;

/**
* @internal
*
Expand All @@ -40,7 +42,11 @@ public function extractFrom(
}
}

return $this->cloneWith(['extractor' => new ChainExtractor(...$extractors)]);
if (count($extractors) > 1) {
return $this->cloneWith(['extractor' => new ChainExtractor(...$extractors)]);
}

return $this->cloneWith(['extractor' => $extractors[0]]);
}

public function transformWith(
Expand All @@ -55,7 +61,11 @@ public function transformWith(
}
}

return $this->cloneWith(['transformer' => new ChainTransformer(...$transformers)]);
if (count($transformers) > 1) {
return $this->cloneWith(['transformer' => new ChainTransformer(...$transformers)]);
}

return $this->cloneWith(['transformer' => $transformers[0]]);
}

public function loadInto(LoaderInterface|callable $loader, LoaderInterface|callable ...$loaders): self
Expand All @@ -68,7 +78,11 @@ public function loadInto(LoaderInterface|callable $loader, LoaderInterface|calla
}
}

return $this->cloneWith(['loader' => new ChainLoader(...$loaders)]);
if (count($loaders) > 1) {
return $this->cloneWith(['loader' => new ChainLoader(...$loaders)]);
}

return $this->cloneWith(['loader' => $loaders[0]]);
}

public function withOptions(EtlConfiguration $configuration): self
Expand Down

0 comments on commit 59a7b05

Please sign in to comment.