Skip to content

Commit

Permalink
Linter and Stan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Torann committed Sep 28, 2020
1 parent cf99c13 commit 1dbd10c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/Contracts/RepositoryContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\Collection;
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Eloquent\Model;
use Torann\LaravelRepository\Exceptions\RepositoryException;

interface RepositoryContract
{
Expand Down Expand Up @@ -113,7 +112,7 @@ public function pluck($value, $key = null);
* @param null $limit
* @param array $columns
*
* @return Paginator
* @return \Illuminate\Contracts\Pagination\Paginator
*/
public function paginate($limit = null, $columns = ['*']);

Expand All @@ -123,7 +122,7 @@ public function paginate($limit = null, $columns = ['*']);
* @param null $limit
* @param array $columns
*
* @return \Illuminate\Pagination\Paginator
* @return \Illuminate\Contracts\Pagination\Paginator
*/
public function simplePaginate($limit = null, $columns = ['*']);

Expand Down Expand Up @@ -168,10 +167,11 @@ public function toSql();
* Add a message to the repository's error messages.
*
* @param string $message
* @param string $key
*
* @return null
* @return self
*/
public function addError($message);
public function addError($message, string $key = 'message');

/**
* Get the repository's error messages.
Expand Down
51 changes: 46 additions & 5 deletions src/Repositories/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,29 @@ public function getOrderBy()
return $this->orderBy;
}

/**
* Set searchable array.
*
* @param array|string $key
* @param mixed $value
*
* @return self
*/
public function setSearchable($key, $value = null)
{
// Allow for a batch assignment
if (is_array($key) === false) {
$key = [$key => $value];
}

// Update the searchable values
foreach ($key as $k => $v) {
$this->searchable[$k] = $v;
}

return $this;
}

/**
* Return searchable keys.
*
Expand Down Expand Up @@ -381,7 +404,9 @@ public function search($queries)
$value = Arr::get($queries, $param, '');

// Validate value
if ($value === '' || $value === null) continue;
if ($value === '' || $value === null) {
continue;
}

// Columns should be an array
$columns = (array) $columns;
Expand Down Expand Up @@ -626,6 +651,21 @@ public function makeModel()
return $this->modelInstance = new $this->model;
}

/**
* Get a new query builder instance with the applied
* the order by and scopes.
*
* @param bool $skipOrdering
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getBuilder(bool $skipOrdering = false)
{
$this->newQuery($skipOrdering);

return $this->query;
}

/**
* Get the raw SQL statements for the request
*
Expand Down Expand Up @@ -685,14 +725,15 @@ protected function applyScope()
* Add a message to the repository's error messages.
*
* @param string $message
* @param string $key
*
* @return null
* @return self
*/
public function addError($message)
public function addError($message, string $key = 'message')
{
$this->getErrors()->add('message', $message);
$this->getErrors()->add($key, $message);

return null;
return $this;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Traits/Cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function skippedCache()
*
* @return string
*/
public function getCacheKey($method, $args = null, $tag)
public function getCacheKey($method, $args = null, $tag = '')
{
// Sort through arguments
foreach ($args as &$a) {
Expand All @@ -86,7 +86,8 @@ public function getCacheKey($method, $args = null, $tag)
// Create hash from arguments and query
$args = serialize($args) . serialize($this->getScopeQuery());

return sprintf('%s-%s@%s-%s',
return sprintf(
'%s-%s@%s-%s',
config('app.locale'),
$tag,
$method,
Expand Down

0 comments on commit 1dbd10c

Please sign in to comment.