Skip to content

Commit

Permalink
Changed default transformers behavior from Entries::add to Entries::s…
Browse files Browse the repository at this point in the history
…et (#220)
  • Loading branch information
norberttech committed Apr 15, 2022
1 parent 30162e2 commit 80a679f
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/ArrayCollectionGetTransformer.php
Expand Up @@ -90,7 +90,7 @@ public function transform(Rows $rows) : Rows
throw new RuntimeException("Extracted value from path \"{$path}\" is not array but {$type}");
}

return $row->add(
return $row->set(
new Row\Entry\ArrayEntry(
$this->newEntryName,
$extractedValues
Expand Down
Expand Up @@ -60,7 +60,7 @@ public function transform(Rows $rows) : Rows
}

/** @psalm-suppress MixedArgument */
return $row->add(
return $row->set(
new Row\Entry\ArrayEntry(
$this->newEntryName,
/** @phpstan-ignore-next-line */
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/ArrayDotGetTransformer.php
Expand Up @@ -58,7 +58,7 @@ public function transform(Rows $rows) : Rows
throw new RuntimeException("{$this->arrayEntryName} is not ArrayEntry but {$entryClass}");
}

return $row->add(
return $row->set(
$this->entryFactory->create(
$this->newEntryName,
array_dot_get($arrayEntry->value(), $this->path)
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/ArrayMergeTransformer.php
Expand Up @@ -56,7 +56,7 @@ public function transform(Rows $rows) : Rows
$entryValues[] = $arrayEntry->value();
}

return $row->add(new Row\Entry\ArrayEntry(
return $row->set(new Row\Entry\ArrayEntry(
$this->newEntryName,
\array_merge(...$entryValues)
));
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/HashTransformer.php
Expand Up @@ -65,7 +65,7 @@ public function transform(Rows $rows) : Rows
}
}

return $row->add(Entry::string($this->newEntryName, \hash($this->algorithm, \implode('', $values), false)));
return $row->set(Entry::string($this->newEntryName, \hash($this->algorithm, \implode('', $values), false)));
};

return $rows->map($transformer);
Expand Down
4 changes: 2 additions & 2 deletions src/Flow/ETL/Transformer/MathOperationTransformer.php
Expand Up @@ -112,10 +112,10 @@ public function transform(Rows $rows) : Rows
};

if (\is_float($value)) {
return $row->add(new Row\Entry\FloatEntry($this->newEntryName, $value));
return $row->set(new Row\Entry\FloatEntry($this->newEntryName, $value));
}

return $row->add(new Row\Entry\IntegerEntry($this->newEntryName, $value));
return $row->set(new Row\Entry\IntegerEntry($this->newEntryName, $value));
};

return $rows->map($transformer);
Expand Down
4 changes: 2 additions & 2 deletions src/Flow/ETL/Transformer/MathValueOperationTransformer.php
Expand Up @@ -103,10 +103,10 @@ public function transform(Rows $rows) : Rows
};

if (\is_float($value)) {
return $row->add(new Row\Entry\FloatEntry($this->newEntryName, $value));
return $row->set(new Row\Entry\FloatEntry($this->newEntryName, $value));
}

return $row->add(new Row\Entry\IntegerEntry($this->newEntryName, $value));
return $row->set(new Row\Entry\IntegerEntry($this->newEntryName, $value));
};

return $rows->map($transformer);
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/ObjectMethodTransformer.php
Expand Up @@ -76,7 +76,7 @@ public function transform(Rows $rows) : Rows
throw new RuntimeException("\"{$this->objectEntryName}\" is object does not have \"{$this->method}\" method.");
}

return $row->add($this->entryFactory->create(
return $row->set($this->entryFactory->create(
$this->newEntryName,
/** @phpstan-ignore-next-line */
\call_user_func([$object, $this->method], ...$this->parameters)
Expand Down
3 changes: 1 addition & 2 deletions src/Flow/ETL/Transformer/ObjectToArrayTransformer.php
Expand Up @@ -47,8 +47,7 @@ public function transform(Rows $rows) : Rows
}

$entries = $row->entries()
->remove($this->objectEntryName)
->add(
->set(
new Row\Entry\ArrayEntry(
$this->objectEntryName,
$this->hydrator->extract(
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/StaticEntryTransformer.php
Expand Up @@ -36,7 +36,7 @@ public function transform(Rows $rows) : Rows
/**
* @psalm-var pure-callable(Row $row) : Row $transformer
*/
$transformer = fn (Row $row) : Row => $row->add($this->entry);
$transformer = fn (Row $row) : Row => $row->set($this->entry);

return $rows->map($transformer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/ETL/Transformer/StringConcatTransformer.php
Expand Up @@ -56,7 +56,7 @@ public function transform(Rows $rows) : Rows
$values[] = $entry->toString();
}

return $row->add(
return $row->set(
new Row\Entry\StringEntry(
$this->newEntryName,
\implode($this->glue, $values)
Expand Down

0 comments on commit 80a679f

Please sign in to comment.