Skip to content

Commit 7853d42

Browse files
committed
Added type-hinted return
1 parent e2840b3 commit 7853d42

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

src/Contracts/RepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function findWhereBetween($field, array $values, $columns = ['*']);
3232

3333
public function create(array $attributes);
3434

35-
public function update(array $attributes, $id);
35+
public function update(array $attributes, int $id);
3636

3737
public function updateOrCreate(array $attributes, array $values = []);
3838

src/Eloquent/BaseRepository.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public function makeModel(): Model
6767
return $this->model = $model;
6868
}
6969

70-
public function scopeQuery(\Closure $scope): BaseRepository
70+
public function scopeQuery(Closure $scope): BaseRepository
7171
{
7272
return tap($this, function () use ($scope) {
7373
$this->scopeQuery = $scope;
7474
});
7575
}
7676

77-
public function pluck($column, $key = null)
77+
public function pluck($column, $key = null): Collection
7878
{
7979
return $this->model->pluck($column, $key);
8080
}
@@ -89,7 +89,7 @@ public function syncWithoutDetaching($id, $relation, $attributes)
8989
return $this->sync($id, $relation, $attributes, false);
9090
}
9191

92-
public function all($columns = ['*'])
92+
public function all($columns = ['*']): Collection|array
9393
{
9494
$this->applyScope();
9595

@@ -101,7 +101,7 @@ public function all($columns = ['*'])
101101
return $results;
102102
}
103103

104-
public function count(array $where = [], $columns = '*')
104+
public function count(array $where = [], $columns = '*'): int
105105
{
106106
$this->applyScope();
107107

@@ -115,12 +115,12 @@ public function count(array $where = [], $columns = '*')
115115
return $result;
116116
}
117117

118-
public function get($columns = ['*']): array|Collection
118+
public function get($columns = ['*']): Collection|array
119119
{
120120
return $this->all($columns);
121121
}
122122

123-
public function first($columns = ['*'])
123+
public function first($columns = ['*']): Model|Builder
124124
{
125125
$this->applyScope();
126126

@@ -131,7 +131,7 @@ public function first($columns = ['*'])
131131
return $result;
132132
}
133133

134-
public function firstOrNew(array $attributes = [])
134+
public function firstOrNew(array $attributes = []): Model|Builder
135135
{
136136
$this->applyScope();
137137

@@ -142,7 +142,7 @@ public function firstOrNew(array $attributes = [])
142142
return $model;
143143
}
144144

145-
public function firstOrCreate(array $attributes = [])
145+
public function firstOrCreate(array $attributes = []): Model|Builder
146146
{
147147
$this->applyScope();
148148

@@ -159,7 +159,7 @@ public function limit($limit, $columns = ['*']): array|Collection
159159
return $this->all($columns);
160160
}
161161

162-
public function paginate($limit = null, $columns = ['*'], $method = "paginate")
162+
public function paginate($limit = null, $columns = ['*'], $method = "paginate"): mixed
163163
{
164164
$this->applyScope();
165165

@@ -179,7 +179,7 @@ public function simplePaginate($limit = null, $columns = ['*'])
179179
return $this->paginate($limit, $columns, "simplePaginate");
180180
}
181181

182-
public function find(int $id, $columns = ['*'])
182+
public function find(int $id, $columns = ['*']): Model|Builder
183183
{
184184
$this->applyScope();
185185
$model = $this->model->findOrFail($id, $columns);
@@ -188,7 +188,7 @@ public function find(int $id, $columns = ['*'])
188188
return $model;
189189
}
190190

191-
public function findByField(string $field, $value = null, $columns = ['*'])
191+
public function findByField(string $field, $value = null, $columns = ['*']): Collection|array
192192
{
193193
$this->applyScope();
194194
$model = $this->model->where($field, '=', $value)->get($columns);
@@ -197,7 +197,7 @@ public function findByField(string $field, $value = null, $columns = ['*'])
197197
return $model;
198198
}
199199

200-
public function findWhere(array $where, $columns = ['*'])
200+
public function findWhere(array $where, $columns = ['*']): Collection|array
201201
{
202202
$this->applyScope();
203203
$this->applyConditions($where);
@@ -207,7 +207,7 @@ public function findWhere(array $where, $columns = ['*'])
207207
return $model;
208208
}
209209

