Passed
Push — feature/job_api_route ( a33aa1...9319dc )
by Tristan
10:55
created

JobApiController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 4
    public function __construct()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
15
    {
16
        // This applies the appropriate policy to each resource route
17 4
        $this->authorizeResource(JobPoster::class, 'job');
18 4
    }
19
20
    /**
21
     * Convert a job poster to the array expected by API requests,
22
     * with all criteria,
23
     * and with translation arrays in both languages.
24
     *
25
     * @param JobPoster $job
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
26
     * @return mixed[]
27
     */
28 2
    private function jobToArray(JobPoster $job)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\Api\JobApiController::jobToArray() does not have return type hint for its return value but it should be possible to add it based on @return annotation "mixed[]".
Loading history...
29
    {
30 2
        $criteria = Criteria::where('job_poster_id', $job->id)->get();
31 2
        $criteriaTranslated = [];
32 2
        foreach ($criteria as $criterion) {
33
            // TODO: getTranslationsArray probably makes DB calls every loop. Find a way to profile & optimize.
34 2
            $criteriaTranslated[] = array_merge($criterion->toArray(), $criterion->getTranslationsArray());
35
        }
36 2
        $jobArray = array_merge($job->toApiArray(), ['criteria' => $criteriaTranslated]);
37 2
        return $jobArray;
38
    }
39
    /**
40
     * Display a listing of the resource.
41
     *
42
     * @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...
43
     */
44
    public function index()
45
    {
46
        //TODO: complete
47
    }
48
49
    /**
50
     * Store a newly created resource in storage.
51
     *
52
     * @param  \Illuminate\Http\Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
53
     * @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...
54
     */
55
    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

55
    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...
56
    {
57
        //TODO: complete
58
    }
59
60
    /**
61
     * Display the specified resource.
62
     *
63
     * @param JobPoster $job
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
64
     * @return \Illuminate\Http\Response
65
     */
66 1
    public function show(JobPoster $job)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\Api\JobApiController::show() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
67
    {
68 1
        return $this->jobToArray($job);
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->jobToArray($job) returns the type array<mixed,mixed> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
69
    }
70
71
    /**
1 ignored issue
show
Coding Style Documentation introduced by
Doc comment for parameter "$job" missing
Loading history...
72
     * Update the specified resource in storage.
73
     *
74
     * @param  App\Http\Requests\UpdateJobPoster  $request Validates input.
2 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Api...equests\UpdateJobPoster was not found. Did you mean App\Http\Requests\UpdateJobPoster? If so, make sure to prefix the type with \.
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 1 found
Loading history...
75
     * @param  JobPoster $jobPoser
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 25 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Doc comment for parameter $jobPoser does not match actual variable name $job
Loading history...
76
     * @return \Illuminate\Http\Response
77
     */
78 1
    public function update(UpdateJobPoster $request, JobPoster $job)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\Api\JobApiController::update() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
79
    {
80 1
        $request->validated();
81 1
        JobPosterValidator::validateUnpublished($job);
82
        // Only values in the JobPoster->fillable array will be set
83 1
        $job->fill($request->input());
84 1
        $job->save();
85 1
        return $this->jobToArray($job);
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->jobToArray($job) returns the type array<mixed,mixed> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
86
    }
87
88
    /**
89
     * Remove the specified resource from storage.
90
     *
91
     * @param  int  $id
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
92
     * @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...
93
     */
94
    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

94
    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...
introduced by
Method \App\Http\Controllers\Api\JobApiController::destroy() does not have parameter type hint for its parameter $id but it should be possible to add it based on @param annotation "int".
Loading history...
Coding Style introduced by
Type hint "int" missing for $id
Loading history...
95
    {
96
        // TODO:
97
    }
98
}
99