Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CustomerResource
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Resources;
4
5use Illuminate\Http\Request;
6use Illuminate\Http\Resources\Json\JsonResource;
7
8class CustomerResource extends JsonResource
9{
10    /** @var integer */
11    private $brandId;
12
13    /**
14     * @param mixed   $resource
15     * @param integer $brandId
16     */
17    public function __construct(mixed $resource, int $brandId)
18    {
19        parent::__construct($resource);
20        $this->brandId = $brandId;
21    }
22
23    /**
24     * Transform the resource into an array.
25     *
26     * @param \Illuminate\Http\Request $request
27     * @return array
28     * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
29     */
30    public function toArray(Request $request): array
31    {
32        //phpcs:disable
33        /** @var \App\Models\CustomerInfo */
34        $infos = $this->infos()->where('brand_id', $this->brandId)->first();
35        /** @var \App\Models\CustomerLogin */
36        $login = $this->logins()->where('brand_id', $this->brandId)->first();
37        return [
38            'status' => 'OK',
39            'user' => [
40                'crm_id'     => $this->id,
41                'firstname'  => $infos->firstname,
42                'lastname'   => $infos->lastname,
43                'email'      => $this->email,
44                'birth_date' => $infos->birth_date,
45                'address'    => $infos->address,
46                'address2'   => $infos->address2,
47                'phone'      => $infos->phone,
48                'country'    => $infos->country->label(),
49                'city'       => $infos->city,
50                'postcode'   => $infos->postcode,
51                'opt_in'     => $infos->opt_in,
52                'hashcode'   => $infos->hashcode,
53                'status'     => $login->status,
54            ]
55        ];
56    }
57}