From 4ccc1325ccd07d9ede938711c8cbcf0093ec4234 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Thu, 26 Dec 2019 18:52:26 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Controllers/RestController.php | 1 - .../Controllers/RepositoryShowController.php | 2 +- src/Http/Requests/InteractWithRepositories.php | 6 ++---- src/Repositories/Repository.php | 8 ++------ src/Repositories/RepositoryCollection.php | 16 +++++++--------- src/Repositories/ResponseResolver.php | 12 +++++------- src/Traits/InteractWithSearch.php | 4 ---- 7 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/Controllers/RestController.php b/src/Controllers/RestController.php index 071a78c49..832c2106a 100644 --- a/src/Controllers/RestController.php +++ b/src/Controllers/RestController.php @@ -9,7 +9,6 @@ use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; use Binaryk\LaravelRestify\Repositories\Repository; use Binaryk\LaravelRestify\Services\Search\SearchService; -use Binaryk\LaravelRestify\Traits\PerformsQueries; use Illuminate\Config\Repository as Config; use Illuminate\Container\Container; use Illuminate\Contracts\Auth\Access\Gate; diff --git a/src/Http/Controllers/RepositoryShowController.php b/src/Http/Controllers/RepositoryShowController.php index 03524f2d4..7281e38aa 100644 --- a/src/Http/Controllers/RepositoryShowController.php +++ b/src/Http/Controllers/RepositoryShowController.php @@ -20,7 +20,7 @@ class RepositoryShowController extends RepositoryController public function handle(RestifyRequest $request) { /** - * @var Repository $repository + * @var Repository */ $repository = $request->newRepositoryWith(tap(SearchService::instance()->prepareRelations($request, $request->findModelQuery()), function ($query) use ($request) { $request->newRepository()->detailQuery($request, $query); diff --git a/src/Http/Requests/InteractWithRepositories.php b/src/Http/Requests/InteractWithRepositories.php index 9c39ecb80..af3ca5485 100644 --- a/src/Http/Requests/InteractWithRepositories.php +++ b/src/Http/Requests/InteractWithRepositories.php @@ -44,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); @@ -106,7 +106,7 @@ public function isResolvedByRestify() /** * Get a new instance of the repository being requested. - * As a model it could accept either a model instance, a collection or even paginated collection + * As a model it could accept either a model instance, a collection or even paginated collection. * * @param $model * @return Repository @@ -118,7 +118,6 @@ public function newRepositoryWith($model) return new $repository($model); } - /** * Get a new, scopeless query builder for the underlying model. * @@ -153,5 +152,4 @@ public function findModelQuery($repositoryId = null) $repositoryId ?? $this->repositoryId ); } - } diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index 9d371e4bd..00a9c9f85 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -16,7 +16,7 @@ /** * This class serve as repository collection and repository single model * This allow you to use all of the Laravel default repositories features (as adding headers in the response, or customizing - * response) + * response). * @author Eduard Lupacescu */ abstract class Repository extends RepositoryCollection implements RestifySearchable @@ -29,7 +29,7 @@ abstract class Repository extends RepositoryCollection implements RestifySearcha /** * This is named `resource` because of the forwarding properties from DelegatesToResource trait. - * This may be a single model or a illuminate collection, or even a paginator instance + * This may be a single model or a illuminate collection, or even a paginator instance. * * @var Model|LengthAwarePaginator */ @@ -54,9 +54,7 @@ public function __construct($model) public function model() { if ($this->isRenderingCollection() || $this->isRenderingPaginated()) { - return $this->modelFromIterator(); - } return $this->resource; @@ -101,9 +99,7 @@ public function toArray($request) $request = Container::getInstance()->make('request'); if ($this->isRenderingCollection()) { - return $this->toArrayForCollection($request); - } $serialized = [ diff --git a/src/Repositories/RepositoryCollection.php b/src/Repositories/RepositoryCollection.php index c55346fad..c0505a4ff 100644 --- a/src/Repositories/RepositoryCollection.php +++ b/src/Repositories/RepositoryCollection.php @@ -9,15 +9,13 @@ use Illuminate\Pagination\AbstractPaginator; use Illuminate\Support\Arr; - /** - * @package Binaryk\LaravelRestify\Repositories; * @author Eduard Lupacescu */ class RepositoryCollection extends Resource { /** - * When the repository is used as a response for a collection list (index controller) + * When the repository is used as a response for a collection list (index controller). * * @param $request * @return array @@ -84,7 +82,7 @@ protected function meta($paginated) /** * Check if the repository is used as a response for a list of items or for a single - * model entity + * model entity. * @return bool */ protected function isRenderingRepository() @@ -94,7 +92,7 @@ protected function isRenderingRepository() /** * Check if the repository is used as a response for a list of items or for a single - * model entity + * model entity. * @return bool */ protected function isRenderingCollection() @@ -111,21 +109,21 @@ public function isRenderingPaginated() } /** - * If collection or paginator then return model from the first item + * If collection or paginator then return model from the first item. * * @return Model */ protected function modelFromIterator() { /** - * @var ArrayIterator $iterator + * @var ArrayIterator */ $iterator = $this->iterator(); /** * This is the first element from the response collection, now we have the class of the restify - * engine - * @var Model $model + * engine. + * @var Model */ $model = $iterator->current(); diff --git a/src/Repositories/ResponseResolver.php b/src/Repositories/ResponseResolver.php index bd1176d38..00ca9556b 100644 --- a/src/Repositories/ResponseResolver.php +++ b/src/Repositories/ResponseResolver.php @@ -3,14 +3,12 @@ namespace Binaryk\LaravelRestify\Repositories; /** - * @package Binaryk\LaravelRestify\Repositories; * @author Eduard Lupacescu */ trait ResponseResolver { - /** - * Return the attributes list + * Return the attributes list. * * @param $request * @return array @@ -35,7 +33,7 @@ public function resolveDetailsMeta($request) } /** - * Return a list with relationship for the current model + * Return a list with relationship for the current model. * * @param $request * @return array @@ -46,7 +44,7 @@ public function resolveDetailsRelationships($request) } /** - * Triggered after toArray + * Triggered after toArray. * * @param $serialized * @return array @@ -57,7 +55,7 @@ public function resolveDetails($serialized) } /** - * Return the attributes list + * Return the attributes list. * * @param $request * @return array @@ -77,7 +75,7 @@ public function resolveIndexMeta($request) } /** - * Return a list with relationship for the current model + * Return a list with relationship for the current model. * * @param $request * @return array diff --git a/src/Traits/InteractWithSearch.php b/src/Traits/InteractWithSearch.php index c0b5275d1..b834508c6 100644 --- a/src/Traits/InteractWithSearch.php +++ b/src/Traits/InteractWithSearch.php @@ -2,9 +2,6 @@ namespace Binaryk\LaravelRestify\Traits; -use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; -use Illuminate\Support\Str; - /** * @author Eduard Lupacescu */ @@ -53,5 +50,4 @@ public static function getOrderByFields() { return static::$sort ?? []; } - }