Repository navigation
Expand file tree
/
Copy pathModel.php
More file actions
77 lines (64 loc) · 2.13 KB
/
Copy pathModel.php
File metadata and controls
77 lines (64 loc) · 2.13 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Types\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Model;
use User;
use function PHPStan\Testing\assertType;
function test(User $user, Post $post, Comment $comment, Article $article): void
{
assertType('Hyperf\Database\Model\Builder<User>', User::query());
assertType('Hyperf\Database\Model\Builder<User>', $user->newQuery());
assertType('Hyperf\Database\Model\Builder<User>', $user->withTrashed());
assertType('Hyperf\Database\Model\Builder<User>', $user->onlyTrashed());
assertType('Hyperf\Database\Model\Builder<User>', $user->withoutTrashed());
assertType('Hyperf\Database\Model\Collection<(int|string), User>', $user->newCollection([new User()]));
assertType('Hyperf\Types\Model\Comments', $comment->newCollection([new Comment()]));
assertType('Hyperf\Database\Model\Collection<(int|string), Hyperf\Types\Model\Post>', $post->newCollection(['foo' => new Post()]));
assertType('Hyperf\Database\Model\Collection<(int|string), Hyperf\Types\Model\Article>', $article->newCollection([new Article()]));
assertType('Hyperf\Types\Model\Comments', $comment->newCollection([new Comment()]));
assertType('bool|null', $user->restore());
}
class Post extends Model
{
protected static string $collectionClass = Posts::class;
}
/**
* @template TKey of array-key
* @template TModel of Post
*
* @extends Collection<TKey, TModel> */
class Posts extends Collection
{
}
final class Comment extends Model
{
/** @param array<array-key, Comment> $models */
public function newCollection(array $models = []): Comments
{
return new Comments($models);
}
}
/** @extends Collection<array-key, Comment> */
final class Comments extends Collection
{
}
class Article extends Model
{
}
/**
* @template TKey of array-key
* @template TModel of Article
*
* @extends Collection<TKey, TModel> */
class Articles extends Collection
{
}