-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
ref()->arrayReverse()
entry expression (#527)
- Loading branch information
Showing
6 changed files
with
69 additions
and
105 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
26 changes: 26 additions & 0 deletions
26
src/core/etl/src/Flow/ETL/Row/Reference/Expression/ArrayReverse.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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Row\Reference\Expression; | ||
|
||
use Flow\ETL\Row; | ||
use Flow\ETL\Row\Reference\Expression; | ||
|
||
final class ArrayReverse implements Expression | ||
{ | ||
public function __construct(private readonly Expression $left, private readonly bool $preserveKeys) | ||
{ | ||
} | ||
|
||
public function eval(Row $row) : mixed | ||
{ | ||
$left = $this->left->eval($row); | ||
|
||
if (!\is_array($left)) { | ||
return null; | ||
} | ||
|
||
return \array_reverse($left, $this->preserveKeys); | ||
} | ||
} |
60 changes: 0 additions & 60 deletions
60
src/core/etl/src/Flow/ETL/Transformer/ArrayReverseTransformer.php
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Reference/Expression/ArrayReverseTest.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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Row\Reference\Expression; | ||
|
||
use function Flow\ETL\DSL\ref; | ||
use Flow\ETL\DSL\Entry; | ||
use Flow\ETL\Row; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ArrayReverseTest extends TestCase | ||
{ | ||
public function test_array_reverse_array_entry() : void | ||
{ | ||
$this->assertSame( | ||
[5, 3, 10, 4], | ||
ref('a')->arrayReverse() | ||
->eval( | ||
Row::create( | ||
Entry::array('a', [4, 10, 3, 5]), | ||
), | ||
) | ||
); | ||
} | ||
|
||
public function test_array_reverse_non_array_entry() : void | ||
{ | ||
$this->assertNull( | ||
ref('a')->arrayReverse() | ||
->eval( | ||
Row::create( | ||
Entry::int('a', 123), | ||
), | ||
) | ||
); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/ArrayReverseTransformerTest.php
This file was deleted.
Oops, something went wrong.