Skip to content

Commit 9a8e601

Browse files
committed
Code cleanup
1 parent 812a6a6 commit 9a8e601

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The BSD 2-Clause License
2-
Copyright (c) 2014-2018, Daniel Stainback
2+
Copyright (c) 2014-2020, Daniel Stainback
33
All rights reserved.
44

55
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

src/Contracts/RepositoryContract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function findOrFail($id);
4040
/**
4141
* Find data by field and value
4242
*
43-
* @param $field
44-
* @param $value
43+
* @param $field
44+
* @param $value
4545
* @param array $columns
4646
*
4747
* @return Model|Collection

src/Repositories/AbstractRepository.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function find($id, $columns = ['*'])
199199
* Find a model by its primary key or throw an exception.
200200
*
201201
* @param string $id
202-
* @param array $columns
202+
* @param array $columns
203203
*
204204
* @return \Illuminate\Database\Eloquent\Model
205205
*
@@ -269,8 +269,7 @@ public function findWhere(array $where, $columns = ['*'])
269269
if (is_array($value)) {
270270
list($field, $condition, $val) = $value;
271271
$this->query->where($field, $condition, $val);
272-
}
273-
else {
272+
} else {
274273
$this->query->where($field, '=', $value);
275274
}
276275
}
@@ -327,9 +326,21 @@ public function getOrderBy()
327326
*/
328327
public function getSearchableKeys()
329328
{
329+
$return = $this->getSearchable();
330+
330331
return array_values(array_map(function ($value, $key) {
331332
return (is_array($value) || is_numeric($key) === false) ? $key : $value;
332-
}, $this->searchable, array_keys($this->searchable)));
333+
}, $return, array_keys($return)));
334+
}
335+
336+
/**
337+
* Return searchable array.
338+
*
339+
* @return array
340+
*/
341+
public function getSearchable()
342+
{
343+
return $this->searchable;
333344
}
334345

335346
/**
@@ -352,7 +363,7 @@ public function search($queries)
352363
// Keep track of what tables have been joined and their aliases
353364
$joined = [];
354365

355-
foreach ($this->searchable as $param => $columns) {
366+
foreach ($this->getSearchable() as $param => $columns) {
356367
// It doesn't always have to map to something
357368
$param = is_numeric($param) ? $columns : $param;
358369

@@ -363,7 +374,7 @@ public function search($queries)
363374
if ($value === '' || $value === null) continue;
364375

365376
// Columns should be an array
366-
$columns = (array)$columns;
377+
$columns = (array) $columns;
367378

368379
// Loop though the columns and look for relationships
369380
foreach ($columns as $key => $column) {
@@ -401,8 +412,7 @@ public function search($queries)
401412
$this->createSearchClause($q, $param, $column, $value, 'or');
402413
}
403414
});
404-
}
405-
else {
415+
} else {
406416
$this->createSearchClause($query, $param, $columns[0], $value);
407417
}
408418
}
@@ -482,10 +492,10 @@ public function pluck($value, $key = null)
482492
/**
483493
* Retrieve all data of repository, paginated
484494
*
485-
* @param int $per_page
486-
* @param array $columns
487-
* @param string $page_name
488-
* @param int|null $page
495+
* @param int $per_page
496+
* @param array $columns
497+
* @param string $page_name
498+
* @param int|null $page
489499
*
490500
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
491501
*/
@@ -511,10 +521,10 @@ public function paginate($per_page = null, $columns = ['*'], $page_name = 'page'
511521
/**
512522
* Retrieve all data of repository, paginated
513523
*
514-
* @param int $per_page
515-
* @param array $columns
516-
* @param string $page_name
517-
* @param int|null $page
524+
* @param int $per_page
525+
* @param array $columns
526+
* @param string $page_name
527+
* @param int|null $page
518528
*
519529
* @return \Illuminate\Contracts\Pagination\Paginator
520530
*/
@@ -716,7 +726,7 @@ protected function appendTableName($column)
716726
}
717727

718728
// Remove alias prefix indicator
719-
if (substr($column, 0, 2) === '_.') {
729+
if (preg_match('/^_\./', $column) != false) {
720730
return preg_replace('/^_\./', '', $column);
721731
}
722732

@@ -736,11 +746,9 @@ protected function createSearchClause(Builder $query, $param, $column, $value, $
736746
{
737747
if ($param === 'query') {
738748
$query->where($this->appendTableName($column), self::$searchOperator, '%' . $value . '%', $boolean);
739-
}
740-
elseif (is_array($value)) {
749+
} elseif (is_array($value)) {
741750
$query->whereIn($this->appendTableName($column), $value, $boolean);
742-
}
743-
else {
751+
} else {
744752
$query->where($this->appendTableName($column), '=', $value, $boolean);
745753
}
746754
}

src/Traits/Cacheable.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ public function skippedCache()
6868
/**
6969
* Get Cache key for the method
7070
*
71-
* @param string $method
72-
* @param mixed $args
73-
* @param string $tag
71+
* @param string $method
72+
* @param mixed $args
73+
* @param string $tag
7474
*
7575
* @return string
7676
*/
7777
public function getCacheKey($method, $args = null, $tag)
7878
{
7979
// Sort through arguments
80-
foreach($args as &$a) {
80+
foreach ($args as &$a) {
8181
if ($a instanceof Model) {
82-
$a = get_class($a).'|'.$a->getKey();
82+
$a = get_class($a) . '|' . $a->getKey();
8383
}
8484
}
8585

@@ -100,7 +100,7 @@ public function getCacheKey($method, $args = null, $tag)
100100
* @param string $method
101101
* @param array $args
102102
* @param \Closure $callback
103-
* @param int $time
103+
* @param int $time
104104
*
105105
* @return mixed
106106
*/

0 commit comments

Comments
 (0)