From 75fbfea5a6b1b8ea63cbdae65a4e7654a3655152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=81api=C5=84ski?= <143662975+f-lapinski@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:56:36 +0100 Subject: [PATCH] feat: create Folded Scalar function with Test (#1449) * feat: create Folded Scalar function with Test * Add Folded ScalarFunction * Remove from DSL and fix to ScalarFunctionChain --- .../Flow/ETL/Function/ScalarFunctionChain.php | 5 +++ .../etl/src/Flow/ETL/Function/StringFold.php | 34 +++++++++++++++++++ .../Tests/Unit/Function/StringFoldTest.php | 22 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/core/etl/src/Flow/ETL/Function/StringFold.php create mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringFoldTest.php diff --git a/src/core/etl/src/Flow/ETL/Function/ScalarFunctionChain.php b/src/core/etl/src/Flow/ETL/Function/ScalarFunctionChain.php index f54f170ae..7bfa8831f 100644 --- a/src/core/etl/src/Flow/ETL/Function/ScalarFunctionChain.php +++ b/src/core/etl/src/Flow/ETL/Function/ScalarFunctionChain.php @@ -471,6 +471,11 @@ public function startsWith(ScalarFunction|string $needle) : self return new StartsWith($this, $needle); } + public function stringFold() : self + { + return new StringFold($this); + } + public function strPad(int $length, string $pad_string = ' ', int $type = STR_PAD_RIGHT) : self { return new StrPad($this, $length, $pad_string, $type); diff --git a/src/core/etl/src/Flow/ETL/Function/StringFold.php b/src/core/etl/src/Flow/ETL/Function/StringFold.php new file mode 100644 index 000000000..6be7dcfc5 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/Function/StringFold.php @@ -0,0 +1,34 @@ +string))->asString($row); + + if ($string === null) { + return null; + } + + return u($string)->folded()->toString(); + } + + public function returns() : Type + { + return type_string(); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringFoldTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringFoldTest.php new file mode 100644 index 000000000..5721d611a --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringFoldTest.php @@ -0,0 +1,22 @@ +stringFold()->eval( + row(str_entry('str', "Die O'Brian Straße")) + ) + ); + } +}