Skip to content

Commit 20c7c62

Browse files
committed
AbstractFunction::setParams() extracts allowed keys from the given array if they are set instead of enforcing them #25
1 parent 5fd4c8e commit 20c7c62

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

src/AbstractFunction.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,9 @@ public function setParam(string $key, float|int|bool|array|string $value): Abstr
267267
public function setParams(array $params): IFunction
268268
{
269269
foreach ($this->getAllowedKeys() as $key) {
270-
if (!array_key_exists($key, $params)) {
271-
throw new InvalidArgumentException(sprintf(
272-
'%s is missing parameter key %s!',
273-
static::class,
274-
$key
275-
));
270+
if (array_key_exists($key, $params)) {
271+
$this->set($key, $params[$key]);
276272
}
277-
$this->set($key, $params[$key]);
278273
}
279274
return $this;
280275
}

tests/AbstractFunctionTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,7 @@ public static function provideInvalidJson(): array
535535
. '"params":{"DbF6y6oE":"CLsVlAje"}}'
536536
],
537537
['7072.8'],
538-
['true'],
539-
[
540-
'{"name":"gYcOqTNx",'
541-
. '"api":[{"type":"string","name":"gixpbEZj","direction":"input","optional":false}],'
542-
. '"params":{"8rszwVLE":"dUK6wkp0"}}'
543-
]
538+
['true']
544539
];
545540
}
546541

0 commit comments

Comments
 (0)