Skip to content

Commit

Permalink
Merge pull request #5 from sinemacula/feature/initial-commit
Browse files Browse the repository at this point in the history
Feature/initial commit
  • Loading branch information
sinemacula-ben committed Apr 18, 2024
2 parents b489501 + df27fc3 commit 128b037
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ public function __call(string $method, array $arguments): mixed
}

/**
* Return the model class
* Reset the scopes.
*
* @return class-string
* @return static
*/
abstract public function model(): string;
public function resetScopes(): static
{
$this->scopes = [];

return $this;
}

/**
* Create a new model instance.
Expand All @@ -109,14 +114,11 @@ public function makeModel(): Model
}

/**
* Get the model instance.
* Return the model class
*
* @return \Illuminate\Database\Eloquent\Model
* @return class-string
*/
public function getModel(): Model
{
return $this->model;
}
abstract public function model(): string;

/**
* Reset the model instance.
Expand All @@ -128,6 +130,16 @@ public function resetModel(): void
$this->makeModel();
}

/**
* Get the model instance.
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function getModel(): Model
{
return $this->model;
}

/**
* Temporarily applies specified criteria to the next request only.
*
Expand Down Expand Up @@ -302,18 +314,6 @@ public function addScope(Closure $scope): static
return $this;
}

/**
* Reset the scopes.
*
* @return static
*/
public function resetScopes(): static
{
$this->scopes = [];

return $this;
}

/**
* Boot the repository instance.
*
Expand Down Expand Up @@ -374,53 +374,53 @@ protected function applyScopes(): static
}

/**
* Sanitize the given array of criteria to ensure they are valid criteria
* instances.
* Reset the various transient values and return the result.
*
* @param array $criteria
* @return array
* @param mixed $result
* @return mixed
*/
private function sanitizeCriteria(array $criteria): array
protected function resetAndReturn(mixed $result): mixed
{
return array_filter($criteria, fn ($criterion) => $criterion instanceof CriteriaInterface);
$this->resetTransientCriteria();
$this->resetScopes();
$this->resetModel();

return $result;
}

/**
* Clears all persistent criteria.
* Clears all transient criteria.
*
* @return static
*/
private function resetPersistentCriteria(): static
private function resetTransientCriteria(): static
{
$this->persistentCriteria = collect();
$this->transientCriteria = collect();

return $this;
}

/**
* Clears all transient criteria.
* Sanitize the given array of criteria to ensure they are valid criteria
* instances.
*
* @return static
* @param array $criteria
* @return array
*/
private function resetTransientCriteria(): static
private function sanitizeCriteria(array $criteria): array
{
$this->transientCriteria = collect();

return $this;
return array_filter($criteria, fn ($criterion) => $criterion instanceof CriteriaInterface);
}

/**
* Reset the various transient values and return the result.
* Clears all persistent criteria.
*
* @param mixed $result
* @return mixed
* @return static
*/
private function resetAndReturn(mixed $result): mixed
private function resetPersistentCriteria(): static
{
$this->resetTransientCriteria();
$this->resetScopes();
$this->resetModel();
$this->persistentCriteria = collect();

return $result;
return $this;
}
}

0 comments on commit 128b037

Please sign in to comment.