CandidateResource::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 21
rs 9.6333
1
<?php
2
3
namespace App\Http\Resources;
4
5
use App\Repositories\CandidatesRepository;
6
use App\Utils\PhoneFormatter;
7
use Illuminate\Http\Resources\Json\JsonResource;
8
9
class CandidateResource extends JsonResource
10
{
11
    /**
12
     * Transform the resource into an array.
13
     *
14
     * @param \Illuminate\Http\Request $request
15
     *
16
     * @return array
17
     */
18
    public function toArray($request)
19
    {
20
        return [
21
            'id'                    => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
            'created_at'            => $this->created_at,
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
            'updated_at'            => $this->updated_at,
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
24
            'name'                  => $this->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
            'email'                 => $this->email,
0 ignored issues
show
Bug Best Practice introduced by
The property email does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
26
            'phone_number'          => PhoneFormatter::format($this->phone_number),
0 ignored issues
show
Bug Best Practice introduced by
The property phone_number does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
27
            'future_agreement'      => $this->future_agreement,
0 ignored issues
show
Bug Best Practice introduced by
The property future_agreement does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
28
            'path_to_cv'            => $this->path_to_cv,
0 ignored issues
show
Bug Best Practice introduced by
The property path_to_cv does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            'source_id'             => $this->source_id,
0 ignored issues
show
Bug Best Practice introduced by
The property source_id does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
            'recruitment_id'        => $this->recruitment_id,
0 ignored issues
show
Bug Best Practice introduced by
The property recruitment_id does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
            'source_recruitment_id' => $this->source_recruitment_id,
0 ignored issues
show
Bug Best Practice introduced by
The property source_recruitment_id does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
            'stage_id'              => $this->stage_id,
0 ignored issues
show
Bug Best Practice introduced by
The property stage_id does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
            'rate'                  => $this->rate,
0 ignored issues
show
Bug Best Practice introduced by
The property rate does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'otherApplications'     => $this->otherApplications(),
35
            'source'                => $this->source,
0 ignored issues
show
Bug Best Practice introduced by
The property source does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            'recruitment'           => $this->recruitment,
0 ignored issues
show
Bug Best Practice introduced by
The property recruitment does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
            'stage'                 => $this->stage,
0 ignored issues
show
Bug Best Practice introduced by
The property stage does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
            'custom_fields'         => json_decode($this->custom_fields),
0 ignored issues
show
Bug Best Practice introduced by
The property custom_fields does not exist on App\Http\Resources\CandidateResource. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
        ];
40
    }
41
42
    protected function otherApplications()
43
    {
44
        $allowedFields = ['id', 'created_at', 'recruitment_id', 'stage_id', 'recruitment'];
45
46
        $otherApplications = CandidatesRepository::getOtherApplications($this->resource);
47
        $filtered = [];
48
49
        foreach ($otherApplications as $application) {
50
            $filtered[] = array_intersect_key($application->toArray(), array_flip($allowedFields));
51
        }
52
53
        return $filtered;
54
    }
55
}
56