-
-
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.
Merge branch '1.x' into integration/symfony-indexof
- Loading branch information
Showing
5 changed files
with
84 additions
and
21 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
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_boolean}; | ||
use function Symfony\Component\String\{b}; | ||
use Flow\ETL\Function\ScalarFunction\TypedScalarFunction; | ||
use Flow\ETL\PHP\Type\Type; | ||
use Flow\ETL\Row; | ||
|
||
final class IsUtf8 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 b($string)->isUtf8(); | ||
} | ||
|
||
public function returns() : Type | ||
{ | ||
return type_boolean(); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/core/etl/tests/Flow/ETL/Tests/Unit/Function/IsUtf8Test.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,39 @@ | ||
<?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, type_boolean}; | ||
use Flow\ETL\Function\IsUtf8; | ||
use Flow\ETL\PHP\Type\Type; | ||
use Flow\ETL\Tests\FlowTestCase; | ||
|
||
final class IsUtf8Test extends FlowTestCase | ||
{ | ||
public function test_is_utf_8() : void | ||
{ | ||
self::assertTrue( | ||
ref('str')->isUtf8()->eval( | ||
row(str_entry('str', 'Lorem Ipsum')) | ||
) | ||
); | ||
|
||
self::assertFalse( | ||
ref('str')->isUtf8()->eval( | ||
row(str_entry('str', "\xc3\x28")) | ||
) | ||
); | ||
} | ||
|
||
public function test_returns_method_returns_string_boolean() : void | ||
{ | ||
$isUtf8Function = new IsUtf8('Lorem Ipsum'); | ||
$returnType = $isUtf8Function->returns(); | ||
|
||
self::assertInstanceOf(Type::class, $returnType); | ||
|
||
self::assertTrue($returnType->isEqual(type_boolean())); | ||
} | ||
} |