Skip to content

Commit

Permalink
nullable type declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Dec 10, 2023
1 parent 64d0343 commit c3bfce8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/BaseEloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function getDisplayField(): string
/**
* {@inheritDoc}
*/
public function findOne(int|string $primaryKey = null): ?Model
public function findOne(int|string|null $primaryKey = null): ?Model
{
if (func_num_args() > 0) {
$this->applyConditions(['id' => $primaryKey]);
Expand All @@ -68,7 +68,7 @@ public function findOne(int|string $primaryKey = null): ?Model
/**
* {@inheritDoc}
*/
public function findOneOrFail(int|string $primaryKey = null): Model
public function findOneOrFail(int|string|null $primaryKey = null): Model
{
if (func_num_args() > 0) {
$this->applyConditions(['id' => $primaryKey]);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function findAll(array $options = []): EloquentCollection
/**
* {@inheritDoc}
*/
public function findList(string $key = null, string $value = null): Collection
public function findList(?string $key = null, ?string $value = null): Collection
{
$this->applyCriteria();
$this->applyRelations();
Expand All @@ -138,7 +138,7 @@ public function findList(string $key = null, string $value = null): Collection
/**
* {@inheritDoc}
*/
public function paginate(int $perPage = null): Paginator
public function paginate(?int $perPage = null): Paginator
{
$perPage = $this->preparePageSize($perPage);

Expand All @@ -156,7 +156,7 @@ public function paginate(int $perPage = null): Paginator
*
* @throws \InvalidArgumentException
*/
protected function preparePageSize(int $perPage = null): int
protected function preparePageSize(?int $perPage = null): int
{
if ($perPage <= 0) {
throw new InvalidArgumentException('Invalid page size');
Expand Down
8 changes: 4 additions & 4 deletions src/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ interface RepositoryInterface
* It applies the conditions, criteria, relations, and order by to the query,
* then gets the first result and resets the query
*/
public function findOne(int|string $primaryKey = null): ?Model;
public function findOne(int|string|null $primaryKey = null): ?Model;

/**
* If the result of the `findOne` function is null, throw a `ModelNotFoundException`
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function findOneOrFail(int|string $primaryKey = null): Model;
public function findOneOrFail(int|string|null $primaryKey = null): Model;

/**
* It takes an array of options, applies them to the query, executes the query, and returns the results.
Expand All @@ -36,12 +36,12 @@ public function findAll(array $options = []): EloquentCollection;
* @param string|null $value The field to use as the value of the select list.
* @return \Illuminate\Support\Collection A collection of key value pairs.
*/
public function findList(string $key = null, string $value = null): Collection;
public function findList(?string $key = null, ?string $value = null): Collection;

/**
* It applies the criteria, relations, and order by to the query, then paginates the results and resets the query
*/
public function paginate(int $perPage = null): Paginator;
public function paginate(?int $perPage = null): Paginator;

/**
* Add a criteria to the query.
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/SearchableRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface SearchableRepositoryInterface
/**
* Search for records based on the provided query parameters and paginate the results.
*/
public function search(array $queryParams, int $perPage = null): Paginator;
public function search(array $queryParams, ?int $perPage = null): Paginator;
}
2 changes: 1 addition & 1 deletion src/Traits/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait Searchable
{
abstract protected function getFilterManager(): BaseFilter;

public function search(array $queryParams, int $perPage = null): Paginator
public function search(array $queryParams, ?int $perPage = null): Paginator
{
$this->setQuery($this->getFilterManager()->applyFilter($queryParams));

Expand Down

0 comments on commit c3bfce8

Please sign in to comment.