32
32
* by other columns, by marking the Criteria that does the ordering with key 'order'.
33
33
*
34
34
* @template TModel of \Illuminate\Database\Eloquent\Model
35
+ *
36
+ * @implements BaseRepositoryInterface<TModel>
35
37
*/
36
38
abstract class BaseRepository implements BaseRepositoryInterface
37
39
{
38
40
protected ContainerInterface $ app ;
39
41
40
42
/**
41
- * @var TModel|Model| EloquentBuilder|BaseBuilder
43
+ * @var TModel|EloquentBuilder<TModel> |BaseBuilder
42
44
*/
43
45
protected Model |EloquentBuilder |BaseBuilder $ modelOrQuery ;
44
46
45
47
/**
46
48
* Criteria to keep and use for all coming queries
47
49
*
48
- * @var Collection<int|string, CriteriaInterface>
50
+ * @var Collection<int|string, CriteriaInterface<TModel, Model> >
49
51
*/
50
52
protected Collection $ criteria ;
51
53
52
54
/**
53
55
* The Criteria to only apply to the next query
54
56
*
55
- * @var Collection<int|string, CriteriaInterface>
57
+ * @var Collection<int|string, CriteriaInterface<TModel, Model> >
56
58
*/
57
59
protected Collection $ onceCriteria ;
58
60
@@ -61,7 +63,7 @@ abstract class BaseRepository implements BaseRepositoryInterface
61
63
* So this is a dynamic list that can change during calls of various repository
62
64
* methods that alter the active criteria.
63
65
*
64
- * @var Collection<int|string, CriteriaInterface>
66
+ * @var Collection<int|string, CriteriaInterface<TModel, Model> >
65
67
*/
66
68
protected Collection $ activeCriteria ;
67
69
@@ -81,8 +83,8 @@ abstract class BaseRepository implements BaseRepositoryInterface
81
83
82
84
83
85
/**
84
- * @param ContainerInterface $container
85
- * @param Collection<int|string, CriteriaInterface> $initialCriteria
86
+ * @param ContainerInterface $container
87
+ * @param Collection<int|string, CriteriaInterface<TModel, Model> > $initialCriteria
86
88
* @throws RepositoryException
87
89
*/
88
90
public function __construct (ContainerInterface $ container , Collection $ initialCriteria )
@@ -148,7 +150,7 @@ public function makeModel(bool $storeModel = true): Model
148
150
/**
149
151
* Give unexecuted (fresh) query wioth the current applied criteria.
150
152
*
151
- * @return EloquentBuilder|BaseBuilder
153
+ * @return EloquentBuilder<TModel> |BaseBuilder
152
154
* @throws RepositoryException
153
155
*/
154
156
public function query (): EloquentBuilder |BaseBuilder
@@ -299,10 +301,11 @@ public function findAllBy(string $attribute, mixed $value, $columns = ['*']): El
299
301
* @param array<string, callable|array<int, string>|mixed> $where
300
302
* @param string[] $columns
301
303
* @param bool $or
302
- * @return EloquentCollection
304
+ * @return EloquentCollection<int, TModel>
303
305
*/
304
306
public function findWhere (array $ where , array $ columns = ['* ' ], bool $ or = false ): EloquentCollection
305
307
{
308
+ /** @var EloquentBuilder<TModel> $model */
306
309
$ model = $ this ->query ();
307
310
308
311
foreach ($ where as $ field => $ value ) {
@@ -386,7 +389,7 @@ public function update(array $data, int|string $id, ?string $attribute = null):
386
389
* @param array<string, mixed> $data
387
390
* @param int|string $id
388
391
* @param string|null $attribute
389
- * @return Model |false
392
+ * @return TModel |false
390
393
* @throws MassAssignmentException|ModelNotFoundException
391
394
*/
392
395
public function fill (array $ data , int |string $ id , ?string $ attribute = null ): Model |false
@@ -429,7 +432,7 @@ public function allCallback(Closure $callback, array $columns = ['*']): Eloquent
429
432
430
433
$ this ->assertValidCustomCallback ($ result );
431
434
432
- /** @var EloquentBuilder|BaseBuilder $result */
435
+ /** @var EloquentBuilder<TModel> |BaseBuilder $result */
433
436
return $ result ->get ($ columns );
434
437
}
435
438
@@ -447,7 +450,7 @@ public function findCallback(Closure $callback, array $columns = ['*']): ?Model
447
450
448
451
$ this ->assertValidCustomCallback ($ result );
449
452
450
- /** @var EloquentBuilder|BaseBuilder $result */
453
+ /** @var EloquentBuilder<TModel> |BaseBuilder $result */
451
454
return $ result ->first ($ columns );
452
455
}
453
456
@@ -469,7 +472,7 @@ public function findCallback(Closure $callback, array $columns = ['*']): ?Model
469
472
* Override with your own defaults (check ExtendedRepository's refreshed,
470
473
* named Criteria for examples).
471
474
*
472
- * @return Collection<int|string, CriteriaInterface>
475
+ * @return Collection<int|string, CriteriaInterface<TModel, Model> >
473
476
*/
474
477
public function defaultCriteria (): Collection
475
478
{
@@ -504,7 +507,7 @@ public function ignoreCriteria(bool $ignore = true): void
504
507
* Returns a cloned set of all currently set criteria (not including
505
508
* those to be applied once).
506
509
*
507
- * @return Collection<int|string, CriteriaInterface>
510
+ * @return Collection<int|string, CriteriaInterface<TModel, Model> >
508
511
*/
509
512
public function getCriteria (): Collection
510
513
{
@@ -514,7 +517,7 @@ public function getCriteria(): Collection
514
517
/**
515
518
* Returns a cloned set of all currently set once criteria.
516
519
*
517
- * @return Collection<int|string, CriteriaInterface>
520
+ * @return Collection<int|string, CriteriaInterface<TModel, Model> >
518
521
*/
519
522
public function getOnceCriteria (): Collection
520
523
{
@@ -524,7 +527,7 @@ public function getOnceCriteria(): Collection
524
527
/**
525
528
* Returns a cloned set of all currently set criteria (not including those to be applied once).
526
529
*
527
- * @return Collection<int|string, CriteriaInterface>
530
+ * @return Collection<int|string, CriteriaInterface<TModel, Model> >
528
531
*/
529
532
public function getAllCriteria (): Collection
530
533
{
@@ -575,8 +578,8 @@ public function applyCriteria(): void
575
578
* If a criteria already exists for the key, it is overridden.
576
579
* Note that this does NOT overrule any onceCriteria, even if set by key!
577
580
*
578
- * @param CriteriaInterface $criteria
579
- * @param string|null $key Unique identifier, may be used to remove and overwrite criteria
581
+ * @param CriteriaInterface<TModel, Model> $criteria
582
+ * @param string|null $key Unique identifier, may be used to remove and overwrite criteria
580
583
*/
581
584
public function pushCriteria (CriteriaInterface $ criteria , ?string $ key = null ): void
582
585
{
@@ -600,8 +603,8 @@ public function removeCriteria(string $key): void
600
603
*
601
604
* Note that this does NOT work for specific criteria exclusively, it resets to default for ALL Criteria.
602
605
*
603
- * @param CriteriaInterface $criteria
604
- * @param string|null $key
606
+ * @param CriteriaInterface<TModel, Model> $criteria
607
+ * @param string|null $key
605
608
* @return $this
606
609
*/
607
610
public function pushCriteriaOnce (CriteriaInterface $ criteria , ?string $ key = null ): static
@@ -636,15 +639,19 @@ public function removeCriteriaOnce(string $key): static
636
639
}
637
640
638
641
// Override by key with null-value.
639
- $ this ->onceCriteria ->put ($ key , new NullCriteria ());
642
+ /** @var NullCriteria<TModel, Model> $nullCriterion */
643
+ $ nullCriterion = new NullCriteria ();
644
+
645
+ $ this ->onceCriteria ->put ($ key , $ nullCriterion );
646
+
640
647
return $ this ;
641
648
}
642
649
643
650
644
651
/**
645
652
* Returns the criteria that must be applied for the next query.
646
653
*
647
- * @return Collection<int|string, CriteriaInterface>
654
+ * @return Collection<int|string, CriteriaInterface<TModel, Model> >
648
655
*/
649
656
protected function getCriteriaToApply (): Collection
650
657
{
0 commit comments