Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
RoleplayLevelBucket
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\DTO\Report;
4
5/**
6 * Immutable value object representing a single roleplay-level distribution
7 * bucket in the "roleplay levels" admin report response.
8 *
9 * @property-read string $key         Machine key (needs_work, developing, …)
10 * @property-read string $label       Human-readable label ("Needs Work", …)
11 * @property-read int    $count       Number of users in this bucket
12 * @property-read float  $percentage  Percentage of the total (0-100, 2 decimals)
13 */
14final class RoleplayLevelBucket
15{
16    /**
17     * @param  string  $key  Machine key for the level bucket
18     * @param  string  $label  Human-readable label
19     * @param  int  $count  Number of users counted in this bucket
20     * @param  float  $percentage  Percentage of the overall cohort (2 decimals)
21     */
22    public function __construct(
23        public readonly string $key,
24        public readonly string $label,
25        public readonly int $count,
26        public readonly float $percentage,
27    ) {}
28
29    /**
30     * Convert the bucket to its JSON-friendly array shape.
31     *
32     * @return array{key: string, label: string, count: int, percentage: float}
33     */
34    public function toArray(): array
35    {
36        return [
37            'key' => $this->key,
38            'label' => $this->label,
39            'count' => $this->count,
40            'percentage' => $this->percentage,
41        ];
42    }
43}