From 804911c9b63c14fc36c1308f6c7caacf6d859c0d Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 18 Jan 2022 13:35:32 +0100 Subject: [PATCH] cast only existing values and throw exception in case a mandatory return value is missing #8 --- src/Traits/ParamTrait.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Traits/ParamTrait.php b/src/Traits/ParamTrait.php index 10fda07..eb19883 100644 --- a/src/Traits/ParamTrait.php +++ b/src/Traits/ParamTrait.php @@ -79,8 +79,15 @@ private function castOutputValues(array $outputs, array $result): array $return = []; foreach ($outputs as $output) { $key = $output->getName(); - $value = $output->cast($result[$key]); - $return[$key] = $value; + if (array_key_exists($key, $result)) { + $return[$key] = $output->cast($result[$key]); + } elseif (!$output->isOptional()) { + throw new FunctionCallException(sprintf( + 'Missing result value \'%s\' for function call \'%s\'!', + $key, + $this->getName() + )); + } } return $return; }