Completed
Push — feature/backpack ( 1e2264...84da73 )
by Chris
07:15
created

WorkSamplesController::update()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 27
ccs 0
cts 18
cp 0
rs 9.6666
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 12
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class WorkSamplesController
Loading history...
15
{
16
17
    /**
18
     * Display the Work Samples associated with the applicant.
19
     *
20
     * @param  \App\Models\Applicant  $applicant
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
22
     */
23
    public function show(Applicant $applicant)
24
    {
25
        //
26
27
    }
28
29
    /**
30
     * Show the form for editing the applicant's work samples
31
     *
32
     * @param  Request  $request
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
35
     */
36
    public function edit(Request $request, Applicant $applicant)
37
    {
38
        return view('applicant/profile_05_portfolio', [
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
42
    }
43
44
    /**
45
     * Update the workSample in storage, or create new one.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
50
     */
51
    public function update(Request $request, ?WorkSample $workSample = null)
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([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
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
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
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
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
87
     */
88
    public function destroy(Request $request, WorkSample $workSample)
89
    {
90
        $this->authorize('delete', $workSample);
91
92
        $workSample->delete();
93
94
        if($request->ajax()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
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