Skip to content

Commit

Permalink
Apply fixes from StyleCI (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupacescu Eduard authored Dec 22, 2019
1 parent 3331837 commit 16740c3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/Controllers/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ protected function response($data = null, $status = 200, array $headers = [])
return $this->response;
}


/**
* @param $modelClass
* @param array $filters
Expand All @@ -144,7 +143,6 @@ public function search($modelClass, $filters = [])
$paginator = $results->paginate($this->request()->get('perPage') ?? ($modelClass::$defaultPerPage ?? RestifySearchable::DEFAULT_PER_PAGE));
$items = $paginator->getCollection()->map->serializeForIndex($this->request());


return array_merge($paginator->toArray(), [
'data' => $items,
]);
Expand Down
3 changes: 1 addition & 2 deletions src/Http/Requests/InteractWithRepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Database\Eloquent\Model;

/**
* @package Binaryk\LaravelRestify\Http\Requests;
* @author Eduard Lupacescu <[email protected]>
*/
trait InteractWithRepositories
Expand Down Expand Up @@ -45,7 +44,7 @@ public function repository()
]), 404);
}

if ( ! $repository::authorizedToViewAny($this)) {
if (! $repository::authorizedToViewAny($this)) {
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [
'name' => $repository,
]), 403);
Expand Down
1 change: 0 additions & 1 deletion src/Http/Requests/RestifyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
class RestifyRequest extends FormRequest
{
use InteractWithRepositories;

}
30 changes: 15 additions & 15 deletions src/Services/Search/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function search(RestifyRequest $request, Model $model)
}

/**
* Will prepare the eloquent array to return
* Will prepare the eloquent array to return.
*
* @return array
*/
Expand All @@ -54,7 +54,7 @@ protected function prepare()
}

/**
* Prepare eloquent exact fields
* Prepare eloquent exact fields.
*
* @param $fields
*
Expand Down Expand Up @@ -98,7 +98,7 @@ protected function prepareIn($fields)
}

/**
* Prepare eloquent exact fields
* Prepare eloquent exact fields.
*
* @param $fields
*
Expand All @@ -115,16 +115,16 @@ protected function prepareOperator($fields)
foreach ($values as $field => $value) {
$qualifiedField = $this->model->qualifyColumn($field);
switch ($key) {
case "gte":
case 'gte':
$this->builder->where($qualifiedField, '>=', $value);
break;
case "gt":
case 'gt':
$this->builder->where($qualifiedField, '>', $value);
break;
case "lte":
case 'lte':
$this->builder->where($qualifiedField, '<=', $value);
break;
case "lt":
case 'lt':
$this->builder->where($qualifiedField, '<', $value);
break;
}
Expand All @@ -136,7 +136,7 @@ protected function prepareOperator($fields)
}

/**
* Prepare eloquent exact fields
* Prepare eloquent exact fields.
*
* @param $fields
*
Expand Down Expand Up @@ -188,7 +188,7 @@ protected function prepareMatchFields($fields)
}

/**
* Prepare eloquent order by
* Prepare eloquent order by.
*
* @param $sort
*
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function prepareOrders($sort)
}

/**
* Prepare relations
* Prepare relations.
*
* @return $this
*/
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function prepareRelations()
}

/**
* Prepare search
* Prepare search.
*
* @param $search
* @return $this
Expand All @@ -254,7 +254,7 @@ protected function prepareSearchFields($search)
{
$this->builder->where(function (Builder $query) use ($search) {
/**
* @var RestifySearchable|Model $model
* @var RestifySearchable|Model
*/
$model = $query->getModel();

Expand All @@ -265,23 +265,22 @@ protected function prepareSearchFields($search)
($connectionType != 'pgsql' || $search <= PHP_INT_MAX) &&
in_array($query->getModel()->getKeyName(), $model::getSearchableFields());


if ($canSearchPrimaryKey) {
$query->orWhere($query->getModel()->getQualifiedKeyName(), $search);
}

$likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like';

foreach ($this->model::getSearchableFields() as $column) {
$query->orWhere($model->qualifyColumn($column), $likeOperator, '%' . $search . '%');
$query->orWhere($model->qualifyColumn($column), $likeOperator, '%'.$search.'%');
}
});

return $this;
}

/**
* Set order
* Set order.
*
* @param $param
*
Expand All @@ -291,6 +290,7 @@ public function setOrder($param)
{
if ($param === 'random') {
$this->builder->inRandomOrder();

return $this;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Services/Search/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

/**
* @package Binaryk\LaravelRestify\Services\Search;
*/
abstract class Searchable
{
/**
Expand All @@ -17,7 +14,7 @@ abstract class Searchable
protected $request;

/**
* @var RestifySearchable|Model $model
* @var RestifySearchable|Model
*/
protected $model;

Expand All @@ -26,7 +23,6 @@ abstract class Searchable
*/
protected $fixedInput;


/**
* @param $input
*
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/AuthorizableModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Illuminate\Support\Str;

/**
* Could be used as a trait in a model class and in a repository class
*
* Could be used as a trait in a model class and in a repository class.
*
* @author Eduard Lupacescu <[email protected]>
*/
trait AuthorizableModels
Expand Down
1 change: 0 additions & 1 deletion tests/Controllers/RepositoryIndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function test_list_resource()
$response->assertJsonCount(3, 'data.data');
}


public function test_the_rest_controller_can_paginate()
{
$this->mockUsers(50);
Expand Down

0 comments on commit 16740c3

Please sign in to comment.