Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| BrandStatsResource | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources\Api\V2; |
| 4 | |
| 5 | use App\Models\BrandStat; |
| 6 | use Illuminate\Http\Request; |
| 7 | use Illuminate\Http\Resources\Json\ResourceCollection as JsonResourceCollection; |
| 8 | |
| 9 | class BrandStatsResource extends JsonResourceCollection |
| 10 | { |
| 11 | /** |
| 12 | * Transform the resource into an array. |
| 13 | * |
| 14 | * @param \Illuminate\Http\Request $request |
| 15 | * @return array |
| 16 | * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass |
| 17 | */ |
| 18 | public function toArray(Request $request): array |
| 19 | { |
| 20 | //phpcs:enable |
| 21 | return [ |
| 22 | 'stats' => $this->collection->map(function (BrandStat $brandStat) { |
| 23 | return [ |
| 24 | 'date' => $brandStat->created_at->isoFormat('YYYY-MM-DD'), |
| 25 | 'active' => $brandStat->active, |
| 26 | 'inactive' => $brandStat->inactive, |
| 27 | 'old_accounts' => $brandStat->old_accounts, |
| 28 | 'new_accounts' => $brandStat->new_accounts, |
| 29 | 'total_accounts' => $brandStat->total_accounts, |
| 30 | 'total_opt_in' => $brandStat->total_opt_in |
| 31 | ]; |
| 32 | }) |
| 33 | ]; |
| 34 | } |
| 35 | } |