Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit 3954c95

Browse files
committed
Apply fixes from StyleCI
1 parent 32d470e commit 3954c95

21 files changed

+174
-138
lines changed

config/json-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
'authorisable' => [
2020
'viewAny' => false,
21-
'view' => false,
21+
'view' => false,
2222
],
2323

2424
/**

src/Builder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ public function jsonPaginate()
1212
/**
1313
* Paginate the given query using JSON:API.
1414
*
15-
* @param int|string $perPage
16-
* @param array $columns
15+
* @param int|string $perPage
16+
* @param array $columns
17+
*
1718
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
1819
*/
1920
return function ($perPage = null, $columns = ['*']) {
2021
$perPage = $perPage ?: $this->model->getPerPage();
2122
$clientPerPage = (int) request('page.size', config('json-api.pagination.default_size'));
2223

23-
if (! $perPage || $perPage < $clientPerPage) {
24+
if (!$perPage || $perPage < $clientPerPage) {
2425
$perPage = $clientPerPage;
2526
}
2627

src/Concerns/HasConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ trait HasConfig
77
/**
88
* Get authorisable from the app config.
99
*
10-
* @param mixed|null $key
10+
* @param mixed|null $key
11+
*
1112
* @return bool|null
1213
*/
1314
protected function getAuthorisableConfig($key = null)

src/Http/Resources/Authorizable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ trait Authorizable
1717
/**
1818
* Authorize to view this resource.
1919
*
20-
* @param mixed $resource
20+
* @param mixed $resource
21+
*
2122
* @return void
2223
*/
2324
protected function authorize($resource)
2425
{
2526
$this->authorise = $this->authorise
2627
?: $this->getAuthorisableConfig('view')
27-
?: ! $resource instanceof Model
28+
?: !$resource instanceof Model
2829
?: Gate::check('view', $resource);
2930

3031
return $this->authorise;

src/Http/Resources/CollectsResources.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ trait CollectsResources
1515
/**
1616
* Map the given collection resource into its individual resources.
1717
*
18-
* @param \Illuminate\Http\Resources\MissingValue|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection $resource
18+
* @param \Illuminate\Http\Resources\MissingValue|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection $resource
19+
*
1920
* @return mixed
2021
*/
2122
protected function collectResource($resource)
@@ -26,7 +27,7 @@ protected function collectResource($resource)
2627

2728
$collects = $this->collects();
2829

29-
$this->collection = $collects && ! $resource->first() instanceof $collects
30+
$this->collection = $collects && !$resource->first() instanceof $collects
3031
? $this->getFiltered($resource, $collects)
3132
: $resource->toBase();
3233

@@ -38,8 +39,9 @@ protected function collectResource($resource)
3839
/**
3940
* Get resource collection filtered by authorisation.
4041
*
41-
* @param mixed $resource
42-
* @param mixed $collects
42+
* @param mixed $resource
43+
* @param mixed $collects
44+
*
4345
* @return \Illuminate\Support\Collection
4446
*/
4547
protected function getFiltered($resource, $collects)
@@ -52,15 +54,15 @@ protected function getFiltered($resource, $collects)
5254
$authoriseKey = 'viewAny';
5355
$authorise = $this->authorise;
5456

55-
if (! $this->getAuthorisableConfig($authoriseKey) && gettype($this->authorise) !== 'boolean') {
57+
if (!$this->getAuthorisableConfig($authoriseKey) && gettype($this->authorise) !== 'boolean') {
5658
$authorise = Gate::check($authoriseKey, class_basename($item));
5759
}
5860

5961
return new $collects($item, $authorise);
6062
});
6163

6264
return $collection->filter(function (JsonApiResource $item) {
63-
return ! $item->resource instanceof MissingValue;
65+
return !$item->resource instanceof MissingValue;
6466
});
6567
}
6668

src/Http/Resources/CollectsWithIncludes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function withIncludes()
3434
$collectionIncludes
3535
)->values()->all();
3636

37-
if (! empty($includesArr)) {
37+
if (!empty($includesArr)) {
3838
Arr::set($this->with, $includedKey, $includesArr);
3939
}
4040
}

src/Http/Resources/Json/ResourceCollection.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class ResourceCollection extends JsonApiResource implements Countable, IteratorA
4545
/**
4646
* Create a new resource instance.
4747
*
48-
* @param mixed $resource
48+
* @param mixed $resource
49+
*
4950
* @return void
5051
*/
5152
public function __construct($resource)
@@ -68,7 +69,8 @@ public function preserveQuery()
6869
/**
6970
* Specify the query string parameters that should be present on pagination links.
7071
*
71-
* @param array $query
72+
* @param array $query
73+
*
7274
* @return $this
7375
*/
7476
public function withQuery(array $query)
@@ -93,7 +95,8 @@ public function count(): int
9395
/**
9496
* Transform the resource into a JSON array.
9597
*
96-
* @param \Illuminate\Http\Request $request
98+
* @param \Illuminate\Http\Request $request
99+
*
97100
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
98101
*/
99102
public function toArray($request)
@@ -104,7 +107,8 @@ public function toArray($request)
104107
/**
105108
* Create an HTTP response that represents the object.
106109
*
107-
* @param \Illuminate\Http\Request $request
110+
* @param \Illuminate\Http\Request $request
111+
*
108112
* @return \Illuminate\Http\JsonResponse
109113
*/
110114
public function toResponse($request)
@@ -119,7 +123,8 @@ public function toResponse($request)
119123
/**
120124
* Create a paginate-aware HTTP response.
121125
*
122-
* @param \Illuminate\Http\Request $request
126+
* @param \Illuminate\Http\Request $request
127+
*
123128
* @return \Illuminate\Http\JsonResponse
124129
*/
125130
protected function preparePaginatedResponse($request)

