Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
RemoteConfigHistoryResource
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 toArray
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Resources\v2;
4
5use App\Http\Models\RemoteConfig;
6use Illuminate\Http\Request;
7use Illuminate\Http\Resources\Json\JsonResource;
8
9/**
10 * Resource for transforming RemoteConfigHistory models for API responses.
11 *
12 * Returns a summary of each history entry including which sections
13 * were present in the snapshot at that point in time.
14 *
15 * @property string $version The config version identifier
16 * @property string $changed_by Who made this change
17 * @property string|null $change_description Description of the change
18 * @property array $snapshot Full config snapshot
19 * @property \Carbon\Carbon|null $created_at
20 */
21class RemoteConfigHistoryResource extends JsonResource
22{
23    /**
24     * Transform the resource into an array.
25     *
26     * @return array<string, mixed>
27     */
28    public function toArray(Request $request): array
29    {
30        $snapshot = $this->snapshot ?? [];
31
32        return [
33            'version' => $this->version,
34            'changed_by' => $this->changed_by,
35            'change_description' => $this->change_description,
36            'sections_present' => collect(RemoteConfig::SECTIONS)
37                ->filter(fn ($s) => ($snapshot[$s] ?? null) !== null)
38                ->values()
39                ->all(),
40            'created_at' => $this->created_at?->timestamp,
41        ];
42    }
43}