Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| RoleplayLevelsResource | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources\v2\Admin\Report; |
| 4 | |
| 5 | use Illuminate\Http\Request; |
| 6 | use Illuminate\Http\Resources\Json\JsonResource; |
| 7 | |
| 8 | /** |
| 9 | * API resource wrapping the roleplay level distribution report into the |
| 10 | * standard FlyMSG `{"result": {"status": "success", "data": ...}}` shape. |
| 11 | * |
| 12 | * The underlying service already returns the canonical |
| 13 | * `['total_users' => int, 'levels' => [...]]` payload; this resource simply |
| 14 | * attaches the `status` flag and keeps the transformation in the versioned |
| 15 | * Resources tree to match the rest of the codebase. |
| 16 | * |
| 17 | * @property array{total_users: int, levels: array<int, array{key: string, label: string, count: int, percentage: float}>} $resource |
| 18 | */ |
| 19 | class RoleplayLevelsResource extends JsonResource |
| 20 | { |
| 21 | /** |
| 22 | * Transform the resource into an array. |
| 23 | * |
| 24 | * @param Request $request Current HTTP request |
| 25 | * @return array{status: string, data: array{total_users: int, levels: array<int, array{key: string, label: string, count: int, percentage: float}>}} |
| 26 | */ |
| 27 | public function toArray($request): array |
| 28 | { |
| 29 | return [ |
| 30 | 'status' => 'success', |
| 31 | 'data' => [ |
| 32 | 'total_users' => $this->resource['total_users'], |
| 33 | 'levels' => $this->resource['levels'], |
| 34 | ], |
| 35 | ]; |
| 36 | } |
| 37 | } |