Skip to content

Commit 3513e77

Browse files
committed
fix: phpstan
1 parent 51bc0c8 commit 3513e77

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Resources/Concerns/PrepareData.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Ark4ne\JsonApi\Descriptors\Resolver;
66
use Illuminate\Http\Request;
7+
use Illuminate\Http\Resources\Json\JsonResource;
78
use Illuminate\Http\Resources\MergeValue;
89
use Illuminate\Http\Resources\PotentiallyMissing;
910
use Illuminate\Support\Arr;
@@ -69,14 +70,19 @@ protected function mergeValues(iterable $data): array
6970
/**
7071
* Merge two array without erase concrete value by missing value.
7172
*
72-
* @param array $array
73-
* @param array $merge
74-
* @return array
73+
* @template TKey1 as array-key
74+
* @template TValue1
75+
* @template TKey2 as array-key
76+
* @template TValue2
77+
*
78+
* @param array<TKey1, TValue1> $array
79+
* @param array<TKey2, TValue2> $merge
80+
* @return array<TKey1&TKey2, TValue1&TValue2>
7581
*/
7682
private function mergeIgnoreMissing(array $array, array $merge): array
7783
{
7884
foreach ($merge as $key => $item) {
79-
if (!isset($array[$key]) || $this->isValueMissing($array[$key]) || !$this->isValueMissing($item)) {
85+
if (!isset($array[$key]) || $this->isMissing($array[$key]) || !$this->isMissing($item)) {
8086
$array[$key] = $item;
8187
}
8288
}
@@ -85,16 +91,15 @@ private function mergeIgnoreMissing(array $array, array $merge): array
8591
}
8692

8793
/**
88-
* Check if a value is missing
94+
* @param mixed|PotentiallyMissing|JsonResource $resource
8995
*
90-
* @param $value
9196
* @return bool
9297
*/
93-
protected function isValueMissing($value): bool
98+
private function isMissing(mixed $resource): bool
9499
{
95-
return ($value instanceof PotentiallyMissing && $value->isMissing()) ||
96-
($value instanceof self &&
97-
$value->resource instanceof PotentiallyMissing &&
98-
$value->isMissing());
100+
return ($resource instanceof PotentiallyMissing && $resource->isMissing())
101+
|| ($resource instanceof JsonResource &&
102+
$resource->resource instanceof PotentiallyMissing &&
103+
$resource->resource->isMissing());
99104
}
100105
}

0 commit comments

Comments
 (0)