Skip to content

Commit 1dbd10c

Browse files
committed
Linter and Stan fixes
1 parent cf99c13 commit 1dbd10c

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

src/Contracts/RepositoryContract.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Support\Collection;
66
use Illuminate\Pagination\Paginator;
77
use Illuminate\Database\Eloquent\Model;
8-
use Torann\LaravelRepository\Exceptions\RepositoryException;
98

109
interface RepositoryContract
1110
{
@@ -113,7 +112,7 @@ public function pluck($value, $key = null);
113112
* @param null $limit
114113
* @param array $columns
115114
*
116-
* @return Paginator
115+
* @return \Illuminate\Contracts\Pagination\Paginator
117116
*/
118117
public function paginate($limit = null, $columns = ['*']);
119118

@@ -123,7 +122,7 @@ public function paginate($limit = null, $columns = ['*']);
123122
* @param null $limit
124123
* @param array $columns
125124
*
126-
* @return \Illuminate\Pagination\Paginator
125+
* @return \Illuminate\Contracts\Pagination\Paginator
127126
*/
128127
public function simplePaginate($limit = null, $columns = ['*']);
129128

@@ -168,10 +167,11 @@ public function toSql();
168167
* Add a message to the repository's error messages.
169168
*
170169
* @param string $message
170+
* @param string $key
171171
*
172-
* @return null
172+
* @return self
173173
*/
174-
public function addError($message);
174+
public function addError($message, string $key = 'message');
175175

176176
/**
177177
* Get the repository's error messages.

src/Repositories/AbstractRepository.php

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,29 @@ public function getOrderBy()
319319
return $this->orderBy;
320320
}
321321

322+
/**
323+
* Set searchable array.
324+
*
325+
* @param array|string $key
326+
* @param mixed $value
327+
*
328+
* @return self
329+
*/
330+
public function setSearchable($key, $value = null)
331+
{
332+
// Allow for a batch assignment
333+
if (is_array($key) === false) {
334+
$key = [$key => $value];
335+
}
336+
337+
// Update the searchable values
338+
foreach ($key as $k => $v) {
339+
$this->searchable[$k] = $v;
340+
}
341+
342+
return $this;
343+
}
344+
322345
/**
323346
* Return searchable keys.
324347
*
@@ -381,7 +404,9 @@ public function search($queries)
381404
$value = Arr::get($queries, $param, '');
382405

383406
// Validate value
384-
if ($value === '' || $value === null) continue;
407+
if ($value === '' || $value === null) {
408+
continue;
409+
}
385410

386411
// Columns should be an array
387412
$columns = (array) $columns;
@@ -626,6 +651,21 @@ public function makeModel()
626651
return $this->modelInstance = new $this->model;
627652
}
628653

654+
/**
655+
* Get a new query builder instance with the applied
656+
* the order by and scopes.
657+
*
658+
* @param bool $skipOrdering
659+
*
660+
* @return \Illuminate\Database\Eloquent\Builder
661+
*/
662+
public function getBuilder(bool $skipOrdering = false)
663+
{
664+
$this->newQuery($skipOrdering);
665+
666+
return $this->query;
667+
}
668+
629669
/**
630670
* Get the raw SQL statements for the request
631671
*
@@ -685,14 +725,15 @@ protected function applyScope()
685725
* Add a message to the repository's error messages.
686726
*
687727
* @param string $message
728+
* @param string $key
688729
*
689-
* @return null
730+
* @return self
690731
*/
691-
public function addError($message)
732+
public function addError($message, string $key = 'message')
692733
{
693-
$this->getErrors()->add('message', $message);
734+
$this->getErrors()->add($key, $message);
694735

695-
return null;
736+
return $this;
696737
}
697738

698739
/**

src/Traits/Cacheable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function skippedCache()
7474
*
7575
* @return string
7676
*/
77-
public function getCacheKey($method, $args = null, $tag)
77+
public function getCacheKey($method, $args = null, $tag = '')
7878
{
7979
// Sort through arguments
8080
foreach ($args as &$a) {
@@ -86,7 +86,8 @@ public function getCacheKey($method, $args = null, $tag)
8686
// Create hash from arguments and query
8787
$args = serialize($args) . serialize($this->getScopeQuery());
8888

89-
return sprintf('%s-%s@%s-%s',
89+
return sprintf(
90+
'%s-%s@%s-%s',
9091
config('app.locale'),
9192
$tag,
9293
$method,

0 commit comments

Comments
 (0)