Conditions | 6 |
Paths | 17 |
Total Lines | 20 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
18 | public function toArray($request): array |
||
19 | { |
||
20 | // Ensure the resource is an array with the expected structure |
||
21 | if (!is_array($this->resource)) { |
||
22 | return [ |
||
23 | 'previous' => null, |
||
24 | 'next' => null, |
||
25 | ]; |
||
26 | } |
||
27 | |||
28 | // Cast to proper array type for PHPStan |
||
29 | /** @var array<string, null|\CSlant\Blog\Core\Models\Post> $navigationData */ |
||
30 | $navigationData = $this->resource; |
||
31 | |||
32 | $previous = array_key_exists('previous', $navigationData) ? $navigationData['previous'] : null; |
||
33 | $next = array_key_exists('next', $navigationData) ? $navigationData['next'] : null; |
||
34 | |||
35 | return [ |
||
36 | 'previous' => $previous ? new PostNavigationResource($previous) : null, |
||
37 | 'next' => $next ? new PostNavigationResource($next) : null, |
||
38 | ]; |
||
41 |