Skip to content

Commit 804911c

Browse files
committed
cast only existing values and throw exception in case a mandatory return value is missing #8
1 parent aaeedce commit 804911c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Traits/ParamTrait.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,15 @@ private function castOutputValues(array $outputs, array $result): array
7979
$return = [];
8080
foreach ($outputs as $output) {
8181
$key = $output->getName();
82-
$value = $output->cast($result[$key]);
83-
$return[$key] = $value;
82+
if (array_key_exists($key, $result)) {
83+
$return[$key] = $output->cast($result[$key]);
84+
} elseif (!$output->isOptional()) {
85+
throw new FunctionCallException(sprintf(
86+
'Missing result value \'%s\' for function call \'%s\'!',
87+
$key,
88+
$this->getName()
89+
));
90+
}
8491
}
8592
return $return;
8693
}

0 commit comments

Comments
 (0)