From be1d1e1844ba8720d7b7d13691c96b3436c08052 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Tue, 24 Dec 2019 11:47:49 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Controllers/RestController.php | 2 +- src/Controllers/RestResponse.php | 19 ++++++++++--------- src/Fields/BaseField.php | 2 -- src/Fields/Field.php | 18 +++++++++--------- src/Fields/OrganicField.php | 1 - src/Fields/RulesTrait.php | 15 +++++++-------- .../Controllers/RepositoryStoreController.php | 4 ++-- .../Requests/InteractWithRepositories.php | 1 - src/Repositories/RepositoryFillFields.php | 8 +++----- src/Repositories/ValidatingTrait.php | 8 +++----- src/Traits/PerformsRequestValidation.php | 2 -- .../RepositoryStoreControllerTest.php | 3 +-- tests/Fixtures/PostRepository.php | 1 - 13 files changed, 36 insertions(+), 48 deletions(-) diff --git a/src/Controllers/RestController.php b/src/Controllers/RestController.php index ec8110d76..9f0cedab7 100644 --- a/src/Controllers/RestController.php +++ b/src/Controllers/RestController.php @@ -157,7 +157,7 @@ public function search($modelClass, $filters = []) return [ 'meta' => Arr::except($paginator->toArray(), ['data', 'next_page_url', 'last_page_url', 'first_page_url', 'prev_page_url', 'path']), 'links' => Arr::only($paginator->toArray(), ['next_page_url', 'last_page_url', 'first_page_url', 'prev_page_url', 'path']), - 'data' => $items + 'data' => $items, ]; } diff --git a/src/Controllers/RestResponse.php b/src/Controllers/RestResponse.php index f5283f0b7..7ea83a7a3 100644 --- a/src/Controllers/RestResponse.php +++ b/src/Controllers/RestResponse.php @@ -119,12 +119,12 @@ class RestResponse protected $type; /** - * Key of the newly created resource + * Key of the newly created resource. * @var */ protected $id; /** - * Model related entities + * Model related entities. * @var */ protected $relationships; @@ -184,7 +184,7 @@ public function errors(array $errors = null) */ public function addError($message) { - if ( ! isset($this->errors)) { + if (! isset($this->errors)) { $this->errors = []; } @@ -269,7 +269,7 @@ public function __get($key) return $this->$key; } - $code = 'static::REST_RESPONSE_' . strtoupper($key) . '_CODE'; + $code = 'static::REST_RESPONSE_'.strtoupper($key).'_CODE'; return defined($code) ? constant($code) : null; } @@ -284,7 +284,7 @@ public function __get($key) */ public function __call($func, $args) { - $code = 'static::REST_RESPONSE_' . strtoupper($func) . '_CODE'; + $code = 'static::REST_RESPONSE_'.strtoupper($func).'_CODE'; if (defined($code)) { return $this->code(constant($code)); @@ -303,7 +303,7 @@ public function __call($func, $args) */ public function respond($response = null) { - if ( ! func_num_args()) { + if (! func_num_args()) { $response = new \stdClass(); $response->data = new \stdClass(); @@ -408,7 +408,7 @@ public function getAttribute($name) } /** - * Set attributes at root level + * Set attributes at root level. * * @param array $attributes * @return mixed @@ -445,6 +445,7 @@ protected function response() public function header($name, $value) { $this->headers[$name] = $value; + return $this; } @@ -455,12 +456,13 @@ public function header($name, $value) public function type($type) { $this->type = $type; + return $this; } /** * Useful when newly created repository, will prepare the response according - * with JSON:API https://jsonapi.org/format/#document-resource-object-fields + * with JSON:API https://jsonapi.org/format/#document-resource-object-fields. * * @param Repository $repository * @param bool $withRelations @@ -502,7 +504,6 @@ public static function beforeRespond($response) return $response; } - return $response; } } diff --git a/src/Fields/BaseField.php b/src/Fields/BaseField.php index 5d6be957b..77e8e1c5a 100644 --- a/src/Fields/BaseField.php +++ b/src/Fields/BaseField.php @@ -3,10 +3,8 @@ namespace Binaryk\LaravelRestify\Fields; /** - * @package Binaryk\LaravelRestify; * @author Eduard Lupacescu */ abstract class BaseField { - } diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 073c5d298..97996bedb 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -7,7 +7,6 @@ use JsonSerializable; /** - * @package Binaryk\LaravelRestify; * @author Eduard Lupacescu */ class Field extends OrganicField implements JsonSerializable @@ -15,20 +14,20 @@ class Field extends OrganicField implements JsonSerializable use RulesTrait; /** - * Column name of the field + * Column name of the field. * @var string */ public $attribute; /** - * Callback called when the value is filled, this callback will do not override the fill action + * Callback called when the value is filled, this callback will do not override the fill action. * @var Closure */ public $storeCallback; /** * Callback called when trying to fill this attribute, this callback will override the fill action, so make - * sure you assign the attribute to the model over this callback + * sure you assign the attribute to the model over this callback. * * @var Closure */ @@ -56,7 +55,7 @@ public static function fire(...$arguments) } /** - * @inheritDoc + * {@inheritdoc} */ public function jsonSerialize() { @@ -65,7 +64,7 @@ public function jsonSerialize() /** * Callback called when the value is filled, this callback will do not override the fill action. If fillCallback is defined - * this will do not be called + * this will do not be called. * * @param Closure $callback * @return Field @@ -79,7 +78,7 @@ public function storeCallback(Closure $callback) /** * Callback called when trying to fill this attribute, this callback will override the fill action, so make - * sure you assign the attribute to the model over this callback + * sure you assign the attribute to the model over this callback. * * @param Closure $callback * @return $this @@ -87,11 +86,12 @@ public function storeCallback(Closure $callback) public function fillCallback(Closure $callback) { $this->fillCallback = $callback; + return $this; } /** - * Fill attribute with value from the request or delegate this action to the user defined callback + * Fill attribute with value from the request or delegate this action to the user defined callback. * * @param RestifyRequest $request * @param $model @@ -111,7 +111,7 @@ public function fillAttribute(RestifyRequest $request, $model) } /** - * Fill the model with value from the request + * Fill the model with value from the request. * * @param RestifyRequest $request * @param $model diff --git a/src/Fields/OrganicField.php b/src/Fields/OrganicField.php index 0cb7c7614..3d4c38343 100644 --- a/src/Fields/OrganicField.php +++ b/src/Fields/OrganicField.php @@ -3,7 +3,6 @@ namespace Binaryk\LaravelRestify\Fields; /** - * @package Binaryk\LaravelRestify; * @author Eduard Lupacescu */ abstract class OrganicField extends BaseField diff --git a/src/Fields/RulesTrait.php b/src/Fields/RulesTrait.php index 9631f1537..094a0a1da 100644 --- a/src/Fields/RulesTrait.php +++ b/src/Fields/RulesTrait.php @@ -5,33 +5,31 @@ use Illuminate\Contracts\Validation\Rule; /** - * @package Binaryk\LaravelRestify\Fields; * @author Eduard Lupacescu */ trait RulesTrait { /** - * Rules for applied when store + * Rules for applied when store. * * @var array */ public $storingRules = []; /** - * Rules for applied when store and update + * Rules for applied when store and update. * * @var array */ public $rules = []; - /** * @var array */ public $messages = []; /** - * Validation rules for store + * Validation rules for store. * @param callable|array|string $rules * @return RulesTrait */ @@ -43,7 +41,7 @@ public function storingRules($rules) } /** - * Validation rules for store + * Validation rules for store. * @param callable|array|string $rules * @return RulesTrait */ @@ -55,7 +53,7 @@ public function rules($rules) } /** - * Validation messages + * Validation messages. * * @param array $messages * @return RulesTrait @@ -63,11 +61,12 @@ public function rules($rules) public function messages(array $messages) { $this->messages = $messages; + return $this; } /** - * Validation rules for storing + * Validation rules for storing. * * @return array */ diff --git a/src/Http/Controllers/RepositoryStoreController.php b/src/Http/Controllers/RepositoryStoreController.php index 92339313a..52e7a7c9a 100644 --- a/src/Http/Controllers/RepositoryStoreController.php +++ b/src/Http/Controllers/RepositoryStoreController.php @@ -30,7 +30,7 @@ class RepositoryStoreController extends RepositoryController public function handle(RepositoryStoreRequest $request) { /** - * @var Repository $repository + * @var Repository */ $repository = $request->repository(); @@ -57,7 +57,7 @@ public function handle(RepositoryStoreRequest $request) return $this->response() ->code(201) ->forRepository($request->newRepositoryWith($model), true) - ->header('Location', Restify::path() . '/' . $repository::uriKey() . '/' . $model->id) + ->header('Location', Restify::path().'/'.$repository::uriKey().'/'.$model->id) ->respond(); } } diff --git a/src/Http/Requests/InteractWithRepositories.php b/src/Http/Requests/InteractWithRepositories.php index 7de006157..fd40683a3 100644 --- a/src/Http/Requests/InteractWithRepositories.php +++ b/src/Http/Requests/InteractWithRepositories.php @@ -116,5 +116,4 @@ public function newRepositoryWith($model) return new $resource($model); } - } diff --git a/src/Repositories/RepositoryFillFields.php b/src/Repositories/RepositoryFillFields.php index ceaab7208..660bc09c5 100644 --- a/src/Repositories/RepositoryFillFields.php +++ b/src/Repositories/RepositoryFillFields.php @@ -8,14 +8,12 @@ use Illuminate\Support\Collection; /** - * @package Binaryk\LaravelRestify\Repositories; * @author Eduard Lupacescu */ trait RepositoryFillFields { - /** - * Fill fields on store request + * Fill fields on store request. * * @param RestifyRequest $request * @param $model @@ -32,7 +30,7 @@ public static function fillWhenStore(RestifyRequest $request, $model) } /** - * Fill each field separately + * Fill each field separately. * * @param RestifyRequest $request * @param Model $model @@ -50,7 +48,7 @@ protected static function fillFields(RestifyRequest $request, Model $model, Coll /** * If some fields were not defined in the @fields method, but they are in fillable attributes and present in request, - * they should be also filled on request + * they should be also filled on request. * @param RestifyRequest $request * @param Model $model * @param Collection $fields diff --git a/src/Repositories/ValidatingTrait.php b/src/Repositories/ValidatingTrait.php index e4a454fda..f6d485d80 100644 --- a/src/Repositories/ValidatingTrait.php +++ b/src/Repositories/ValidatingTrait.php @@ -8,7 +8,6 @@ use Illuminate\Support\Facades\Validator; /** - * @package Binaryk\LaravelRestify\Repositories; * @author Eduard Lupacescu */ trait ValidatingTrait @@ -24,7 +23,6 @@ abstract public function collectFields(RestifyRequest $request); */ abstract public static function newModel(); - /** * @param RestifyRequest $request * @return \Illuminate\Contracts\Validation\Validator @@ -36,8 +34,9 @@ public static function validatorForStoring(RestifyRequest $request) $messages = $on->collectFields($request)->flatMap(function ($k) { $messages = []; foreach ($k->messages as $ruleFor => $message) { - $messages[$k->attribute . '.' . $ruleFor] = $message; + $messages[$k->attribute.'.'.$ruleFor] = $message; } + return $messages; })->toArray(); @@ -45,7 +44,6 @@ public static function validatorForStoring(RestifyRequest $request) static::afterValidation($request, $validator); static::afterStoringValidation($request, $validator); }); - } /** @@ -79,7 +77,7 @@ public function getStoringRules(RestifyRequest $request) { return $this->collectFields($request)->mapWithKeys(function (Field $k) { return [ - $k->attribute => $k->getStoringRules() + $k->attribute => $k->getStoringRules(), ]; })->toArray(); } diff --git a/src/Traits/PerformsRequestValidation.php b/src/Traits/PerformsRequestValidation.php index da60f6fda..ab4470412 100644 --- a/src/Traits/PerformsRequestValidation.php +++ b/src/Traits/PerformsRequestValidation.php @@ -3,10 +3,8 @@ namespace Binaryk\LaravelRestify\Traits; /** - * @package Binaryk\LaravelRestify\Traits; * @author Eduard Lupacescu */ trait PerformsRequestValidation { - } diff --git a/tests/Controllers/RepositoryStoreControllerTest.php b/tests/Controllers/RepositoryStoreControllerTest.php index 10335074f..42cb6d9cc 100644 --- a/tests/Controllers/RepositoryStoreControllerTest.php +++ b/tests/Controllers/RepositoryStoreControllerTest.php @@ -5,7 +5,6 @@ use Binaryk\LaravelRestify\Tests\IntegrationTest; /** - * @package Binaryk\LaravelRestify\Tests\Controllers; * @author Eduard Lupacescu */ class RepositoryStoreControllerTest extends IntegrationTest @@ -24,7 +23,7 @@ public function test_basic_validation_works() ->assertJson([ 'errors' => [ 'description' => [ - 'Description field is required bro.' + 'Description field is required bro.', ], ], ]); diff --git a/tests/Fixtures/PostRepository.php b/tests/Fixtures/PostRepository.php index e9095c42b..0bd059867 100644 --- a/tests/Fixtures/PostRepository.php +++ b/tests/Fixtures/PostRepository.php @@ -37,6 +37,5 @@ public function fields(RestifyRequest $request) 'required' => 'Description field is required bro.', ]), ]; - } }