From 49d2e961238b6109586714b8fa69bab54f600c46 Mon Sep 17 00:00:00 2001 From: Bastien Philippe Date: Mon, 28 Feb 2022 10:28:59 +0100 Subject: [PATCH 1/2] Fix Conditional::when and Conditional::unless when called with invokable object --- .../Conditionable/Traits/Conditionable.php | 4 ++-- types/Support/Collection.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Conditionable/Traits/Conditionable.php b/src/Illuminate/Conditionable/Traits/Conditionable.php index 0f8a3a029ff6..40356a6621b4 100644 --- a/src/Illuminate/Conditionable/Traits/Conditionable.php +++ b/src/Illuminate/Conditionable/Traits/Conditionable.php @@ -13,7 +13,7 @@ trait Conditionable * @template TWhenParameter * @template TWhenReturnType * - * @param (callable($this): TWhenParameter)|TWhenParameter $value + * @param (Closure($this): TWhenParameter)|TWhenParameter $value * @param (callable($this, TWhenParameter): TWhenReturnType)|null $callback * @param (callable($this, TWhenParameter): TWhenReturnType)|null $default * @return $this|TWhenReturnType @@ -41,7 +41,7 @@ public function when($value, callable $callback = null, callable $default = null * @template TUnlessParameter * @template TUnlessReturnType * - * @param (callable($this): TUnlessParameter)|TUnlessParameter $value + * @param (Closure($this): TUnlessParameter)|TUnlessParameter $value * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $callback * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $default * @return $this|TUnlessReturnType diff --git a/types/Support/Collection.php b/types/Support/Collection.php index a2eaead80465..54b387ed9132 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -12,6 +12,15 @@ /** @var Traversable $traversable */ $traversable = []; +class Invokable +{ + public function __invoke(): string + { + return 'Taylor'; + } +} +$invokable = new Invokable(); + assertType('Illuminate\Support\Collection', $collection); assertType('Illuminate\Support\Collection', collect(['string'])); @@ -294,6 +303,11 @@ function ($collection, $count) { ) ); +assertType('Illuminate\Support\Collection|void', $collection->when($invokable, function ($collection, $param) { + assertType('Illuminate\Support\Collection', $collection); + assertType('Invokable', $param); +})); + assertType('bool|Illuminate\Support\Collection', $collection->whenEmpty(function ($collection) { assertType('Illuminate\Support\Collection', $collection); @@ -376,6 +390,11 @@ function ($collection, $count) { ) ); +assertType('Illuminate\Support\Collection|void', $collection->unless($invokable, function ($collection, $param) { + assertType('Illuminate\Support\Collection', $collection); + assertType('Invokable', $param); +})); + assertType('bool|Illuminate\Support\Collection', $collection->unlessEmpty(function ($collection) { assertType('Illuminate\Support\Collection', $collection); From 356b1221321be41f0721b29d03a35e1535929643 Mon Sep 17 00:00:00 2001 From: Bastien Philippe Date: Mon, 28 Feb 2022 17:37:46 +0100 Subject: [PATCH 2/2] Use FQCN in docblocks --- src/Illuminate/Conditionable/Traits/Conditionable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Conditionable/Traits/Conditionable.php b/src/Illuminate/Conditionable/Traits/Conditionable.php index 40356a6621b4..81451bcded5c 100644 --- a/src/Illuminate/Conditionable/Traits/Conditionable.php +++ b/src/Illuminate/Conditionable/Traits/Conditionable.php @@ -13,7 +13,7 @@ trait Conditionable * @template TWhenParameter * @template TWhenReturnType * - * @param (Closure($this): TWhenParameter)|TWhenParameter $value + * @param (\Closure($this): TWhenParameter)|TWhenParameter $value * @param (callable($this, TWhenParameter): TWhenReturnType)|null $callback * @param (callable($this, TWhenParameter): TWhenReturnType)|null $default * @return $this|TWhenReturnType @@ -41,7 +41,7 @@ public function when($value, callable $callback = null, callable $default = null * @template TUnlessParameter * @template TUnlessReturnType * - * @param (Closure($this): TUnlessParameter)|TUnlessParameter $value + * @param (\Closure($this): TUnlessParameter)|TUnlessParameter $value * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $callback * @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $default * @return $this|TUnlessReturnType