Skip to content

Commit 10403ca

Browse files
committed
fix(Utils): Improve method callable check for parameter handling
- Enhance the method existence check with is_callable for more reliability - Simplify parameter handling by using a ternary operator - Ensure proper invocation of methods based on their parameter count - This change resolves potential issues when methods are not callable
1 parent bf33381 commit 10403ca

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/Support/Utils.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,14 @@ public static function applyConfigurationToObject(object $object, array $configu
4848
static fn (string $key): string => 'on'.Str::studly($key),
4949
] as $caster
5050
) {
51-
if (method_exists($object, $method = $caster($key))) {
51+
if (method_exists($object, $method = $caster($key)) && \is_callable([$object, $method])) {
5252
$numberOfParameters = (new \ReflectionMethod($object, $method))->getNumberOfParameters();
5353

5454
if (0 === $numberOfParameters) {
5555
continue;
5656
}
5757

58-
if (1 === $numberOfParameters) {
59-
$object->{$method}($value);
60-
61-
return;
62-
}
63-
64-
app()->call([$object, $method], $value);
58+
1 === $numberOfParameters ? $object->{$method}($value) : app()->call([$object, $method], $value);
6559

6660
return;
6761
}

0 commit comments

Comments
 (0)