Passed
Push — feature/add_relatives_from_ski... ( 795d93...edf85c )
by Tristan
07:28
created

WorkSamplesController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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
13
class WorkSamplesController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class WorkSamplesController
Loading history...
14
{
15
16
    /**
17
     * Display the Work Samples associated with the applicant.
18
     *
19
     * @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...
20
     * @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...
21
     */
22
    public function show(Applicant $applicant)
23
    {
24
        //
25
26
    }
27
28
    /**
29
     * Show the form for editing the applicant's work samples
30
     *
31
     * @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...
32
     * @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...
33
     * @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...
34
     */
35
    public function edit(Request $request, Applicant $applicant)
36
    {
37
        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...
38
            'applicant' => $applicant,
39
            'profile' => Lang::get('applicant/profile_work_samples'),
40
        ]);
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...
41
    }
42
43
    /**
44
     * Update the workSample in storage, or create new one.
45
     *
46
     * @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...
47
     * @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...
48
     * @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...
49
     */
50
    public function update(Request $request, ?WorkSample $workSample = null)
51
    {
52
        if ($workSample === null) {
53
            $workSample = new WorkSample();
54
            $workSample->applicant_id = $request->user()->applicant->id;
55
        }
56
        $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...
57
            'name' => $request->input('name'),
58
            'file_type_id' => $request->input('file_type_id'),
59
            'url' => $request->input('url'),
60
            'description' => $request->input('description'),
61
        ]);
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...
62
        $workSample->save();
63
64
        //Attach relatives
65
        $skillIds = $this->getRelativeIds($request->input(), 'skills');
66
        $workSample->skill_declarations()->sync($skillIds);
67
68
        // if an ajax request, return the new object
69
        if ($request->ajax()) {
70
            $workSample->load('file_type');
71
            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...
72
        } else {
73
            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...
74
        }
75
    }
76
77
    /**
78
     * Delete the particular work sample from storage.
79
     *
80
     * @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...
81
     * @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...
82
     * @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...
83
     */
84
    public function destroy(Request $request, WorkSample $workSample)
85
    {
86
        $this->authorize('delete', $workSample);
87
88
        $workSample->delete();
89
90
        if($request->ajax()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
91
            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...
92
                "message" => 'Work sample deleted'
93
            ];
94
        }
95
96
        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...
97
    }
98
99
}
100