diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 6c3d74e71..366de0afe 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -19,7 +19,7 @@ class Field extends OrganicField implements JsonSerializable public $attribute; /** - * Field value + * Field value. * * @var string|callable|null */ @@ -223,7 +223,7 @@ public function getUpdatingRules(): array * @param string|null $attribute * @return Field */ - public function resolveForShow($repository, $attribute = null): Field + public function resolveForShow($repository, $attribute = null): self { $attribute = $attribute ?? $this->attribute; @@ -234,7 +234,7 @@ public function resolveForShow($repository, $attribute = null): Field return $this; } - public function resolveForIndex($repository, $attribute = null): Field + public function resolveForIndex($repository, $attribute = null): self { $attribute = $attribute ?? $this->attribute; diff --git a/src/Fields/OrganicField.php b/src/Fields/OrganicField.php index 47028d237..4f7bc5929 100644 --- a/src/Fields/OrganicField.php +++ b/src/Fields/OrganicField.php @@ -10,7 +10,6 @@ */ abstract class OrganicField extends BaseField { - /** * The callback used to authorize viewing the filter or action. * diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index 815b425aa..dfa42c275 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -56,7 +56,7 @@ abstract class Repository implements RestifySearchable, JsonSerializable public $resource; /** - * The list of relations available for the details or index + * The list of relations available for the details or index. * * e.g. ?with=users * @var array @@ -64,21 +64,21 @@ abstract class Repository implements RestifySearchable, JsonSerializable public static array $related; /** - * The list of searchable fields + * The list of searchable fields. * * @var array */ public static array $search; /** - * The list of matchable fields + * The list of matchable fields. * * @var array */ public static array $match; /** - * The list of fields to be sortable + * The list of fields to be sortable. * * @var array */ @@ -290,7 +290,7 @@ public function resolveRelationships($request): array /** * @var AbstractPaginator $paginator */ $paginator = $this->resource->{$relation}()->paginate($request->get('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE)); - $withs[$relation] = $paginator->getCollection()->map(fn(Model $item) => [ + $withs[$relation] = $paginator->getCollection()->map(fn (Model $item) => [ 'attributes' => $item->toArray(), ]); } @@ -335,7 +335,7 @@ public function serializeIndex(RestifyRequest $request): array }), 'type' => $this->model()->getTable(), 'attributes' => $this->resolveIndexAttributes($request), - 'relationships' => $this->when(!empty($relations), $relations), + 'relationships' => $this->when(! empty($relations), $relations), 'meta' => $this->when(value($this->resolveDetailsMeta($request)), $this->resolveDetailsMeta($request)), ]; } @@ -352,11 +352,11 @@ public function resolveIndexAttributes($request) // Resolve the show method, and attach the value to the array $this->collectFields($request) - ->filter(fn(Field $field) => !$field->isHiddenOnIndex($request, static::class)) + ->filter(fn (Field $field) => ! $field->isHiddenOnIndex($request, static::class)) ->each(function (Field $field) use (&$resolvedAttributes) { $resolvedAttributes[$field->attribute] = $field->resolveForIndex($this)->value; }); - $hidden = $this->collectFields($request)->filter(fn(Field $field) => $field->isHiddenOnIndex($request, $this))->pluck('attribute')->toArray(); + $hidden = $this->collectFields($request)->filter(fn (Field $field) => $field->isHiddenOnIndex($request, $this))->pluck('attribute')->toArray(); return Arr::except($resolvedAttributes, $hidden); } @@ -394,9 +394,9 @@ public function index(RestifyRequest $request) $items = $paginator->getCollection()->map(function ($value) { return static::resolveWith($value); - })->filter(function (Repository $repository) use ($request) { + })->filter(function (self $repository) use ($request) { return $repository->authorizedToShow($request); - })->values()->map(fn(self $item) => $this->filter($item->serializeIndex($request))); + })->values()->map(fn (self $item) => $this->filter($item->serializeIndex($request))); return $this->response([ 'meta' => RepositoryCollection::meta($paginator->toArray()), @@ -447,7 +447,7 @@ public function store(RestifyRequest $request) return $this->response('', RestResponse::REST_RESPONSE_CREATED_CODE) ->model($this->resource) - ->header('Location', Restify::path() . '/' . static::uriKey() . '/' . $this->resource->id); + ->header('Location', Restify::path().'/'.static::uriKey().'/'.$this->resource->id); } public function update(RestifyRequest $request, $repositoryId) diff --git a/src/Services/Search/RepositorySearchService.php b/src/Services/Search/RepositorySearchService.php index 8f4c05fc0..b69deb0ff 100644 --- a/src/Services/Search/RepositorySearchService.php +++ b/src/Services/Search/RepositorySearchService.php @@ -24,7 +24,7 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = []) { $model = $query->getModel(); foreach ($this->repository->getMatchByFields() as $key => $type) { - if (!$request->has($key) && !data_get($extra, "match.$key")) { + if (! $request->has($key) && ! data_get($extra, "match.$key")) { continue; } @@ -57,7 +57,7 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = []) case RestifySearchable::MATCH_INTEGER: case 'number': case 'int': - $query->where($field, '=', (int)$match); + $query->where($field, '=', (int) $match); break; } } @@ -122,7 +122,7 @@ public function prepareSearchFields(RestifyRequest $request, $query, $extra = [] $likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like'; foreach ($this->repository->getSearchableFields() as $column) { - $query->orWhere($model->qualifyColumn($column), $likeOperator, '%' . $search . '%'); + $query->orWhere($model->qualifyColumn($column), $likeOperator, '%'.$search.'%'); } }); diff --git a/src/Services/Search/SearchService.php b/src/Services/Search/SearchService.php index 7be307467..025e581a0 100644 --- a/src/Services/Search/SearchService.php +++ b/src/Services/Search/SearchService.php @@ -15,7 +15,7 @@ class SearchService extends Searchable { public function search(RestifyRequest $request, $model) { - if (!$model instanceof RestifySearchable) { + if (! $model instanceof RestifySearchable) { return $model->newQuery(); } @@ -37,7 +37,7 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = []) $model = $query->getModel(); if ($model instanceof RestifySearchable) { foreach ($model::getMatchByFields() as $key => $type) { - if (!$request->has($key) && !data_get($extra, "match.$key")) { + if (! $request->has($key) && ! data_get($extra, "match.$key")) { continue; } @@ -70,7 +70,7 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = []) case RestifySearchable::MATCH_INTEGER: case 'number': case 'int': - $query->where($field, '=', (int)$match); + $query->where($field, '=', (int) $match); break; } } @@ -162,7 +162,7 @@ public function prepareSearchFields(RestifyRequest $request, $query, $extra = [] $likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like'; foreach ($model::getSearchableFields() as $column) { - $query->orWhere($model->qualifyColumn($column), $likeOperator, '%' . $search . '%'); + $query->orWhere($model->qualifyColumn($column), $likeOperator, '%'.$search.'%'); } }); } diff --git a/tests/Controllers/RepositoryIndexControllerTest.php b/tests/Controllers/RepositoryIndexControllerTest.php index 8aeb0c865..8d53d6959 100644 --- a/tests/Controllers/RepositoryIndexControllerTest.php +++ b/tests/Controllers/RepositoryIndexControllerTest.php @@ -5,8 +5,6 @@ use Binaryk\LaravelRestify\Contracts\RestifySearchable; use Binaryk\LaravelRestify\Tests\Fixtures\Apple; use Binaryk\LaravelRestify\Tests\Fixtures\AppleRepository; -use Binaryk\LaravelRestify\Tests\Fixtures\Post; -use Binaryk\LaravelRestify\Tests\Fixtures\UserRepository; use Binaryk\LaravelRestify\Tests\IntegrationTest; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -80,12 +78,12 @@ public function test_repository_filter_works() public function test_repository_order() { AppleRepository::$sort = [ - 'title' + 'title', ]; - factory(Apple::class)->create(['title' => 'aaa',]); + factory(Apple::class)->create(['title' => 'aaa']); - factory(Apple::class)->create(['title' => 'zzz',]); + factory(Apple::class)->create(['title' => 'zzz']); $response = $this ->getJson('restify-api/apples?sort=-title') @@ -104,11 +102,11 @@ public function test_repository_order() public function test_repsitory_with_relations() { - AppleRepository::$related = ['user',]; + AppleRepository::$related = ['user']; $user = $this->mockUsers(1)->first(); - factory(Apple::class)->create(['user_id' => $user->id,]); + factory(Apple::class)->create(['user_id' => $user->id]); $response = $this->getJson('/restify-api/apples?related=user') ->assertStatus(200); diff --git a/tests/Factories/AppleFactory.php b/tests/Factories/AppleFactory.php index 214b873c2..8a0683d02 100644 --- a/tests/Factories/AppleFactory.php +++ b/tests/Factories/AppleFactory.php @@ -16,6 +16,6 @@ $factory->define(Apple::class, function (Faker $faker) { return [ - 'title' => $faker->text(50) + 'title' => $faker->text(50), ]; }); diff --git a/tests/Fixtures/Apple.php b/tests/Fixtures/Apple.php index 16388875b..3da2a42b0 100644 --- a/tests/Fixtures/Apple.php +++ b/tests/Fixtures/Apple.php @@ -10,12 +10,12 @@ class Apple extends Model protected $fillable = [ 'title', - 'user_id' + 'user_id', ]; public function user() { - return $this->belongsTo(User::class); + return $this->belongsTo(User::class); } public function toArray()