From 3eea0104de41a53111ccbe8991e87e7d5a7bd308 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 15 Jan 2024 10:16:34 +0300 Subject: [PATCH] Fixed a bug when working with text values like function names --- src/Concerns/Call.php | 9 +++++++-- tests/TestCase.php | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Concerns/Call.php b/src/Concerns/Call.php index e6f8c7e..a267a8f 100644 --- a/src/Concerns/Call.php +++ b/src/Concerns/Call.php @@ -10,12 +10,12 @@ trait Call protected function call(mixed $callback = null): mixed { - return $this->isCallable($callback) ? $callback() : $callback; + return $this->isCallable($callback) && ! $this->isFunction($callback) ? $callback() : $callback; } protected function makeCallable($value): callable { - if ($this->isCallable($value)) { + if ($this->isCallable($value) && ! $this->isFunction($value)) { return $value; } @@ -28,4 +28,9 @@ protected function isCallable($value): bool { return is_callable($value); } + + protected function isFunction($value): bool + { + return is_string($value) && function_exists($value); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 0ab35e2..6bf40b5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,9 +28,9 @@ abstract class TestCase extends BaseTestCase protected array $keys = ['Foo', 'Bar', 'Baz']; - protected mixed $value = 'Foo'; + protected mixed $value = 'value'; - protected string $value_second = 'Bar'; + protected string $value_second = 'Foo'; protected function getPackageProviders($app): array {