From e994f8589928f25349bee591a84cbb8359fd55f9 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Sun, 22 Dec 2019 18:45:35 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Exceptions/InstanceOfException.php | 2 -- src/Services/Search/SearchService.php | 30 +++++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Exceptions/InstanceOfException.php b/src/Exceptions/InstanceOfException.php index 50190b985..a26d0f1c0 100644 --- a/src/Exceptions/InstanceOfException.php +++ b/src/Exceptions/InstanceOfException.php @@ -5,10 +5,8 @@ use Exception; /** - * @package Binaryk\LaravelRestify\Exceptions; * @author Eduard Lupacescu */ class InstanceOfException extends Exception { - } diff --git a/src/Services/Search/SearchService.php b/src/Services/Search/SearchService.php index f1349f3fc..fc60b5ade 100644 --- a/src/Services/Search/SearchService.php +++ b/src/Services/Search/SearchService.php @@ -35,7 +35,7 @@ public function search(RestifyRequest $request, Model $model) } /** - * Will prepare the eloquent array to return + * Will prepare the eloquent array to return. * * @return array * @throws InstanceOfException @@ -49,7 +49,7 @@ protected function prepare() ->prepareOrders($this->request->get('sort', '')) ->prepareRelations(); } else { - throw new InstanceOfException(__("Model is not an instance of :parent class", [ + throw new InstanceOfException(__('Model is not an instance of :parent class', [ 'parent' => RestifySearchable::class, ])); } @@ -63,7 +63,7 @@ protected function prepare() } /** - * Prepare eloquent exact fields + * Prepare eloquent exact fields. * * @param $fields * @@ -80,16 +80,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; } @@ -101,7 +101,7 @@ protected function prepareOperator($fields) } /** - * Prepare eloquent exact fields + * Prepare eloquent exact fields. * * @param $fields * @@ -109,7 +109,7 @@ protected function prepareOperator($fields) */ protected function prepareMatchFields() { - foreach($this->model::getMatchByFields() as $key => $type) { + foreach ($this->model::getMatchByFields() as $key => $type) { if (! $this->request->has($key) && ! data_get($this->fixedInput, "match.$key")) { continue; } @@ -149,7 +149,7 @@ protected function prepareMatchFields() } /** - * Prepare eloquent order by + * Prepare eloquent order by. * * @param $sort * @@ -177,7 +177,7 @@ protected function prepareOrders($sort) } /** - * Prepare relations + * Prepare relations. * * @return $this */ @@ -206,7 +206,7 @@ protected function prepareRelations() } /** - * Prepare search + * Prepare search. * * @param $search * @return $this @@ -221,7 +221,6 @@ protected function prepareSearchFields($search) ($connectionType != 'pgsql' || $search <= PHP_INT_MAX) && in_array($query->getModel()->getKeyName(), $this->model::getSearchableFields()); - if ($canSearchPrimaryKey) { $query->orWhere($query->getModel()->getQualifiedKeyName(), $search); } @@ -229,7 +228,7 @@ protected function prepareSearchFields($search) $likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like'; foreach ($this->model::getSearchableFields() as $column) { - $query->orWhere($this->model->qualifyColumn($column), $likeOperator, '%' . $search . '%'); + $query->orWhere($this->model->qualifyColumn($column), $likeOperator, '%'.$search.'%'); } }); @@ -237,7 +236,7 @@ protected function prepareSearchFields($search) } /** - * Set order + * Set order. * * @param $param * @@ -247,6 +246,7 @@ public function setOrder($param) { if ($param === 'random') { $this->builder->inRandomOrder(); + return $this; }