Skip to content

Commit 701d921

Browse files
committed
fix: phpstan
1 parent 420e569 commit 701d921

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

src/Descriptors/Relations/Relation.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public function whenIncluded(): static
6868
*
6969
* @param string|null $relation
7070
*
71-
* @return $this
71+
* @return static
7272
*/
73-
public function whenLoaded(string $relation = null): static
73+
public function whenLoaded(string $relation = null): self
7474
{
7575
return $this->when(fn(
7676
Request $request,
@@ -85,9 +85,9 @@ public function whenLoaded(string $relation = null): static
8585
* @param string $table
8686
* @param string|null $accessor
8787
*
88-
* @return $this
88+
* @return static
8989
*/
90-
public function whenPivotLoaded(string $table, string $accessor = null): static
90+
public function whenPivotLoaded(string $table, string $accessor = null): self
9191
{
9292
return $this->when(fn(
9393
Request $request,

src/Resources/Concerns/ConditionallyLoadsAttributes.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ trait ConditionallyLoadsAttributes
1313
/**
1414
* Retrieve a relationship if it has been present in fields.
1515
*
16-
* @template T
16+
* @template K
1717
*
1818
* @param \Illuminate\Http\Request $request
1919
* @param string $attribute
20-
* @param T $value
20+
* @param K $value
2121
*
22-
* @return \Illuminate\Http\Resources\MissingValue|T
22+
* @return \Illuminate\Http\Resources\MissingValue|K
2323
*/
2424
protected function whenInFields(Request $request, string $attribute, mixed $value)
2525
{
@@ -29,13 +29,13 @@ protected function whenInFields(Request $request, string $attribute, mixed $valu
2929
/**
3030
* Retrieve a relationship if it has been included.
3131
*
32-
* @template T
32+
* @template K
3333
*
3434
* @param \Illuminate\Http\Request $request
3535
* @param string $type
36-
* @param T $value
36+
* @param K $value
3737
*
38-
* @return \Illuminate\Http\Resources\MissingValue|T
38+
* @return \Illuminate\Http\Resources\MissingValue|K
3939
*/
4040
protected function whenIncluded(Request $request, string $type, mixed $value)
4141
{

src/Resources/Concerns/Links.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ protected function toLinks(Request $request): ?iterable
2929
/**
3030
* @param \Illuminate\Http\Request $request
3131
*
32-
* @return array<string, mixed>|null
32+
* @return array<string, mixed>
3333
*/
34-
private function requestedLinks(Request $request): ?array
34+
private function requestedLinks(Request $request): array
3535
{
3636
return $this->prepareData($request, $this->toLinks($request));
3737
}

src/Resources/Concerns/Meta.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ protected function toMeta(Request $request): ?iterable
4343
/**
4444
* @param \Illuminate\Http\Request $request
4545
*
46-
* @return array<string, mixed>|null
46+
* @return array<string, mixed>
4747
*/
48-
private function requestedResourceMeta(Request $request): ?array
48+
private function requestedResourceMeta(Request $request): array
4949
{
5050
return $this->prepareData($request, $this->toResourceMeta($request));
5151
}
5252

5353
/**
5454
* @param \Illuminate\Http\Request $request
5555
*
56-
* @return array<string, mixed>|null
56+
* @return array<string, mixed>
5757
*/
58-
private function requestedMeta(Request $request): ?array
58+
private function requestedMeta(Request $request): array
5959
{
6060
return $this->prepareData($request, $this->toMeta($request));
6161
}

src/Resources/Concerns/PrepareData.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ trait PrepareData
1212
use Resolver;
1313

1414
/**
15-
* @template TKey extends array-key
15+
* @template TKey as array-key
1616
* @template TValue
1717
*
18-
* @param iterable<TKey, TValue> $data
18+
* @param \Illuminate\Http\Request $request
19+
* @param iterable<TKey, TValue>|null $data
1920
*
2021
* @return iterable<TKey, TValue>
2122
*/
@@ -25,7 +26,7 @@ protected function prepareData(Request $request, ?iterable $data): iterable
2526
}
2627

2728
/**
28-
* @template TKey extends array-key
29+
* @template TKey as array-key
2930
* @template TValue
3031
*
3132
* @param iterable<TKey, TValue> $data

tests/app/Http/Resources/PostResource.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function toRelationships(Request $request): iterable
4242
'self' => "https://api.example.com/posts/{$this->resource->id}/relationships/comments",
4343
'related' => "https://api.example.com/posts/{$this->resource->id}/comments",
4444
])->meta(fn() => [
45-
'total' => $this->resource->comments()->count(),
45+
'total' => $this->resource->comments()->getQuery()->count(),
4646
]),
4747
];
4848
}

tests/app/Http/Resources/UserResource.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function toRelationships(Request $request): iterable
4343
'self' => "https://api.example.com/user/{$this->resource->id}/relationships/posts",
4444
'related' => "https://api.example.com/user/{$this->resource->id}/posts",
4545
], fn() => [
46-
'total' => $this->resource->posts()->count(),
46+
'total' => $this->resource->posts()->getQuery()->count(),
4747
])
4848
->asCollection(),
4949

@@ -54,7 +54,7 @@ protected function toRelationships(Request $request): iterable
5454
'related' => "https://api.example.com/user/{$this->resource->id}/comments",
5555
])
5656
->meta(fn() => [
57-
'total' => $this->resource->comments()->count(),
57+
'total' => $this->resource->comments()->getQuery()->count(),
5858
]),
5959
];
6060
}

0 commit comments

Comments
 (0)