File: Helpers.php

package info (click to toggle)
php-laravel-framework 10.48.29%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,188 kB
  • sloc: php: 232,347; sh: 167; makefile: 46
file content (59 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

use function PHPStan\Testing\assertType;

assertType('User', with(new User()));
assertType('bool', with(new User())->save());

assertType('User', with(new User(), function (User $user) {
    return $user;
}));
assertType('User', with(new User(), function (User $user): User {
    return $user;
}));

assertType('User', with(new User(), function ($user) {
    /** @var User $user */
    return $user;
}));
assertType('User', with(new User(), function ($user): User {
    /** @var User $user */
    return $user;
}));

assertType('int', with(new User(), function ($user) {
    assertType('User', $user);

    return 10;
}));
assertType('int', with(new User(), function ($user): int {
    assertType('User', $user);

    return 10;
}));

assertType('User', with(new User(), function ($user) {
    return $user;
}));
assertType('User', with(new User(), function ($user): User {
    return $user;
}));

// falls back to default if provided
assertType('int|null', transform(optional(), fn () => 1));
// default as callable
assertType('int|string', transform(optional(), fn () => 1, fn () => 'string'));

// non empty values
assertType('int', transform('filled', fn () => 1));
assertType('int', transform(['filled'], fn () => 1));
assertType('int', transform(new User(), fn () => 1));

// "empty" values
assertType('null', transform(null, fn () => 1));
assertType('null', transform('', fn () => 1));
assertType('null', transform([], fn () => 1));

assertType('int|null', rescue(fn () => 123));
assertType('int', rescue(fn () => 123, 345));
assertType('int', rescue(fn () => 123, fn () => 345));