210-
public function findWhereIn($field, array $values, $columns = ['*'])
210+
public function findWhereIn($field, array $values, $columns = ['*']): Collection|array
211211
{
212212
$this->applyScope();
213213
$model = $this->model->whereIn($field, $values)->get($columns);
@@ -216,7 +216,7 @@ public function findWhereIn($field, array $values, $columns = ['*'])
216216
return $model;
217217
}
218218

219-
public function findWhereNotIn($field, array $values, $columns = ['*'])
219+
public function findWhereNotIn($field, array $values, $columns = ['*']): Collection|array
220220
{
221221
$this->applyScope();
222222
$model = $this->model->whereNotIn($field, $values)->get($columns);
@@ -225,7 +225,7 @@ public function findWhereNotIn($field, array $values, $columns = ['*'])
225225
return $model;
226226
}
227227

228-
public function findWhereBetween($field, array $values, $columns = ['*'])
228+
public function findWhereBetween($field, array $values, $columns = ['*']): Collection|array
229229
{
230230
$this->applyScope();
231231
$model = $this->model->whereBetween($field, $values)->get($columns);
@@ -245,7 +245,7 @@ public function create(array $attributes): Model
245245
return $model;
246246
}
247247

248-
public function update(array $attributes, $id)
248+
public function update(array $attributes, int $id): Model
249249
{
250250
$this->applyScope();
251251

@@ -258,7 +258,7 @@ public function update(array $attributes, $id)
258258
return $model;
259259
}
260260

261-
public function updateOrCreate(array $attributes, array $values = [])
261+
public function updateOrCreate(array $attributes, array $values = []): Model|Builder
262262
{
263263
$this->applyScope();
264264

@@ -334,7 +334,7 @@ public function hidden(array $fields): BaseRepository
334334
});
335335
}
336336

337-
public function visible(array $fields)
337+
public function visible(array $fields): BaseRepository
338338
{
339339
return tap($this, function () use ($fields) {
340340
$this->model->setVisible($fields);

src/Traits/Cacheable.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use CodeOfDigital\CacheRepository\Helpers\CacheKeys;
66
use Illuminate\Contracts\Cache\Repository as CacheRepository;
7+
use Illuminate\Database\Eloquent\Builder;
8+
use Illuminate\Database\Eloquent\Collection;
9+
use Illuminate\Database\Eloquent\Model;
710
use Illuminate\Support\Facades\Config;
811

912
trait Cacheable
@@ -108,7 +111,7 @@ public function getCacheTTL(): float|int
108111
return Config::get('repository.cache.minutes', 30) * 60;
109112
}
110113

111-
public function all($columns = ['*'])
114+
public function all($columns = ['*']): Collection|array
112115
{
113116
if (!$this->allowedCache('all') || $this->isSkippedCache())
114117
return parent::all($columns);
@@ -125,7 +128,7 @@ public function all($columns = ['*'])
125128
return $value;
126129
}
127130

128-
public function paginate($limit = null, $columns = ['*'], $method = 'paginate')
131+
public function paginate($limit = null, $columns = ['*'], $method = 'paginate'): mixed
129132
{
130133
if (!$this->allowedCache('paginate') || $this->isSkippedCache()) {
131134
return parent::paginate($limit, $columns, $method);
@@ -143,7 +146,7 @@ public function paginate($limit = null, $columns = ['*'], $method = 'paginate')
143146
return $value;
144147
}
145148

146-
public function find(int $id, $columns = ['*'])
149+
public function find(int $id, $columns = ['*']): Model|Builder
147150
{
148151
if (!$this->allowedCache('find') || $this->isSkippedCache()) {
149152
return parent::find($id, $columns);
@@ -161,7 +164,7 @@ public function find(int $id, $columns = ['*'])
161164
return $value;
162165
}
163166

164-
public function findByField(string $field, $value = null, $columns = ['*'])
167+
public function findByField(string $field, $value = null, $columns = ['*']): Collection|array
165168
{
166169
if (!$this->allowedCache('findByField') || $this->isSkippedCache()) {
167170
return parent::findByField($field, $columns);
@@ -179,7 +182,7 @@ public function findByField(string $field, $value = null, $columns = ['*'])
179182
return $value;
180183
}
181184

182-
public function findWhere(array $where, $columns = ['*'])
185+
public function findWhere(array $where, $columns = ['*']): Collection|array
183186
{
184187
if (!$this->allowedCache('findWhere') || $this->isSkippedCache()) {
185188
return parent::findWhere($where, $columns);

0 commit comments

Comments
 (0)