Skip to content

Commit

Permalink
Merge pull request #40 from FourFourAI/use-instanceof
Browse files Browse the repository at this point in the history
Use instanceof instead of $this::class
  • Loading branch information
biiiiiigmonster authored Mar 11, 2024
2 parents 94d7626 + bcb5798 commit 0fad18d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Database/Eloquent/RelationMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ public function getRelationExistenceInQuery(): Closure
return $relation($query, $parentQuery, $columns);
};

return match ($this::class) {
MorphMany::class => $morphOneOrMany($query, $parentQuery),
BelongsTo::class, MorphTo::class => $belongsTo($query, $parentQuery),
HasMany::class, => $hasOneOrMany($query, $parentQuery),
HasOne::class => $hasOne($query, $parentQuery),
MorphOne::class => $morphOne($query, $parentQuery),
BelongsToMany::class => $belongsToMany($query, $parentQuery),
MorphToMany::class => $morphToMany($query, $parentQuery),
HasOneThrough::class, HasManyThrough::class => $hasManyThrough($query, $parentQuery),
return match (true) {
$this instanceof MorphMany => $morphOneOrMany($query, $parentQuery),
$this instanceof BelongsTo, $this instanceof MorphTo => $belongsTo($query, $parentQuery),
$this instanceof HasMany => $hasOneOrMany($query, $parentQuery),
$this instanceof HasOne => $hasOne($query, $parentQuery),
$this instanceof MorphOne => $morphOne($query, $parentQuery),
$this instanceof BelongsToMany => $belongsToMany($query, $parentQuery),
$this instanceof MorphToMany => $morphToMany($query, $parentQuery),
$this instanceof HasOneThrough, $this instanceof HasManyThrough => $hasManyThrough($query, $parentQuery),
default => throw new LogicException(
sprintf('%s must be a relationship instance.', $this::class)
)
Expand All @@ -140,11 +140,11 @@ public function getRelationExistenceInQuery(): Closure

public function getRelationWhereInKey(): Closure
{
return fn (): string => match ($this::class) {
BelongsTo::class, MorphTo::class => $this->getQualifiedForeignKeyName(),
HasOne::class, HasMany::class, BelongsToMany::class,
MorphMany::class, MorphOne::class, MorphToMany::class => $this->getQualifiedParentKeyName(),
HasOneThrough::class, HasManyThrough::class => $this->getQualifiedLocalKeyName(),
return fn (): string => match (true) {
$this instanceof BelongsTo, $this instanceof MorphTo => $this->getQualifiedForeignKeyName(),
$this instanceof HasOne, $this instanceof HasMany, $this instanceof BelongsToMany,
$this instanceof MorphMany, $this instanceof MorphOne, $this instanceof MorphToMany => $this->getQualifiedParentKeyName(),
$this instanceof HasOneThrough, $this instanceof HasManyThrough => $this->getQualifiedLocalKeyName(),
default => throw new LogicException(
sprintf('%s must be a relationship instance.', $this::class)
)
Expand Down

0 comments on commit 0fad18d

Please sign in to comment.