-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
efc9369
commit 75fbfea
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Function; | ||
|
||
use function Flow\ETL\DSL\type_string; | ||
use function Symfony\Component\String\u; | ||
use Flow\ETL\Function\ScalarFunction\TypedScalarFunction; | ||
use Flow\ETL\PHP\Type\Type; | ||
use Flow\ETL\Row; | ||
|
||
final class StringFold extends ScalarFunctionChain implements TypedScalarFunction | ||
{ | ||
public function __construct(private readonly ScalarFunction|string $string) | ||
{ | ||
} | ||
|
||
public function eval(Row $row) : mixed | ||
{ | ||
$string = (new Parameter($this->string))->asString($row); | ||
|
||
if ($string === null) { | ||
return null; | ||
} | ||
|
||
return u($string)->folded()->toString(); | ||
} | ||
|
||
public function returns() : Type | ||
{ | ||
return type_string(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringFoldTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Function; | ||
|
||
use function Flow\ETL\DSL\row; | ||
use function Flow\ETL\DSL\{ref, str_entry}; | ||
use Flow\ETL\Tests\FlowTestCase; | ||
|
||
final class StringFoldTest extends FlowTestCase | ||
{ | ||
public function test_string_folded() : void | ||
{ | ||
self::assertSame( | ||
"die o'brian strasse", | ||
ref('str')->stringFold()->eval( | ||
row(str_entry('str', "Die O'Brian Straße")) | ||
) | ||
); | ||
} | ||
} |