Skip to content

Commit 39bdb99

Browse files
authored
Simplify concat functions internals (#1393)
Simplify concat functions
1 parent 9a6df1e commit 39bdb99

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/core/etl/src/Flow/ETL/Function/Concat.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,17 @@ public function __construct(
2323

2424
public function eval(Row $row) : mixed
2525
{
26-
$values = \array_map(fn (ScalarFunction|string $string) : mixed => \is_string($string) ? $string : Caster::default()->to(type_string(true))->value($string->eval($row)), $this->refs);
27-
26+
/** @var array<string> $concatValues */
2827
$concatValues = [];
2928

30-
foreach ($values as $value) {
29+
foreach ($this->refs as $value) {
30+
$value = \is_string($value) ? $value : Caster::default()->to(type_string(true))->value($value->eval($row));
31+
3132
if (\is_string($value)) {
3233
$concatValues[] = $value;
3334
}
3435
}
3536

36-
if (\count($concatValues) === 0) {
37-
return '';
38-
}
39-
40-
/** @var array<string> $values */
4137
return \implode('', $concatValues);
4238
}
4339
}

src/core/etl/src/Flow/ETL/Function/ConcatWithSeparator.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,17 @@ public function eval(Row $row) : mixed
3030
return '';
3131
}
3232

33-
$values = \array_map(fn (ScalarFunction|string $string) : mixed => \is_string($string) ? $string : Caster::default()->to(type_string(true))->value($string->eval($row)), $this->refs);
34-
33+
/** @var array<string> $concatValues */
3534
$concatValues = [];
3635

37-
foreach ($values as $value) {
36+
foreach ($this->refs as $value) {
37+
$value = \is_string($value) ? $value : Caster::default()->to(type_string(true))->value($value->eval($row));
38+
3839
if (\is_string($value)) {
3940
$concatValues[] = $value;
4041
}
4142
}
4243

43-
if (\count($concatValues) === 0) {
44-
return '';
45-
}
46-
47-
/** @var array<string> $values */
4844
return \implode($separator, $concatValues);
4945
}
5046
}

0 commit comments

Comments
 (0)