Skip to content

[Proposal]: Remove Rows::fromArray() helper (syntax-sugar?) #1928

@stloyd

Description

@stloyd

Describe the Proposal

As a first step in reusing EntryFactory, we should remove this helper method, as it is, in fact, just "syntax-sugar" hiding inside a call to array_to_rows().

That helper in the current codebase is only used in benchmarks. I didn't find any real exposure of it in the docs or elsewhere; that's why I think it's safe to remove it and use array_to_rows() directly.

API Adjustments

Subject: [PATCH] Remove `Rows::fromArray()`
---
Index: src/core/etl/src/Flow/ETL/Rows.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/core/etl/src/Flow/ETL/Rows.php b/src/core/etl/src/Flow/ETL/Rows.php
--- a/src/core/etl/src/Flow/ETL/Rows.php	(revision d233d899aef236466fadd808f9d1de9235541dd6)
+++ b/src/core/etl/src/Flow/ETL/Rows.php	(date 1761665853910)
@@ -4,7 +4,7 @@
 
 namespace Flow\ETL;
 
-use function Flow\ETL\DSL\{array_to_rows, row};
+use function Flow\ETL\DSL\row;
 use function Flow\Types\DSL\type_integer;
 use Flow\ETL\Exception\{DuplicatedEntriesException, InvalidArgumentException, RuntimeException};
 use Flow\ETL\Hash\{Algorithm, NativePHPHash};
@@ -34,14 +34,6 @@
         $this->partitions = new Partitions();
     }
 
-    /**
-     * @param array<array-key, mixed> $data
-     */
-    public static function fromArray(array $data, EntryFactory $entryFactory = new EntryFactory()) : self
-    {
-        return array_to_rows($data, $entryFactory);
-    }
-
     /**
      * @param array<int, Row>|array<Row> $rows
      * @param array<Partition>|array<string, string>|Partitions $partitions
Index: src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEachEntryTransformerBench.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEachEntryTransformerBench.php b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEachEntryTransformerBench.php
--- a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEachEntryTransformerBench.php	(revision d233d899aef236466fadd808f9d1de9235541dd6)
+++ b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEachEntryTransformerBench.php	(date 1761665853432)
@@ -4,7 +4,7 @@
 
 namespace Flow\ETL\Tests\Benchmark\Transformer;
 
-use function Flow\ETL\DSL\{config, flow_context, rename_style};
+use function Flow\ETL\DSL\{array_to_rows, config, flow_context, rename_style};
 use Flow\ETL\{FlowContext, Rows, String\StringStyles, Transformer\RenameEachEntryTransformer};
 use PhpBench\Attributes\{BeforeMethods, Groups};
 
@@ -18,14 +18,14 @@
 
     public function setUp() : void
     {
-        $this->rows = Rows::fromArray(
+        $this->rows = array_to_rows(
             \array_merge(...\array_map(static fn () : array => [
                 ['id' => 1, 'random text' => null, 'from' => 666],
                 ['id' => 2, 'random text' => null, 'from' => 666],
                 ['id' => 3, 'random text' => null, 'from' => 666],
                 ['id' => 4, 'random text' => null, 'from' => 666],
                 ['id' => 5, 'random text' => null, 'from' => 666],
-            ], \range(0, 1_000)))
+            ], \range(0, 1_000))),
         );
         $this->context = flow_context(config());
     }
Index: src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php
--- a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php	(revision d233d899aef236466fadd808f9d1de9235541dd6)
+++ b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php	(date 1761665825556)
@@ -4,7 +4,7 @@
 
 namespace Flow\ETL\Tests\Benchmark;
 
-use function Flow\ETL\DSL\{ref, string_entry};
+use function Flow\ETL\DSL\{array_to_rows, ref, string_entry};
 use Flow\ETL\{Row, Rows};
 use PhpBench\Attributes\{BeforeMethods, Groups, Revs};
 
@@ -19,7 +19,7 @@
 
     public function setUp() : void
     {
-        $this->rows = Rows::fromArray(
+        $this->rows = array_to_rows(
             \array_merge(...\array_map(static fn () : array => [
                 ['id' => 1, 'random' => false, 'text' => null, 'from' => 666],
                 ['id' => 2, 'random' => true, 'text' => null, 'from' => 666],
@@ -29,7 +29,7 @@
             ], \range(0, 10_000)))
         );
 
-        $this->reducedRows = Rows::fromArray(
+        $this->reducedRows = array_to_rows(
             \array_merge(...\array_map(static fn () : array => [
                 ['id' => 1, 'random' => false, 'text' => null, 'from' => 666],
                 ['id' => 2, 'random' => true, 'text' => null, 'from' => 666],
Index: src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEntryTransformerBench.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEntryTransformerBench.php b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEntryTransformerBench.php
--- a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEntryTransformerBench.php	(revision d233d899aef236466fadd808f9d1de9235541dd6)
+++ b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/Transformer/RenameEntryTransformerBench.php	(date 1761665825548)
@@ -4,7 +4,7 @@
 
 namespace Flow\ETL\Tests\Benchmark\Transformer;
 
-use function Flow\ETL\DSL\{config, flow_context};
+use function Flow\ETL\DSL\{array_to_rows, config, flow_context};
 use Flow\ETL\{FlowContext, Rows};
 use Flow\ETL\Transformer\RenameEntryTransformer;
 use PhpBench\Attributes\{BeforeMethods, Groups};
@@ -19,7 +19,7 @@
 
     public function setUp() : void
     {
-        $this->rows = Rows::fromArray(
+        $this->rows = array_to_rows(
             \array_merge(...\array_map(static fn () : array => [
                 ['id' => 1, 'random' => false, 'text' => null, 'from' => 666],
                 ['id' => 2, 'random' => true, 'text' => null, 'from' => 666],

Are you intending to also work on proposed change?

Yes

Are you interested in sponsoring this change?

No

Integration & Dependencies

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions