Passed
Push — feature/job-api-store ( 1bd635 )
by Tristan
09:53
created

JobApiController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
wmc 8
eloc 20
dl 0
loc 89
ccs 18
cts 28
cp 0.6429
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 2 1
A jobToArray() 0 9 2
A store() 0 8 1
A destroy() 0 2 1
A update() 0 9 1
A __construct() 0 4 1
A show() 0 3 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
use App\Http\Requests\StoreJobPoster;
12
13
class JobApiController extends Controller
14
{
15 6
    public function __construct()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
16
    {
17
        // This applies the appropriate policy to each resource route
18 6
        $this->authorizeResource(JobPoster::class, 'job');
19 6
    }
20
21
    /**
22
     * Convert a job poster to the array expected by API requests,
23
     * with all criteria,
24
     * and with translation arrays in both languages.
25
     *
26
     * @param JobPoster $job
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
27
     * @return mixed[]
28
     */
29 3
    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...
30
    {
31 3
        $criteria = Criteria::where('job_poster_id', $job->id)->get();
32 3
        $criteriaTranslated = [];
33 3
        foreach ($criteria as $criterion) {
34 3
            $criteriaTranslated[] = array_merge($criterion->toArray(), $criterion->getTranslationsArray());
35
        }
36 3
        $jobArray = array_merge($job->toApiArray(), ['criteria' => $criteriaTranslated]);
37 3
        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  App\Http\Requests\StoreJobPoster  $request
2 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Api...Requests\StoreJobPoster was not found. Did you mean App\Http\Requests\StoreJobPoster? If so, make sure to prefix the type with \.
Loading history...
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
54
     */
55
    public function store(StoreJobPoster $request)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\Api\JobApiController::store() 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...
56
    {
57
        $data = $request->validated();
58
        $job = new JobPoster();
59
        $job->manager_id = $request->user()->manager->id;
60
        $job->fill($data);
61
        $job->save();
62
        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...
63
    }
64
65
    /**
66
     * Display the specified resource.
67
     *
68
     * @param JobPoster $job
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
69
     * @return \Illuminate\Http\Response
70
     */
71 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...
72
    {
73 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...
74
    }
75
76
    /**
1 ignored issue
show
Coding Style Documentation introduced by
Doc comment for parameter "$job" missing
Loading history...
77
     * Update the specified resource in storage.
78
     *
79
     * @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...
80
     * @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...
81
     * @return \Illuminate\Http\Response
82
     */
83 2
    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...
84
    {
85 2
        $data = $request->validated();
86 2
        JobPosterValidator::validateUnpublished($job);
87
        // Only values both in the JobPoster->fillable array,
88
        //  and returned by UpdateJobPoster->validatedData(), will be set
89 2
        $job->fill($data);
90 2
        $job->save();
91 2
        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...
92
    }
93
94
    /**
95
     * Remove the specified resource from storage.
96
     *
97
     * @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...
98
     * @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...
99
     */
100
    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

100
    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...
101
    {
102
        // TODO:
103
    }
104
}
105