3
3
namespace Torann \LaravelRepository \Contracts ;
4
4
5
5
use Illuminate \Support \Collection ;
6
- use Illuminate \Pagination \Paginator ;
7
6
use Illuminate \Database \Eloquent \Model ;
8
7
8
+ /**
9
+ * @template TKey of array-key
10
+ * @template TValue
11
+ *
12
+ * @implements \ArrayAccess<TKey, TValue>
13
+ */
9
14
interface RepositoryContract
10
15
{
11
16
/**
12
17
* Return model instance.
13
18
*
14
19
* @return Model
15
20
*/
16
- public function getModel ();
21
+ public function getModel (): Model ;
17
22
18
23
/**
19
24
* Find data by id
@@ -23,29 +28,29 @@ public function getModel();
23
28
*
24
29
* @return Model|Collection
25
30
*/
26
- public function find ($ id , $ columns = ['* ' ]);
31
+ public function find (mixed $ id , array $ columns = ['* ' ]);
27
32
28
33
/**
29
34
* Find a model by its primary key or throw an exception.
30
35
*
31
- * @para string $id
32
- *
33
- * @return \Illuminate\Database\Eloquent\Model
36
+ * @param string $id
37
+ * @param array $columns
34
38
*
39
+ * @return Model
35
40
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
36
41
*/
37
- public function findOrFail ($ id );
42
+ public function findOrFail (string $ id, array $ columns = [ ' * ' ] );
38
43
39
44
/**
40
45
* Find data by field and value
41
46
*
42
- * @param $field
43
- * @param $value
44
- * @param array $columns
47
+ * @param string $field
48
+ * @param string $value
49
+ * @param array $columns
45
50
*
46
- * @return Model|Collection
51
+ * @return Model|object|static|null
47
52
*/
48
- public function findBy ($ field , $ value , $ columns = ['* ' ]);
53
+ public function findBy (string $ field , string $ value , array $ columns = ['* ' ]);
49
54
50
55
/**
51
56
* Find data by field
@@ -54,38 +59,38 @@ public function findBy($field, $value, $columns = ['*']);
54
59
* @param mixed $value
55
60
* @param array $columns
56
61
*
57
- * @return mixed
62
+ * @return \Illuminate\Database\Eloquent\Collection|static[]
58
63
*/
59
- public function findAllBy ($ attribute , $ value , $ columns = ['* ' ]);
64
+ public function findAllBy (string $ attribute , mixed $ value , array $ columns = ['* ' ]);
60
65
61
66
/**
62
67
* Find data by multiple fields
63
68
*
64
69
* @param array $where
65
70
* @param array $columns
66
71
*
67
- * @return mixed
72
+ * @return \Illuminate\Database\Eloquent\Collection|static[]
68
73
*/
69
- public function findWhere (array $ where , $ columns = ['* ' ]);
74
+ public function findWhere (array $ where , array $ columns = ['* ' ]);
70
75
71
76
/**
72
77
* Order results by.
73
78
*
74
- * @param string $column
75
- * @param string $direction
79
+ * @param mixed $column
80
+ * @param string|null $direction
76
81
*
77
- * @return self
82
+ * @return static
78
83
*/
79
- public function orderBy ($ column , $ direction );
84
+ public function orderBy (mixed $ column , string | null $ direction );
80
85
81
86
/**
82
87
* Filter results by given query params.
83
88
*
84
- * @param string $queries
89
+ * @param string|array $queries
85
90
*
86
- * @return self
91
+ * @return static
87
92
*/
88
- public function search ($ queries );
93
+ public function search (string | array $ queries );
89
94
90
95
/**
91
96
* Retrieve all data of repository
@@ -94,37 +99,37 @@ public function search($queries);
94
99
*
95
100
* @return Collection
96
101
*/
97
- public function all ($ columns = ['* ' ]);
102
+ public function all (array $ columns = ['* ' ]);
98
103
99
104
/**
100
105
* Get an array with the values of a given column.
101
106
*
102
- * @param string $value
103
- * @param string $key
107
+ * @param string $value
108
+ * @param string|null $key
104
109
*
105
- * @return array
110
+ * @return array<TKey, TValue>
106
111
*/
107
- public function pluck ($ value , $ key = null );
112
+ public function pluck (string $ value , string $ key = null );
108
113
109
114
/**
110
115
* Retrieve all data of repository, paginated
111
116
*
112
- * @param null $limit
113
- * @param array $columns
117
+ * @param mixed $per_page
118
+ * @param string| array $columns
114
119
*
115
120
* @return \Illuminate\Contracts\Pagination\Paginator
116
121
*/
117
- public function paginate ($ limit = null , $ columns = ['* ' ]);
122
+ public function paginate (mixed $ per_page = null , string | array $ columns = ['* ' ]);
118
123
119
124
/**
120
125
* Retrieve all data of repository, paginated
121
126
*
122
- * @param null $limit
123
- * @param array $columns
127
+ * @param mixed $per_page
128
+ * @param string| array $columns
124
129
*
125
130
* @return \Illuminate\Contracts\Pagination\Paginator
126
131
*/
127
- public function simplePaginate ($ limit = null , $ columns = ['* ' ]);
132
+ public function simplePaginate (mixed $ per_page = null , string | array $ columns = ['* ' ]);
128
133
129
134
/**
130
135
* Save a new entity in repository
@@ -151,10 +156,9 @@ public function update(Model $entity, array $attributes);
151
156
* @param mixed $entity
152
157
*
153
158
* @return bool|null
154
- *
155
159
* @throws \Exception
156
160
*/
157
- public function delete ($ entity );
161
+ public function delete (mixed $ entity );
158
162
159
163
/**
160
164
* Get the raw SQL statements for the request
@@ -169,9 +173,9 @@ public function toSql();
169
173
* @param string $message
170
174
* @param string $key
171
175
*
172
- * @return self
176
+ * @return static
173
177
*/
174
- public function addError ($ message , string $ key = 'message ' );
178
+ public function addError (string $ message , string $ key = 'message ' );
175
179
176
180
/**
177
181
* Get the repository's error messages.
@@ -187,5 +191,5 @@ public function getErrors();
187
191
*
188
192
* @return string
189
193
*/
190
- public function getErrorMessage ($ default = '' );
191
- }
194
+ public function getErrorMessage (string $ default = '' ): string ;
195
+ }
0 commit comments