Passed
Push — bugfix/relatives_not_saving ( 6485fa...f1e1c5 )
by Tristan
13:39
created

WorkSamplesController::editAuthenticated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Lang;
6
use Illuminate\Support\Facades\Log;
7
use Illuminate\Http\Request;
8
use App\Http\Controllers\Controller;
9
use App\Models\Skill;
10
use App\Models\Applicant;
11
use App\Models\WorkSample;
12
use App\Services\Validation\Requests\UpdateWorkSampleValidator;
13
14
class WorkSamplesController extends Controller
15
{
16
17
    /**
18
     * Display the Work Samples associated with the applicant.
19
     *
20
     * @param  \App\Models\Applicant  $applicant
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...
21
     * @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...
22
     */
23
    public function show(Applicant $applicant)
24
    {
25
        //
26
27
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
28
29
    /**
30
     * Show the form for editing the applicant's work samples
31
     *
32
     * @param  Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 15 spaces after parameter type; 2 found
Loading history...
33
     * @param  \App\Models\Applicant  $applicant
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...
34
     * @return \Illuminate\Http\Response
35
     */
36
    public function edit(Request $request, Applicant $applicant)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\WorkSamplesController::edit() 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...
37
    {
38
        return view('applicant/profile_05_portfolio', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/p...rofile_work_samples'))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
39
            'applicant' => $applicant,
40
            'profile' => Lang::get('applicant/profile_work_samples'),
41
        ]);
42
    }
43
44
    /**
45
     * Update the workSample in storage, or create new one.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 2 found
Loading history...
48
     * @param  \App\Models\WorkSample|null  $workSample
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...
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function update(Request $request, ?WorkSample $workSample = null)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\WorkSamplesController::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...
52
    {
53
        $validator = new UpdateWorkSampleValidator();
54
        $validator->validate($request->input());
55
56
        if ($workSample === null) {
57
            $workSample = new WorkSample();
58
            $workSample->applicant_id = $request->user()->applicant->id;
59
        }
60
        $workSample->fill([
61
            'name' => $request->input('name'),
62
            'file_type_id' => $request->input('file_type_id'),
63
            'url' => $request->input('url'),
64
            'description' => $request->input('description'),
65
        ]);
66
        $workSample->save();
67
68
        //Attach relatives
69
        $skillIds = $this->getRelativeIds($request->input(), 'skills');
70
        $workSample->skill_declarations()->sync($skillIds);
71
72
        // if an ajax request, return the new object
73
        if ($request->ajax()) {
74
            $workSample->load('file_type');
75
            return $workSample->toJson();
1 ignored issue
show
Bug Best Practice introduced by
The expression return $workSample->toJson() returns the type string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
76
        } else {
77
            return redirect()->back();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
78
        }
79
    }
80
81
    /**
82
     * Delete the particular work sample from storage.
83
     *
84
     * @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...
85
     * @param  \App\Models\WorkSample  $workSample
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 2 found
Loading history...
86
     * @return \Illuminate\Http\Response
87
     */
88
    public function destroy(Request $request, WorkSample $workSample)
0 ignored issues
show
introduced by
Method \App\Http\Controllers\WorkSamplesController::destroy() 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...
89
    {
90
        $this->authorize('delete', $workSample);
91
92
        $workSample->delete();
93
94
        if($request->ajax()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after IF keyword; 0 found
Loading history...
95
            return [
1 ignored issue
show
Bug Best Practice introduced by
The expression return array('message' => 'Work sample deleted') returns the type array<string,string> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
96
                "message" => 'Work sample deleted'
97
            ];
98
        }
99
100
        return redirect()->back();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
101
    }
102
103
}
104