From 4066318302ac7faa02f2100a79ee9d7f08ee5b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Wei=C3=9F?= Date: Fri, 24 Jan 2025 22:09:27 +0100 Subject: [PATCH] Fix phpstan --- src/Lazy.php | 3 +-- src/Support/Lazy/InertiaDeferred.php | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Lazy.php b/src/Lazy.php index 4f5c72d3..4c038881 100644 --- a/src/Lazy.php +++ b/src/Lazy.php @@ -5,7 +5,6 @@ use Closure; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Traits\Macroable; -use Inertia\DeferProp; use Spatie\LaravelData\Support\Lazy\ClosureLazy; use Spatie\LaravelData\Support\Lazy\ConditionalLazy; use Spatie\LaravelData\Support\Lazy\DefaultLazy; @@ -39,7 +38,7 @@ public static function inertia(Closure $value): InertiaLazy return new InertiaLazy($value); } - public static function inertiaDeferred(DeferProp $value): InertiaDeferred + public static function inertiaDeferred(mixed $value): InertiaDeferred { return new InertiaDeferred($value); } diff --git a/src/Support/Lazy/InertiaDeferred.php b/src/Support/Lazy/InertiaDeferred.php index 96ec9290..a544ca2d 100644 --- a/src/Support/Lazy/InertiaDeferred.php +++ b/src/Support/Lazy/InertiaDeferred.php @@ -7,9 +7,13 @@ class InertiaDeferred extends ConditionalLazy { public function __construct( - DeferProp $value, + mixed $value, ) { - parent::__construct(fn () => true, fn () => $value()); + $callback = is_a($value, DeferProp::class) + ? fn () => $value() + : fn () => new DeferProp($value); + + parent::__construct(fn () => true, $callback); } public function resolve(): DeferProp