From 6116d5106525a05d885408ed0a63a752732ba253 Mon Sep 17 00:00:00 2001 From: netpok Date: Thu, 15 Apr 2021 13:59:24 +0200 Subject: [PATCH] Use value helper when applicable (#36994) --- .../Database/Eloquent/Concerns/HidesAttributes.php | 8 ++------ .../Foundation/Testing/Concerns/InteractsWithViews.php | 7 +------ src/Illuminate/Foundation/helpers.php | 2 +- src/Illuminate/View/Concerns/ManagesComponents.php | 8 ++------ 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php index 7f6ebfdbc55f..065d48a8d0ff 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php @@ -94,9 +94,7 @@ public function makeVisible($attributes) */ public function makeVisibleIf($condition, $attributes) { - $condition = $condition instanceof Closure ? $condition($this) : $condition; - - return $condition ? $this->makeVisible($attributes) : $this; + return value($condition, $this) ? $this->makeVisible($attributes) : $this; } /** @@ -123,8 +121,6 @@ public function makeHidden($attributes) */ public function makeHiddenIf($condition, $attributes) { - $condition = $condition instanceof Closure ? $condition($this) : $condition; - - return value($condition) ? $this->makeHidden($attributes) : $this; + return value($condition, $this) ? $this->makeHidden($attributes) : $this; } } diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php index faa6c64a367e..9dfbff5a38d2 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php @@ -2,7 +2,6 @@ namespace Illuminate\Foundation\Testing\Concerns; -use Closure; use Illuminate\Support\Facades\View as ViewFacade; use Illuminate\Support\MessageBag; use Illuminate\Support\Str; @@ -57,11 +56,7 @@ protected function component(string $componentClass, array $data = []) { $component = $this->app->make($componentClass, $data); - $view = $component->resolveView(); - - if ($view instanceof Closure) { - $view = $view($data); - } + $view = value($component->resolveView(), $data); return $view instanceof View ? new TestView($view->with($component->data())) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 7aa2228e187c..5f5a71168701 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -659,7 +659,7 @@ function rescue(callable $callback, $rescue = null, $report = true) report($e); } - return $rescue instanceof Closure ? $rescue($e) : $rescue; + return value($rescue, $e); } } } diff --git a/src/Illuminate/View/Concerns/ManagesComponents.php b/src/Illuminate/View/Concerns/ManagesComponents.php index 81b2bdf6cbaf..273e8b496328 100644 --- a/src/Illuminate/View/Concerns/ManagesComponents.php +++ b/src/Illuminate/View/Concerns/ManagesComponents.php @@ -2,7 +2,6 @@ namespace Illuminate\View\Concerns; -use Closure; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Contracts\View\View; use Illuminate\Support\Arr; @@ -84,9 +83,7 @@ public function renderComponent() $data = $this->componentData(); - if ($view instanceof Closure) { - $view = $view($data); - } + $view = value($view, $data); if ($view instanceof View) { return $view->with($data)->render(); @@ -151,8 +148,7 @@ public function endSlot() $this->slotStack[$this->currentComponent()] ); - $this->slots[$this->currentComponent()] - [$currentSlot] = new HtmlString(trim(ob_get_clean())); + $this->slots[$this->currentComponent()][$currentSlot] = new HtmlString(trim(ob_get_clean())); } /**