From af6bfafebed297745d33cec1dad3ebcf156bc3b7 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Fri, 6 Oct 2023 11:44:18 +0200 Subject: [PATCH] Remove `ArraySortTransformer` --- src/core/etl/README.md | 1 - src/core/etl/src/Flow/ETL/DSL/Transform.php | 5 -- .../ETL/Transformer/ArraySortTransformer.php | 63 ----------------- .../Transformer/ArraySortTransformerTest.php | 69 ------------------- 4 files changed, 138 deletions(-) delete mode 100644 src/core/etl/src/Flow/ETL/Transformer/ArraySortTransformer.php delete mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ArraySortTransformerTest.php diff --git a/src/core/etl/README.md b/src/core/etl/README.md index 6a3620247..9c3782e7f 100644 --- a/src/core/etl/README.md +++ b/src/core/etl/README.md @@ -219,7 +219,6 @@ Adapters might also define some custom transformers. * [static entry](src/Flow/ETL/Transformer/StaticEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/StaticEntryTransformerTest.php) * **Array** * [array keys style converter](src/Flow/ETL/Transformer/ArrayKeysStyleConverterTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/ArrayKeysStyleConverterTransformerTest.php) - * [array sort](src/Flow/ETL/Transformer/ArraySortTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/ArraySortTransformerTest.php) * **Callback** - *Might come with performance degradation* * [callback row](src/Flow/ETL/Transformer/CallbackRowTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/CallbackRowTransformerTest.php) diff --git a/src/core/etl/src/Flow/ETL/DSL/Transform.php b/src/core/etl/src/Flow/ETL/DSL/Transform.php index d45584c2a..38242abd7 100644 --- a/src/core/etl/src/Flow/ETL/DSL/Transform.php +++ b/src/core/etl/src/Flow/ETL/DSL/Transform.php @@ -64,11 +64,6 @@ final public static function array_convert_keys(string $array_column, string $st ); } - final public static function array_sort(string $array_name, int $sort_flag = \SORT_REGULAR) : Transformer - { - return new Transformer\ArraySortTransformer($array_name, $sort_flag); - } - /** * @param callable(Row) : Row $callable */ diff --git a/src/core/etl/src/Flow/ETL/Transformer/ArraySortTransformer.php b/src/core/etl/src/Flow/ETL/Transformer/ArraySortTransformer.php deleted file mode 100644 index 95b5cea77..000000000 --- a/src/core/etl/src/Flow/ETL/Transformer/ArraySortTransformer.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -final class ArraySortTransformer implements Transformer -{ - public function __construct( - private readonly string $arrayEntryName, - private readonly int $sortingFlag = \SORT_REGULAR - ) { - } - - public function __serialize() : array - { - return [ - 'array_entry_name' => $this->arrayEntryName, - 'sorting_flag' => $this->sortingFlag, - ]; - } - - public function __unserialize(array $data) : void - { - $this->arrayEntryName = $data['array_entry_name']; - $this->sortingFlag = $data['sorting_flag']; - } - - public function transform(Rows $rows, FlowContext $context) : Rows - { - $transformer = function (Row $row) : Row { - if (!$row->entries()->has($this->arrayEntryName)) { - throw new RuntimeException("\"{$this->arrayEntryName}\" not found"); - } - - if (!$row->entries()->get($this->arrayEntryName) instanceof Row\Entry\ArrayEntry) { - throw new RuntimeException("\"{$this->arrayEntryName}\" is not ArrayEntry"); - } - - $arrayEntry = $row->get($this->arrayEntryName); - - /** @var array $array */ - $array = $arrayEntry->value(); - \sort($array, $this->sortingFlag); - - return $row->set(new Row\Entry\ArrayEntry( - $arrayEntry->name(), - $array - )); - }; - - return $rows->map($transformer); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ArraySortTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ArraySortTransformerTest.php deleted file mode 100644 index 04f03db13..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ArraySortTransformerTest.php +++ /dev/null @@ -1,69 +0,0 @@ -assertEquals( - [ - [ - 'array' => [ - new \DateTimeImmutable('2020-01-01 00:00:00 UTC'), - new \DateTimeImmutable('2020-01-01 12:00:00 UTC'), - new \DateTimeImmutable('2020-01-03 00:00:00 UTC'), - new \DateTimeImmutable('2020-01-10 00:00:00 UTC'), - ], - ], - ], - $transformer->transform(new Rows(Row::create($arrayEntry)), new FlowContext(Config::default()))->toArray() - ); - } - - public function test_sort_integer_array_entries() : void - { - $arrayEntry = new ArrayEntry( - 'array', - [ - 5, - 3, - 10, - 4, - ] - ); - - $transformer = Transform::array_sort('array'); - - $this->assertSame( - [ - [ - 'array' => [3, 4, 5, 10], - ], - ], - $transformer->transform(new Rows(Row::create($arrayEntry)), new FlowContext(Config::default()))->toArray() - ); - } -}