Passed
Push — feature/job-builder/base ( bc057a...5f28ca )
by Tristan
12:23 queued 05:14
created

JobApiController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use Illuminate\Http\Request;
6
use App\Http\Controllers\Controller;
7
use App\Models\JobPoster;
8
use App\Models\Criteria;
9
use App\Services\Validation\JobPosterValidator;
10
use App\Http\Requests\UpdateJobPoster;
11
12
class JobApiController extends Controller
13
{
14
    /**
15
     * Class constructor
16
     */
17 5
    public function __construct()
18
    {
19
        // This applies the appropriate policy to each resource route.
20 5
        $this->authorizeResource(JobPoster::class, 'job');
21 5
    }
22
23
    /**
24
     * Convert a job poster to the array expected by API requests,
25
     * with all criteria,
26
     * and with translation arrays in both languages.
27
     *
28
     * @param  \App\Models\JobPoster $job Incoming Job Poster object.
29
     * @return mixed[]
30
     */
31 3
    private function jobToArray(JobPoster $job)
32
    {
33 3
        $criteria = Criteria::where('job_poster_id', $job->id)->get();
34 3
        $criteriaTranslated = [];
35 3
        foreach ($criteria as $criterion) {
36 3
            $criteriaTranslated[] = array_merge($criterion->toArray(), $criterion->getTranslationsArray());
37
        }
38 3
        $jobArray = array_merge($job->toApiArray(), ['criteria' => $criteriaTranslated]);
39 3
        return $jobArray;
40
    }
41
    /**
42
     * Display a listing of the resource.
43
     *
44
     * @return \Illuminate\Http\Response
1 ignored issue
show
Coding Style introduced by
Function return type is not void, but function has no return statement
Loading history...
45
     */
46
    public function index()
47
    {
48
        // TODO: complete.
49
    }
50
51
    /**
52
     * Store a newly created resource in storage.
53
     *
54
     * @param  \Illuminate\Http\Request $request Incoming request.
55
     * @return \Illuminate\Http\Response
1 ignored issue
show
Coding Style introduced by
Function return type is not void, but function has no return statement
Loading history...
56
     */
57
    public function store(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

57
    public function store(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        // TODO: complete.
60
    }
61
62
    /**
63
     * Display the specified resource.
64
     *
65
     * @param  \App\Models\JobPoster $job Incoming Job Poster.
66
     * @return \Illuminate\Http\Response
67
     */
68 1
    public function show(JobPoster $job)
69
    {
70 1
        return $this->jobToArray($job);
71
    }
72
73
    /**
74
     * Update the specified resource in storage.
75
     *
76
     * @param  \App\Http\Requests\UpdateJobPoster $request Validates input.
77
     * @param  \App\Models\JobPoster              $job     Incoming Job Poster.
78
     * @return \Illuminate\Http\Response
79
     */
80 2
    public function update(UpdateJobPoster $request, JobPoster $job)
81
    {
82 2
        $data = $request->validated();
83 2
        JobPosterValidator::validateUnpublished($job);
84
        // Only values both in the JobPoster->fillable array,
85
        // and returned by UpdateJobPoster->validatedData(), will be set.
86 2
        $job->fill($data);
87 2
        $job->save();
88 2
        return $this->jobToArray($job);
89
    }
90
91
    /**
92
     * Remove the specified resource from storage.
93
     *
94
     * @param  integer $id Job Poster ID.
95
     * @return \Illuminate\Http\Response
1 ignored issue
show
Coding Style introduced by
Function return type is not void, but function has no return statement
Loading history...
96
     */
97
    public function destroy($id)
1 ignored issue
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
    public function destroy(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Type hint "int" missing for $id
Loading history...
98
    {
99
        // TODO: complete.
100
    }
101
}
102