Skip to content

Commit 9ff8ed9

Browse files
committed
Merge branch 'master' of https://github.com/php-etl/fast-map
# Conflicts: # src/Mapping/Composite/ArrayMapper.php
2 parents 651e5d2 + 9cff869 commit 9ff8ed9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Mapping/Composite/ArrayMapper.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,25 @@ public function __invoke($input, $output, PropertyPathInterface $outputPath)
4343

4444
public function compile(Node\Expr $outputNode): array
4545
{
46-
$output = [];
47-
foreach ($this->fields as $field) {
48-
if ($field instanceof CompilableInterface) {
49-
$output = array_merge($output, $field->compile($outputNode));
46+
return array_merge(
47+
...$this->compileMappers($outputNode)
48+
);
49+
}
50+
51+
private function compileMappers(Node\Expr $outputNode): iterable
52+
{
53+
foreach ($this->fields as $mapper) {
54+
if (!$mapper instanceof Contracts\CompilableInterface) {
55+
throw new \RuntimeException(strtr(
56+
'Expected a %expected%, but got an object of type %actual%.',
57+
[
58+
'%expected%' => Contracts\CompilableInterface::class,
59+
'%actual%' => get_class($mapper),
60+
]
61+
));
5062
}
51-
}
5263

53-
return $output;
64+
yield $mapper->compile($outputNode);
65+
}
5466
}
5567
}

0 commit comments

Comments
 (0)