src/Http/Resources/JsonApiCollection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class JsonApiCollection extends ResourceCollection
1313
/**
1414
* Create a new resource instance.
1515
*
16-
* @param mixed $resource
17-
* @param bool|null $authorise
18-
* @param class-string<\SkoreLabs\JsonApi\Http\Resources\JsonApiResource>|null $collects
16+
* @param mixed $resource
17+
* @param bool|null $authorise
18+
* @param class-string<\SkoreLabs\JsonApi\Http\Resources\JsonApiResource>|null $collects
19+
*
1920
* @return void
2021
*/
2122
public function __construct($resource, $authorise = null, $collects = null)

src/Http/Resources/JsonApiResource.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class JsonApiResource extends JsonResource
2424
/**
2525
* Create a new resource instance.
2626
*
27-
* @param mixed $resource
28-
* @param bool|null $authorise
27+
* @param mixed $resource
28+
* @param bool|null $authorise
29+
*
2930
* @return void
3031
*/
3132
public function __construct($resource, $authorise = null)
@@ -43,15 +44,16 @@ public function __construct($resource, $authorise = null)
4344
/**
4445
* Transform the resource into an array.
4546
*
46-
* @param \Illuminate\Http\Request $request
47+
* @param \Illuminate\Http\Request $request
48+
*
4749
* @return array
4850
*/
4951
public function toArray($request)
5052
{
5153
if ($this->evaluateResponse()) {
5254
return [
5355
$this->merge($this->getResourceIdentifier()),
54-
'attributes' => $this->getAttributes(),
56+
'attributes' => $this->getAttributes(),
5557
'relationships' => $this->when($this->relationships, $this->relationships),
5658
];
5759
}
@@ -66,9 +68,9 @@ public function toArray($request)
6668
*/
6769
protected function evaluateResponse()
6870
{
69-
return ! is_array($this->resource)
71+
return !is_array($this->resource)
7072
&& $this->resource !== null
71-
&& ! $this->resource instanceof MissingValue;
73+
&& !$this->resource instanceof MissingValue;
7274
}
7375

7476
/**
@@ -80,7 +82,7 @@ public function getResourceIdentifier()
8082
{
8183
return [
8284
$this->resource->getKeyName() => (string) $this->resource->getKey(),
83-
'type' => JsonApi::getResourceType($this->resource),
85+
'type' => JsonApi::getResourceType($this->resource),
8486
];
8587
}
8688

@@ -94,7 +96,7 @@ protected function getAttributes()
9496
return array_filter(
9597
array_merge($this->resource->attributesToArray(), $this->withAttributes()),
9698
function ($value, $key) {
97-
return ! Str::endsWith($key, '_id') && $key !== $this->resource->getKeyName() && $value !== null;
99+
return !Str::endsWith($key, '_id') && $key !== $this->resource->getKeyName() && $value !== null;
98100
},
99101
ARRAY_FILTER_USE_BOTH
100102
);

src/Http/Resources/RelationshipsWithIncludes.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ protected function withRelationships()
3737
/**
3838
* Attach relationships to the resource.
3939
*
40-
* @param \Illuminate\Database\Eloquent\Model $model
40+
* @param \Illuminate\Database\Eloquent\Model $model
41+
*
4142
* @return void
4243
*/
4344
protected function attachRelations(Model $model)
@@ -71,7 +72,8 @@ protected function attachRelations(Model $model)
7172
/**
7273
* Process a model relation attaching to its model additional attributes.
7374
*
74-
* @param \Illuminate\Database\Eloquent\Model $model
75+
* @param \Illuminate\Database\Eloquent\Model $model
76+
*
7577
* @return array
7678
*/
7779
protected function processModelRelation(Model $model)
@@ -81,7 +83,7 @@ protected function processModelRelation(Model $model)
8183
$modelResource = new $modelResourceClass($model, $this->authorise);
8284
$modelIdentifier = $modelResource->getResourceIdentifier();
8385

84-
if (! empty(Arr::get($modelIdentifier, $model->getKeyName(), null))) {
86+
if (!empty(Arr::get($modelIdentifier, $model->getKeyName(), null))) {
8587
$this->addIncluded($modelResource);
8688

8789
return $modelIdentifier;
@@ -94,6 +96,7 @@ protected function processModelRelation(Model $model)
9496
* Set included data to resource's with.
9597
*
9698
* @param $resource
99+
*
97100
* @return void
98101
*/
99102
protected function addIncluded(JsonApiResource $resource)
@@ -108,7 +111,7 @@ protected function addIncluded(JsonApiResource $resource)
108111
$includesCol
109112
)->values()->all();
110113

111-
if (! empty($includesArr)) {
114+
if (!empty($includesArr)) {
112115
Arr::set($this->with, $this->getIncludedConfig(), $includesArr);
113116
}
114117
}
@@ -127,6 +130,7 @@ public function getIncluded()
127130
* Check and return unique resources on a collection.
128131
*
129132
* @param \Illuminate\Support\Collection
133+
*
130134
* @return \Illuminate\Support\Collection
131135
*/
132136
protected function checkUniqueness(Collection $collection)
@@ -139,7 +143,8 @@ protected function checkUniqueness(Collection $collection)
139143
/**
140144
* Get API resource from model.
141145
*
142-
* @param \Illuminate\Database\Eloquent\Model $model
146+
* @param \Illuminate\Database\Eloquent\Model $model
147+
*
143148
* @return string
144149
*/
145150
protected function getModelResource(Model $model)

0 commit comments

Comments
 (0)