Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| BrandStatsResource | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| toArray | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources\Api\V2; |
| 4 | |
| 5 | use App\Models\BrandStat; |
| 6 | use Illuminate\Http\Resources\Json\ResourceCollection as JsonResourceCollection; |
| 7 | |
| 8 | class 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 | } |