Skip to content

Commit 69b1c46

Browse files
committed
Extract DataRow.of()
1 parent 90ec44b commit 69b1c46

9 files changed

+13
-14
lines changed

src/Internal/Frame/DataRow.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public function __construct(array $keys, array $assoc, array $values)
1717
$this->values = $values;
1818
}
1919

20-
public static function empty(): DataRow
20+
public static function of(array $values): DataRow
2121
{
22-
return new self([], [], []);
22+
return new DataRow($values, \array_fill(0, \count($values), true), $values);
2323
}
2424

25-
public static function associative($key, array $values): DataRow
25+
public static function dictionaryEntry($key, $value): DataRow
2626
{
27-
return new DataRow([$key], [true], $values);
27+
return new DataRow([$key], [true], [$value]);
2828
}
2929

3030
public function isAssociative(int $index): bool
@@ -42,7 +42,6 @@ public function joined(DataRow $dataRow): DataRow
4242
return new DataRow(
4343
\array_merge($this->keys, $dataRow->keys),
4444
\array_merge($this->associative, $dataRow->associative),
45-
\array_merge($this->values, $dataRow->values)
46-
);
45+
\array_merge($this->values, $dataRow->values));
4746
}
4847
}

src/Internal/Provider/DictionaryProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function dataset(): array
1818
{
1919
$dataset = [];
2020
foreach ($this->dictionary as $key => $value) {
21-
$dataset[] = DataRow::associative($key, [$value]);
21+
$dataset[] = DataRow::dictionaryEntry($key, $value);
2222
}
2323
return $dataset;
2424
}

src/Internal/Provider/DistinctPairsProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function dataset(): array
2222
if ($index1 === $index2) {
2323
continue;
2424
}
25-
$dataset[] = new DataRow([$augend, $addend], [true, true], [$augend, $addend]);
25+
$dataset[] = DataRow::of([$augend, $addend]);
2626
}
2727
}
2828
return $dataset;

src/Internal/Provider/EntriesProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function dataset(): array
1818
{
1919
$dataset = [];
2020
foreach ($this->dictionary as $key => $value) {
21-
$dataset[] = new DataRow([$key, $value], [true, true], [$key, $value]);
21+
$dataset[] = DataRow::of([$key, $value]);
2222
}
2323
return $dataset;
2424
}

src/Internal/Provider/ListProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function dataset(): array
1818
{
1919
$dataset = [];
2020
foreach ($this->values as $value) {
21-
$dataset[] = DataRow::associative($value, [$value]);
21+
$dataset[] = DataRow::of([$value]);
2222
}
2323
return $dataset;
2424
}

src/Internal/Provider/PairsProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function dataset(): array
1919
$dataset = [];
2020
foreach ($this->values as $augend) {
2121
foreach ($this->values as $addend) {
22-
$dataset[] = new DataRow([$augend, $addend], [true, true], [$augend, $addend]);
22+
$dataset[] = DataRow::of([$augend, $addend]);
2323
}
2424
}
2525
return $dataset;

src/Internal/Provider/TuplesProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function dataset(): array
1818
{
1919
$dataset = [];
2020
foreach ($this->sets as $set) {
21-
$dataset[] = new DataRow($set, \array_fill(0, \count($set), true), $set);
21+
$dataset[] = DataRow::of($set);
2222
}
2323
return $dataset;
2424
}

src/Internal/Provider/ZipProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function count(): int
6767

6868
private function zippedRow(int $rowIndex): DataRow
6969
{
70-
$joinedRow = DataRow::empty();
70+
$joinedRow = DataRow::of([]);
7171
foreach ($this->dataFrames as $dataProvider) {
7272
$joinedRow = $joinedRow->joined($dataProvider->dataset()[$rowIndex]);
7373
}

test/Fixture/HistoryDataProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private function arrayDatasets(): array
2929
{
3030
$datasets = [];
3131
foreach ($this->elements as $key => $value) {
32-
$datasets[] = DataRow::associative($key, [$value]);
32+
$datasets[] = DataRow::dictionaryEntry($key, $value);
3333
}
3434
return $datasets;
3535
}

0 commit comments

Comments
 (0)