Skip to content

Commit

Permalink
No need to pass key in transformer.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek committed Feb 19, 2018
1 parent 56216ac commit 2658fed
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/Etl.php
Expand Up @@ -230,7 +230,7 @@ public function execute($input): void

// Transform data
try {
$value = $transformer->transform($key, $value);
$value = $transformer->transform($value);
$this->dispatch(self::ON_TRANSFORM, $key, $value, $this);
} catch (\Throwable $exception) {
$exception = new TransformException($exception, $key, $value);
Expand Down
1 change: 0 additions & 1 deletion src/Loader/LoaderInterface.php
Expand Up @@ -8,7 +8,6 @@ interface LoaderInterface
/**
* Load or pre-load elements.
*
* @param $key
* @param $value
*/
public function load($key, $value): void;
Expand Down
4 changes: 2 additions & 2 deletions src/Transformer/CallableTransformer.php
Expand Up @@ -20,9 +20,9 @@ public function __construct(callable $callable)
/**
* @inheritDoc
*/
public function transform($key, $value)
public function transform($value)
{
$call = $this->callable;
return $call($key, $value);
return $call($value);
}
}
29 changes: 0 additions & 29 deletions src/Transformer/CallableValueTransformer.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Transformer/NullTransformer.php
Expand Up @@ -7,7 +7,7 @@ class NullTransformer implements TransformerInterface
/**
* @inheritDoc
*/
public function transform($key, $value)
public function transform($value)
{
return $value;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Transformer/TransformerInterface.php
Expand Up @@ -8,9 +8,8 @@ interface TransformerInterface
/**
* Transform $value.
*
* @param $key
* @param $value
* @return mixed - The transformed value
*/
public function transform($key, $value);
public function transform($value);
}
4 changes: 2 additions & 2 deletions tests/src/EtlTest.php
Expand Up @@ -4,7 +4,7 @@

use BenTools\ETL\Etl;
use BenTools\ETL\Loader\ArrayLoader;
use BenTools\ETL\Transformer\CallableValueTransformer;
use BenTools\ETL\Transformer\CallableTransformer;
use PHPUnit\Framework\TestCase;

class EtlTest extends TestCase
Expand All @@ -15,7 +15,7 @@ public function testEtl()
$loader = new ArrayLoader();
$etl = Etl::create()
->withLoader($loader)
->withTransformer(new CallableValueTransformer('strtoupper'))
->withTransformer(new CallableTransformer('strtoupper'))
;
$data = [
'foo',
Expand Down
15 changes: 4 additions & 11 deletions tests/src/Transformer/CallableTransformerTest.php
Expand Up @@ -10,17 +10,10 @@ class CallableTransformerTest extends TestCase

public function testTransform()
{

$items = ['123e4567-e89b-12d3-a456-426655440000' => 'CAPS ARE HELL'];
$transform = new CallableTransformer(function ($key, &$value) {
return strtolower($value);
});

foreach ($items as $key => $item) {
$item = $transform->transform($key, $item);
$this->assertSame('123e4567-e89b-12d3-a456-426655440000', $key);
$this->assertSame('caps are hell', $item);
}
$item = 'CAPS ARE HELL';
$transform = new CallableTransformer('strtolower');
$item = $transform->transform($item);
$this->assertSame('caps are hell', $item);

}
}
25 changes: 0 additions & 25 deletions tests/src/Transformer/CallableValueTransformerTest.php

This file was deleted.

0 comments on commit 2658fed

Please sign in to comment.