Skip to content

Commit 3b0b42a

Browse files
committed
wip
1 parent dbd94d6 commit 3b0b42a

File tree

10 files changed

+27
-73
lines changed

10 files changed

+27
-73
lines changed

src/Concerns/Identification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private function resolveType(Request $request)
125125
*/
126126
private static function idResolver()
127127
{
128-
return self::$idResolver ?? function (mixed $resource, Request $request): string {
128+
return self::$idResolver ??= function (mixed $resource, Request $request): string {
129129
if (! $resource instanceof Model) {
130130
throw ResourceIdentificationException::attemptingToDetermineIdFor($resource);
131131
}
@@ -144,7 +144,7 @@ private static function idResolver()
144144
*/
145145
private static function typeResolver()
146146
{
147-
return self::$typeResolver ?? function (mixed $resource, Request $request): string {
147+
return self::$typeResolver ??= function (mixed $resource, Request $request): string {
148148
if (! $resource instanceof Model) {
149149
throw ResourceIdentificationException::attemptingToDetermineTypeFor($resource);
150150
}

src/Concerns/Implementation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public static function resolveServerImplementationNormally()
4444
*/
4545
public static function serverImplementationResolver()
4646
{
47-
return self::$serverImplementationResolver ?? fn (Request $request): ServerImplementation => new ServerImplementation('1.0');
47+
return self::$serverImplementationResolver ??= fn (Request $request): ServerImplementation => new ServerImplementation('1.0');
4848
}
4949
}

src/Concerns/Relationships.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private function shouldBePresentInIncludes()
186186
*/
187187
private static function guessRelationshipResource(string $relationship, JsonApiResource $resource)
188188
{
189-
return (self::$relationshipResourceGuesser ?? function (string $relationship, JsonApiResource $resource): string {
189+
return (self::$relationshipResourceGuesser ??= function (string $relationship, JsonApiResource $resource): string {
190190
$relationship = Str::of($relationship);
191191

192192
foreach ([

src/Exceptions/ResourceIdentificationException.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,28 @@
99
use function gettype;
1010
use function is_object;
1111

12+
/**
13+
* @internal
14+
*/
1215
final class ResourceIdentificationException extends RuntimeException
1316
{
1417
/**
15-
* @internal
16-
*
1718
* @return self
1819
*/
1920
public static function attemptingToDetermineIdFor(mixed $resource)
2021
{
21-
return new static('Unable to resolve resource object id for ['.static::determineType($resource).'].');
22+
return new self('Unable to resolve resource object id for ['.static::determineType($resource).'].');
2223
}
2324

2425
/**
25-
* @internal
26-
*
2726
* @return self
2827
*/
2928
public static function attemptingToDetermineTypeFor(mixed $resource)
3029
{
31-
return new static('Unable to resolve resource object type for ['.static::determineType($resource).'].');
30+
return new self('Unable to resolve resource object type for ['.static::determineType($resource).'].');
3231
}
3332

3433
/**
35-
* @internal
36-
*
3734
* @return string
3835
*/
3936
private static function determineType(mixed $resource)

src/Exceptions/UnknownRelationshipException.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
use function gettype;
1212
use function is_object;
1313

14+
/**
15+
* @internal
16+
*/
1417
final class UnknownRelationshipException extends Exception
1518
{
1619
/**
17-
* @internal
18-
*
1920
* @return self
2021
*/
2122
public static function from(mixed $resource)
@@ -24,8 +25,6 @@ public static function from(mixed $resource)
2425
}
2526

2627
/**
27-
* @internal
28-
*
2928
* @return string
3029
*/
3130
private static function determineType(mixed $resource)

src/JsonApiResource.php

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Illuminate\Http\Resources\PotentiallyMissing;
1111
use Illuminate\Support\Collection;
1212
use stdClass;
13-
1413
use function property_exists;
1514

1615
abstract class JsonApiResource extends JsonResource
@@ -25,8 +24,6 @@ abstract class JsonApiResource extends JsonResource
2524
use Concerns\Relationships;
2625

2726
/**
28-
* @api
29-
*
3027
* @return array<string, mixed>
3128
*/
3229
public function toAttributes(Request $request)
@@ -37,8 +34,6 @@ public function toAttributes(Request $request)
3734
}
3835

3936
/**
40-
* @api
41-
*
4237
* @return array<string, (callable(): JsonApiResource|JsonApiResourceCollection|PotentiallyMissing)>
4338
*/
4439
public function toRelationships(Request $request)
@@ -49,8 +44,6 @@ public function toRelationships(Request $request)
4944
}
5045

5146
/**
52-
* @api
53-
*
5447
* @return array<int, Link>
5548
*/
5649
public function toLinks(Request $request)
@@ -61,8 +54,6 @@ public function toLinks(Request $request)
6154
}
6255

6356
/**
64-
* @api
65-
*
6657
* @return array<string, mixed>
6758
*/
6859
public function toMeta(Request $request)
@@ -73,8 +64,6 @@ public function toMeta(Request $request)
7364
}
7465

7566
/**
76-
* @api
77-
*
7867
* @return string
7968
*/
8069
public function toId(Request $request)
@@ -83,8 +72,6 @@ public function toId(Request $request)
8372
}
8473

8574
/**
86-
* @api
87-
*
8875
* @return string
8976
*/
9077
public function toType(Request $request)
@@ -93,8 +80,6 @@ public function toType(Request $request)
9380
}
9481

9582
/**
96-
* @api
97-
*
9883
* @return RelationshipObject
9984
*/
10085
public function toResourceLink(Request $request)
@@ -105,8 +90,6 @@ public function toResourceLink(Request $request)
10590
}
10691

10792
/**
108-
* @api
109-
*
11093
* @return ResourceIdentifier
11194
*/
11295
public function toResourceIdentifier(Request $request)
@@ -115,12 +98,9 @@ public function toResourceIdentifier(Request $request)
11598
}
11699

117100
/**
118-
* @api
119-
*
120-
* @param Request $request
121101
* @return array{id: string, type: string, attributes?: stdClass, relationships?: stdClass, meta?: stdClass, links?: stdClass}
122102
*/
123-
public function toArray($request)
103+
public function toArray(Request $request)
124104
{
125105
return [
126106
'id' => $this->resolveId($request),
@@ -135,12 +115,9 @@ public function toArray($request)
135115
}
136116

137117
/**
138-
* @api
139-
*
140-
* @param Request $request
141-
* @return array{included: Collection<int, JsonApiResource>, jsonapi: JsonApiServerImplementation}
118+
* @return array{included?: Collection<int, JsonApiResource>, jsonapi: JsonApiServerImplementation}
142119
*/
143-
public function with($request)
120+
public function with(Request $request)
144121
{
145122
return [
146123
...($included = $this->included($request)
@@ -152,12 +129,9 @@ public function with($request)
152129
}
153130

154131
/**
155-
* @api
156-
*
157-
* @param mixed $resource
158132
* @return JsonApiResourceCollection<int, mixed>
159133
*/
160-
public static function collection($resource)
134+
public static function collection(mixed $resource)
161135
{
162136
return tap(static::newCollection($resource), function (JsonApiResourceCollection $collection): void {
163137
if (property_exists(static::class, 'preserveKeys')) {
@@ -168,8 +142,6 @@ public static function collection($resource)
168142
}
169143

170144
/**
171-
* @api
172-
*
173145
* @return JsonApiResourceCollection<int, mixed>
174146
*/
175147
public static function newCollection(mixed $resource)
@@ -178,8 +150,6 @@ public static function newCollection(mixed $resource)
178150
}
179151

180152
/**
181-
* @api
182-
*
183153
* @param Request $request
184154
* @return JsonResponse
185155
*/

src/JsonApiResourceCollection.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class JsonApiResourceCollection extends AnonymousResourceCollection
1313
use Concerns\RelationshipLinks;
1414

1515
/**
16-
* @api
17-
*
1816
* @param (callable(JsonApiResource): JsonApiResource) $callback
1917
* @return $this
2018
*/
@@ -26,8 +24,6 @@ public function map(callable $callback)
2624
}
2725

2826
/**
29-
* @api
30-
*
3127
* @return RelationshipObject
3228
*/
3329
public function toResourceLink(Request $request)
@@ -36,8 +32,6 @@ public function toResourceLink(Request $request)
3632
}
3733

3834
/**
39-
* @internal
40-
*
4135
* @return Collection<int, ResourceIdentifier>
4236
*/
4337
private function resolveResourceIdentifiers(Request $request)
@@ -48,12 +42,9 @@ private function resolveResourceIdentifiers(Request $request)
4842
}
4943

5044
/**
51-
* @api
52-
*
53-
* @param Request $request
54-
* @return array{included: Collection<int, JsonApiResource>, jsonapi: JsonApiServerImplementation}
45+
* @return array{included?: Collection<int, JsonApiResource>, jsonapi: JsonApiServerImplementation}
5546
*/
56-
public function with($request)
47+
public function with(Request $request)
5748
{
5849
return [
5950
...($included = $this->collection
@@ -67,8 +58,6 @@ public function with($request)
6758
}
6859

6960
/**
70-
* @api
71-
*
7261
* @param Request $request
7362
* @return \Illuminate\Http\JsonResponse
7463
*/
@@ -78,14 +67,11 @@ public function toResponse($request)
7867
}
7968

8069
/**
81-
* @api
82-
*
83-
* @param Request $request
8470
* @param array<array-key, mixed> $paginated
8571
* @param array{links: array<string, ?string>} $default
8672
* @return array{links: array<string, string>}
8773
*/
88-
public function paginationInformation($request, $paginated, $default)
74+
public function paginationInformation(Request $request, array $paginated, array $default)
8975
{
9076
if (isset($default['links'])) {
9177
$default['links'] = array_filter($default['links'], fn (?string $link): bool => $link !== null);

src/Link.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ final class Link implements JsonSerializable
2020

2121
/**
2222
* @param array<string, mixed> $meta
23+
* @return self
2324
*/
24-
public static function self(string $href, array $meta = []): self
25+
public static function self(string $href, array $meta = [])
2526
{
2627
return new self('self', $href, $meta);
2728
}
2829

2930
/**
3031
* @param array<string, mixed> $meta
32+
* @return self
3133
*/
32-
public static function related(string $href, array $meta = []): self
34+
public static function related(string $href, array $meta = [])
3335
{
3436
return new self('related', $href, $meta);
3537
}

src/RelationshipObject.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ final class RelationshipObject implements JsonSerializable
2020
/**
2121
* @param array<int, Link> $links
2222
* @param array<string, mixed> $meta
23+
* @return self
2324
*/
24-
public static function toOne(ResourceIdentifier|null $data, array $links = [], array $meta = []): self
25+
public static function toOne(ResourceIdentifier|null $data, array $links = [], array $meta = [])
2526
{
2627
return new self($data, $links, $meta);
2728
}
@@ -30,8 +31,9 @@ public static function toOne(ResourceIdentifier|null $data, array $links = [], a
3031
* @param array<int, ResourceIdentifier> $data
3132
* @param array<int, Link> $links
3233
* @param array<string, mixed> $meta
34+
* @return self
3335
*/
34-
public static function toMany(array $data, array $links = [], array $meta = []): self
36+
public static function toMany(array $data, array $links = [], array $meta = [])
3537
{
3638
return new self($data, $links, $meta);
3739
}
@@ -50,7 +52,6 @@ private function __construct(ResourceIdentifier|array|null $data, array $links =
5052
$this->meta = $meta;
5153
}
5254

53-
5455
/**
5556
* @return array{data: ResourceIdentifier|null|array<int, ResourceIdentifier>, meta?: stdClass, links?: stdClass}
5657
*/

src/Support/Includes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Support\Str;
1010
use Symfony\Component\HttpKernel\Exception\HttpException;
1111
use WeakMap;
12-
1312
use function explode;
1413
use function is_array;
1514

0 commit comments

Comments
 (0)