Skip to content

Commit

Permalink
Security updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Torann committed Feb 23, 2023
1 parent 5ece5e5 commit e644af4
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 183 deletions.
84 changes: 44 additions & 40 deletions src/Contracts/RepositoryContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
namespace Torann\LaravelRepository\Contracts;

use Illuminate\Support\Collection;
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Eloquent\Model;

/**
* @template TKey of array-key
* @template TValue
*
* @implements \ArrayAccess<TKey, TValue>
*/
interface RepositoryContract
{
/**
* Return model instance.
*
* @return Model
*/
public function getModel();
public function getModel(): Model;

/**
* Find data by id
Expand All @@ -23,29 +28,29 @@ public function getModel();
*
* @return Model|Collection
*/
public function find($id, $columns = ['*']);
public function find(mixed $id, array $columns = ['*']);

/**
* Find a model by its primary key or throw an exception.
*
* @para string $id
*
* @return \Illuminate\Database\Eloquent\Model
* @param string $id
* @param array $columns
*
* @return Model
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function findOrFail($id);
public function findOrFail(string $id, array $columns = ['*']);

/**
* Find data by field and value
*
* @param $field
* @param $value
* @param array $columns
* @param string $field
* @param string $value
* @param array $columns
*
* @return Model|Collection
* @return Model|object|static|null
*/
public function findBy($field, $value, $columns = ['*']);
public function findBy(string $field, string $value, array $columns = ['*']);

/**
* Find data by field
Expand All @@ -54,38 +59,38 @@ public function findBy($field, $value, $columns = ['*']);
* @param mixed $value
* @param array $columns
*
* @return mixed
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function findAllBy($attribute, $value, $columns = ['*']);
public function findAllBy(string $attribute, mixed $value, array $columns = ['*']);

/**
* Find data by multiple fields
*
* @param array $where
* @param array $columns
*
* @return mixed
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function findWhere(array $where, $columns = ['*']);
public function findWhere(array $where, array $columns = ['*']);

/**
* Order results by.
*
* @param string $column
* @param string $direction
* @param mixed $column
* @param string|null $direction
*
* @return self
* @return static
*/
public function orderBy($column, $direction);
public function orderBy(mixed $column, string|null $direction);

/**
* Filter results by given query params.
*
* @param string $queries
* @param string|array $queries
*
* @return self
* @return static
*/
public function search($queries);
public function search(string|array $queries);

/**
* Retrieve all data of repository
Expand All @@ -94,37 +99,37 @@ public function search($queries);
*
* @return Collection
*/
public function all($columns = ['*']);
public function all(array $columns = ['*']);

/**
* Get an array with the values of a given column.
*
* @param string $value
* @param string $key
* @param string $value
* @param string|null $key
*
* @return array
* @return array<TKey, TValue>
*/
public function pluck($value, $key = null);
public function pluck(string $value, string $key = null);

/**
* Retrieve all data of repository, paginated
*
* @param null $limit
* @param array $columns
* @param mixed $per_page
* @param string|array $columns
*
* @return \Illuminate\Contracts\Pagination\Paginator
*/
public function paginate($limit = null, $columns = ['*']);
public function paginate(mixed $per_page = null, string|array $columns = ['*']);

/**
* Retrieve all data of repository, paginated
*
* @param null $limit
* @param array $columns
* @param mixed $per_page
* @param string|array $columns
*
* @return \Illuminate\Contracts\Pagination\Paginator
*/
public function simplePaginate($limit = null, $columns = ['*']);
public function simplePaginate(mixed $per_page = null, string|array $columns = ['*']);

/**
* Save a new entity in repository
Expand All @@ -151,10 +156,9 @@ public function update(Model $entity, array $attributes);
* @param mixed $entity
*
* @return bool|null
*
* @throws \Exception
*/
public function delete($entity);
public function delete(mixed $entity);

/**
* Get the raw SQL statements for the request
Expand All @@ -169,9 +173,9 @@ public function toSql();
* @param string $message
* @param string $key
*
* @return self
* @return static
*/
public function addError($message, string $key = 'message');
public function addError(string $message, string $key = 'message');

/**
* Get the repository's error messages.
Expand All @@ -187,5 +191,5 @@ public function getErrors();
*
* @return string
*/
public function getErrorMessage($default = '');
}
public function getErrorMessage(string $default = ''): string;
}
Loading

0 comments on commit e644af4

Please sign in to comment.