Skip to content

Commit 4baf4f7

Browse files
authored
Makes with generic (#39615)
1 parent 032c69a commit 4baf4f7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Illuminate/Support/helpers.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,11 @@ function windows_os()
368368
/**
369369
* Return the given value, optionally passed through the given callback.
370370
*
371-
* @param mixed $value
372-
* @param callable|null $callback
373-
* @return mixed
371+
* @template TValue
372+
*
373+
* @param TValue $value
374+
* @param (callable(TValue): TValue)|null $callback
375+
* @return TValue
374376
*/
375377
function with($value, callable $callback = null)
376378
{

types/Support/Helpers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use function PHPStan\Testing\assertType;
4+
5+
assertType('User', with(new User()));
6+
assertType('bool', with(new User())->save());
7+
assertType('User', with(new User(), function (User $user) {
8+
return $user;
9+
}));
10+
11+
assertType('int|User', with(new User(), function ($user) {
12+
assertType('int|User', $user);
13+
14+
return 10;
15+
}));

0 commit comments

Comments
 (0)