Skip to content

Commit

Permalink
Simplify RenameEntriesTransformer to work only on one entry
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Oct 5, 2023
1 parent 664d699 commit f342bd5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 92 deletions.
5 changes: 2 additions & 3 deletions src/core/etl/src/Flow/ETL/DSL/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
use Flow\ETL\Transformer;
use Flow\ETL\Transformer\ArrayKeysStyleConverterTransformer;
use Flow\ETL\Transformer\KeepEntriesTransformer;
use Flow\ETL\Transformer\Rename\EntryRename;
use Flow\ETL\Transformer\RenameEntriesTransformer;
use Flow\ETL\Transformer\RenameEntryTransformer;
use Flow\ETL\Transformer\StyleConverter\StringStyles;

/**
Expand Down Expand Up @@ -149,7 +148,7 @@ final public static function remove(string|Reference ...$entry) : Transformer

final public static function rename(string $from, string $to) : Transformer
{
return new RenameEntriesTransformer(new EntryRename($from, $to));
return new RenameEntryTransformer($from, $to);
}

public static function rename_all_case(bool $upper = false, bool $lower = false, bool $ucfirst = false, bool $ucwords = false) : Transformer
Expand Down
41 changes: 0 additions & 41 deletions src/core/etl/src/Flow/ETL/Transformer/Rename/EntryRename.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/core/etl/src/Flow/ETL/Transformer/RenameEntriesTransformer.php

This file was deleted.

39 changes: 39 additions & 0 deletions src/core/etl/src/Flow/ETL/Transformer/RenameEntryTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Flow\ETL\Transformer;

use Flow\ETL\FlowContext;
use Flow\ETL\Row;
use Flow\ETL\Rows;
use Flow\ETL\Transformer;

/**
* @implements Transformer<array{from: string, to: string}>
*/
final class RenameEntryTransformer implements Transformer
{
public function __construct(private readonly string $from, private readonly string $to)
{
}

public function __serialize() : array
{
return [
'from' => $this->from,
'to' => $this->to,
];
}

public function __unserialize(array $data) : void
{
$this->from = $data['from'];
$this->to = $data['to'];
}

public function transform(Rows $rows, FlowContext $context) : Rows
{
return $rows->map(fn (Row $row) : Row => $row->rename($this->from, $this->to));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Flow\ETL\Rows;
use PHPUnit\Framework\TestCase;

final class RenameEntriesTransformerTest extends TestCase
final class RenameEntryTransformerTest extends TestCase
{
public function test_renaming_entries() : void
{
Expand Down

0 comments on commit f342bd5

Please sign in to comment.