Skip to content

Commit

Permalink
feat(Database): Improve phpstan support for scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Mar 8, 2024
1 parent 58d654c commit 64d2322
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/Database/Scopes/AbstractInScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public function __construct(
$this->not = $not;
}

/**
* @param Builder<Model> $builder
*/
public function apply(Builder $builder, Model $model): void
{
$column = $this->table === '' ? $this->getColumn($model) : $this->table . '.' . $this->getColumn($model);
Expand Down
21 changes: 17 additions & 4 deletions src/Database/Scopes/AbstractScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@
abstract class AbstractScope implements Scope
{
/**
* @param Builder<Model> $builder
* @template TModel of Model
* @param Builder<TModel> $builder
*/
abstract public function apply(Builder $builder, Model $model): void;

/**
* @param Relation<Model> $relation
* @template TModel of Model
* @param Relation<TModel> $relation
*/
public function applyOnRelation(Relation $relation): void
{
$this->applyRelationScope($this, $relation);
}

/**
* @template TModel of Model
* @param Builder<TModel> $builder
*/
public function applyOnBuilder(Builder $builder): void
{
$this->apply($builder, $builder->getModel());
}

/**
* Apply scope that contains with query and eager load relations to the model.
*/
Expand All @@ -35,15 +46,17 @@ public function eagerLoadRelationsFromScope(Model $model): void
}

/**
* @param Builder<Model> $builder
* @template TModel of Model
* @param Builder<TModel> $builder
*/
protected function applyChildScope(Scope $scope, Builder $builder, Model $model): void
{
$scope->apply($builder, $model);
}

/**
* @param Relation<Model> $relation
* @template TModel of Model
* @param Relation<TModel> $relation
*/
protected function applyRelationScope(Scope $scope, Relation $relation): void
{
Expand Down

0 comments on commit 64d2322

Please sign in to comment.