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