diff --git a/src/Controllers/RestController.php b/src/Controllers/RestController.php index 39f2b530..eae58dfc 100644 --- a/src/Controllers/RestController.php +++ b/src/Controllers/RestController.php @@ -125,7 +125,6 @@ protected function response($data = null, $status = 200, array $headers = []) return $this->response; } - /** * @param $modelClass * @param array $filters @@ -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, ]); diff --git a/src/Http/Requests/InteractWithRepositories.php b/src/Http/Requests/InteractWithRepositories.php index d86a2fb1..16482797 100644 --- a/src/Http/Requests/InteractWithRepositories.php +++ b/src/Http/Requests/InteractWithRepositories.php @@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model; /** - * @package Binaryk\LaravelRestify\Http\Requests; * @author Eduard Lupacescu */ trait InteractWithRepositories @@ -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); diff --git a/src/Http/Requests/RestifyRequest.php b/src/Http/Requests/RestifyRequest.php index d57f75a3..711031f4 100644 --- a/src/Http/Requests/RestifyRequest.php +++ b/src/Http/Requests/RestifyRequest.php @@ -10,5 +10,4 @@ class RestifyRequest extends FormRequest { use InteractWithRepositories; - } diff --git a/src/Services/Search/SearchService.php b/src/Services/Search/SearchService.php index d810641f..6f180eb2 100644 --- a/src/Services/Search/SearchService.php +++ b/src/Services/Search/SearchService.php @@ -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 */ @@ -54,7 +54,7 @@ protected function prepare() } /** - * Prepare eloquent exact fields + * Prepare eloquent exact fields. * * @param $fields * @@ -98,7 +98,7 @@ protected function prepareIn($fields) } /** - * Prepare eloquent exact fields + * Prepare eloquent exact fields. * * @param $fields * @@ -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; } @@ -136,7 +136,7 @@ protected function prepareOperator($fields) } /** - * Prepare eloquent exact fields + * Prepare eloquent exact fields. * * @param $fields * @@ -188,7 +188,7 @@ protected function prepareMatchFields($fields) } /** - * Prepare eloquent order by + * Prepare eloquent order by. * * @param $sort * @@ -216,7 +216,7 @@ protected function prepareOrders($sort) } /** - * Prepare relations + * Prepare relations. * * @return $this */ @@ -245,7 +245,7 @@ protected function prepareRelations() } /** - * Prepare search + * Prepare search. * * @param $search * @return $this @@ -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(); @@ -265,7 +265,6 @@ 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); } @@ -273,7 +272,7 @@ protected function prepareSearchFields($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.'%'); } }); @@ -281,7 +280,7 @@ protected function prepareSearchFields($search) } /** - * Set order + * Set order. * * @param $param * @@ -291,6 +290,7 @@ public function setOrder($param) { if ($param === 'random') { $this->builder->inRandomOrder(); + return $this; } diff --git a/src/Services/Search/Searchable.php b/src/Services/Search/Searchable.php index 87e880b6..35ca074c 100644 --- a/src/Services/Search/Searchable.php +++ b/src/Services/Search/Searchable.php @@ -6,9 +6,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; -/** - * @package Binaryk\LaravelRestify\Services\Search; - */ abstract class Searchable { /** @@ -17,7 +14,7 @@ abstract class Searchable protected $request; /** - * @var RestifySearchable|Model $model + * @var RestifySearchable|Model */ protected $model; @@ -26,7 +23,6 @@ abstract class Searchable */ protected $fixedInput; - /** * @param $input * diff --git a/src/Traits/AuthorizableModels.php b/src/Traits/AuthorizableModels.php index 319ee36b..9580f238 100644 --- a/src/Traits/AuthorizableModels.php +++ b/src/Traits/AuthorizableModels.php @@ -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 */ trait AuthorizableModels diff --git a/tests/Controllers/RepositoryIndexControllerTest.php b/tests/Controllers/RepositoryIndexControllerTest.php index 36d97c1b..3a08ad22 100644 --- a/tests/Controllers/RepositoryIndexControllerTest.php +++ b/tests/Controllers/RepositoryIndexControllerTest.php @@ -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);