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