diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 73adf3606965..8dbef5ea7fe1 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -665,7 +665,7 @@ public function intersectByKeys($items) * * @phpstan-assert-if-true null $this->first() * - * @phpstan-assert-if-false !null $this->first() + * @phpstan-assert-if-false TValue $this->first() * * @return bool */ diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index 14fc0ba399a7..2ea0880c2398 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -367,7 +367,7 @@ public function ensure($type) /** * Determine if the collection is not empty. * - * @phpstan-assert-if-true !null $this->first() + * @phpstan-assert-if-true TValue $this->first() * * @phpstan-assert-if-false null $this->first() * diff --git a/types/Support/Collection.php b/types/Support/Collection.php index 2e8b4a926386..94769f8dc8ee 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -487,6 +487,20 @@ function ($collection, $count) { assertType('string|User', $collection->first(null, function () { return 'string'; })); +if ($collection->isNotEmpty()) { + assertType('User', $collection->first()); + assertType('string|User', $collection->first(null, 'foo')); +} else { + assertType('null', $collection->first()); + assertType('string|User', $collection->first(null, 'foo')); +} +if ($collection->isEmpty()) { + assertType('null', $collection->first()); + assertType('string|User', $collection->first(null, 'foo')); +} else { + assertType('User', $collection->first()); + assertType('string|User', $collection->first(null, 'foo')); +} assertType('Illuminate\Support\Collection', $collection->flatten()); assertType('Illuminate\Support\Collection', $collection::make(['string' => 'string'])->flatten(4));