Skip to content

Commit ff1657c

Browse files
committed
Add #[Override] attribute to relationship classes
1 parent 357361e commit ff1657c

File tree

8 files changed

+69
-43
lines changed

8 files changed

+69
-43
lines changed

src/Relations/BelongsTo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Eloquent\Builder;
88
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Database\Eloquent\Relations\BelongsTo as EloquentBelongsTo;
10+
use Override;
1011

1112
/**
1213
* @template TRelatedModel of Model
@@ -26,6 +27,7 @@ public function getHasCompareKey()
2627
}
2728

2829
/** @inheritdoc */
30+
#[Override]
2931
public function addConstraints()
3032
{
3133
if (static::$constraints) {
@@ -37,6 +39,7 @@ public function addConstraints()
3739
}
3840

3941
/** @inheritdoc */
42+
#[Override]
4043
public function addEagerConstraints(array $models)
4144
{
4245
// We'll grab the primary key name of the related models since it could be set to
@@ -46,6 +49,7 @@ public function addEagerConstraints(array $models)
4649
}
4750

4851
/** @inheritdoc */
52+
#[Override]
4953
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
5054
{
5155
return $query;
@@ -58,11 +62,13 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
5862
*
5963
* @return string
6064
*/
65+
#[Override]
6166
protected function whereInMethod(Model $model, $key)
6267
{
6368
return 'whereIn';
6469
}
6570

71+
#[Override]
6672
public function getQualifiedForeignKeyName(): string
6773
{
6874
return $this->foreignKey;

src/Relations/BelongsToMany.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
1111
use Illuminate\Support\Arr;
1212
use MongoDB\Laravel\Eloquent\Model as DocumentModel;
13+
use Override;
1314

1415
use function array_diff;
1516
use function array_keys;
@@ -39,12 +40,14 @@ public function getHasCompareKey()
3940
}
4041

4142
/** @inheritdoc */
43+
#[Override]
4244
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
4345
{
4446
return $query;
4547
}
4648

4749
/** @inheritdoc */
50+
#[Override]
4851
protected function hydratePivotRelation(array $models)
4952
{
5053
// Do nothing.
@@ -61,12 +64,14 @@ protected function getSelectColumns(array $columns = ['*'])
6164
}
6265

6366
/** @inheritdoc */
67+
#[Override]
6468
protected function shouldSelect(array $columns = ['*'])
6569
{
6670
return $columns;
6771
}
6872

6973
/** @inheritdoc */
74+
#[Override]
7075
public function addConstraints()
7176
{
7277
if (static::$constraints) {
@@ -89,6 +94,7 @@ protected function setWhere()
8994
}
9095

9196
/** @inheritdoc */
97+
#[Override]
9298
public function save(Model $model, array $pivotAttributes = [], $touch = true)
9399
{
94100
$model->save(['touch' => false]);
@@ -99,6 +105,7 @@ public function save(Model $model, array $pivotAttributes = [], $touch = true)
99105
}
100106

101107
/** @inheritdoc */
108+
#[Override]
102109
public function create(array $attributes = [], array $joining = [], $touch = true)
103110
{
104111
$instance = $this->related->newInstance($attributes);
@@ -114,6 +121,7 @@ public function create(array $attributes = [], array $joining = [], $touch = tru
114121
}
115122

116123
/** @inheritdoc */
124+
#[Override]
117125
public function sync($ids, $detaching = true)
118126
{
119127
$changes = [
@@ -177,13 +185,15 @@ public function sync($ids, $detaching = true)
177185
}
178186

179187
/** @inheritdoc */
188+
#[Override]
180189
public function updateExistingPivot($id, array $attributes, $touch = true)
181190
{
182191
// Do nothing, we have no pivot table.
183192
return $this;
184193
}
185194

186195
/** @inheritdoc */
196+
#[Override]
187197
public function attach($id, array $attributes = [], $touch = true)
188198
{
189199
if ($id instanceof Model) {
@@ -224,6 +234,7 @@ public function attach($id, array $attributes = [], $touch = true)
224234
}
225235

226236
/** @inheritdoc */
237+
#[Override]
227238
public function detach($ids = [], $touch = true)
228239
{
229240
if ($ids instanceof Model) {
@@ -264,6 +275,7 @@ public function detach($ids = [], $touch = true)
264275
}
265276

266277
/** @inheritdoc */
278+
#[Override]
267279
protected function buildDictionary(Collection $results)
268280
{
269281
$foreign = $this->foreignPivotKey;
@@ -283,6 +295,7 @@ protected function buildDictionary(Collection $results)
283295
}
284296

285297
/** @inheritdoc */
298+
#[Override]
286299
public function newPivotQuery()
287300
{
288301
return $this->newRelatedQuery();
@@ -309,12 +322,14 @@ public function getForeignKey()
309322
}
310323

311324
/** @inheritdoc */
325+
#[Override]
312326
public function getQualifiedForeignPivotKeyName()
313327
{
314328
return $this->foreignPivotKey;
315329
}
316330

317331
/** @inheritdoc */
332+
#[Override]
318333
public function getQualifiedRelatedPivotKeyName()
319334
{
320335
return $this->relatedPivotKey;
@@ -323,10 +338,9 @@ public function getQualifiedRelatedPivotKeyName()
323338
/**
324339
* Get the name of the "where in" method for eager loading.
325340
*
326-
* @param string $key
327-
*
328-
* @return string
341+
* @inheritdoc
329342
*/
343+
#[Override]
330344
protected function whereInMethod(Model $model, $key)
331345
{
332346
return 'whereIn';

src/Relations/EmbedsOneOrMany.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Database\Query\Expression;
1313
use MongoDB\Driver\Exception\LogicException;
1414
use MongoDB\Laravel\Eloquent\Model as DocumentModel;
15+
use Override;
1516
use Throwable;
1617

1718
use function array_merge;
@@ -78,6 +79,7 @@ public function __construct(Builder $query, Model $parent, Model $related, strin
7879
}
7980

8081
/** @inheritdoc */
82+
#[Override]
8183
public function addConstraints()
8284
{
8385
if (static::$constraints) {
@@ -86,12 +88,14 @@ public function addConstraints()
8688
}
8789

8890
/** @inheritdoc */
91+
#[Override]
8992
public function addEagerConstraints(array $models)
9093
{
9194
// There are no eager loading constraints.
9295
}
9396

9497
/** @inheritdoc */
98+
#[Override]
9599
public function match(array $models, Collection $results, $relation)
96100
{
97101
foreach ($models as $model) {
@@ -105,13 +109,8 @@ public function match(array $models, Collection $results, $relation)
105109
return $models;
106110
}
107111

108-
/**
109-
* Shorthand to get the results of the relationship.
110-
*
111-
* @param array $columns
112-
*
113-
* @return Collection
114-
*/
112+
/** Shorthand to get the results of the relationship. */
113+
#[Override]
115114
public function get($columns = ['*'])
116115
{
117116
return $this->getResults();
@@ -324,6 +323,7 @@ protected function getParentRelation()
324323
}
325324

326325
/** @inheritdoc */
326+
#[Override]
327327
public function getQuery()
328328
{
329329
// Because we are sharing this relation instance to models, we need
@@ -332,6 +332,7 @@ public function getQuery()
332332
}
333333

334334
/** @inheritdoc */
335+
#[Override]
335336
public function toBase()
336337
{
337338
// Because we are sharing this relation instance to models, we need
@@ -367,6 +368,7 @@ protected function getPathHierarchy($glue = '.')
367368
}
368369

369370
/** @inheritdoc */
371+
#[Override]
370372
public function getQualifiedParentKeyName()
371373
{
372374
$parentRelation = $this->getParentRelation();
@@ -425,10 +427,10 @@ public function getQualifiedForeignKeyName()
425427
* Get the name of the "where in" method for eager loading.
426428
*
427429
* @param EloquentModel $model
428-
* @param string $key
429430
*
430-
* @return string
431+
* @inheritdoc
431432
*/
433+
#[Override]
432434
protected function whereInMethod(EloquentModel $model, $key)
433435
{
434436
return 'whereIn';

src/Relations/HasMany.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Eloquent\Builder;
88
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany;
10+
use Override;
1011

1112
/**
1213
* @template TRelatedModel of Model
@@ -20,6 +21,7 @@ class HasMany extends EloquentHasMany
2021
*
2122
* @return string
2223
*/
24+
#[Override]
2325
public function getForeignKeyName()
2426
{
2527
return $this->foreignKey;
@@ -36,6 +38,7 @@ public function getHasCompareKey()
3638
}
3739

3840
/** @inheritdoc */
41+
#[Override]
3942
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
4043
{
4144
$foreignKey = $this->getHasCompareKey();
@@ -46,10 +49,9 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
4649
/**
4750
* Get the name of the "where in" method for eager loading.
4851
*
49-
* @param string $key
50-
*
51-
* @return string
52+
* @inheritdoc
5253
*/
54+
#[Override]
5355
protected function whereInMethod(Model $model, $key)
5456
{
5557
return 'whereIn';

src/Relations/HasOne.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Eloquent\Builder;
88
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
10+
use Override;
1011

1112
/**
1213
* @template TRelatedModel of Model
@@ -20,6 +21,7 @@ class HasOne extends EloquentHasOne
2021
*
2122
* @return string
2223
*/
24+
#[Override]
2325
public function getForeignKeyName()
2426
{
2527
return $this->foreignKey;
@@ -36,20 +38,16 @@ public function getHasCompareKey()
3638
}
3739

3840
/** @inheritdoc */
41+
#[Override]
3942
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
4043
{
4144
$foreignKey = $this->getForeignKeyName();
4245

4346
return $query->select($foreignKey)->where($foreignKey, 'exists', true);
4447
}
4548

46-
/**
47-
* Get the name of the "where in" method for eager loading.
48-
*
49-
* @param string $key
50-
*
51-
* @return string
52-
*/
49+
/** Get the name of the "where in" method for eager loading. */
50+
#[Override]
5351
protected function whereInMethod(Model $model, $key)
5452
{
5553
return 'whereIn';

src/Relations/MorphMany.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Relations\MorphMany as EloquentMorphMany;
9+
use Override;
910

1011
/**
1112
* @template TRelatedModel of Model
@@ -14,13 +15,8 @@
1415
*/
1516
class MorphMany extends EloquentMorphMany
1617
{
17-
/**
18-
* Get the name of the "where in" method for eager loading.
19-
*
20-
* @param string $key
21-
*
22-
* @return string
23-
*/
18+
/** Get the name of the "where in" method for eager loading. */
19+
#[Override]
2420
protected function whereInMethod(Model $model, $key)
2521
{
2622
return 'whereIn';

0 commit comments

Comments
 (0)