Completed
Push — feature/add_relatives_from_ski... ( 1e8e28...795d93 )
by Tristan
16:16 queued 09:08
created

SkillsController::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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\Models\Skill;
9
use App\Models\Lookup\SkillLevel;
10
use App\Models\Lookup\SkillStatus;
11
use App\Models\SkillDeclaration;
12
use App\Models\Applicant;
13
use App\Http\Controllers\Controller;
14
use App\Services\Validation\BulkSkillDeclarationValidator;
15
use App\Services\Validation\SkillDeclarationValidator;
16
17
class SkillsController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SkillsController
Loading history...
18
{
19
20
    /**
21
     * Display the Skills page associated with the applicant.
22
     *
23
     * @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...
24
     * @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...
25
     */
26
    public function show(Applicant $applicant)
0 ignored issues
show
Unused Code introduced by
The parameter $applicant 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

26
    public function show(/** @scrutinizer ignore-unused */ Applicant $applicant)

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...
27
    {
28
        //
29
30
    }
31
32
    /**
33
     * Show the form for editing the applicant's skills
34
     *
35
     * @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...
36
     * @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...
37
     * @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...
38
     */
39
    public function edit(Request $request, Applicant $applicant)
40
    {
41
        $skills = Skill::all();
42
43
        return view('applicant/profile_03_skills', [
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..., 'skills' => $skills)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
44
            'applicant' => $applicant,
45
            'profile' => Lang::get('applicant/profile_skills'),
46
            'skills' => $skills
47
        ]);
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...
48
    }
49
50
    /**
51
     * Create the particular skill declaration in storage.
52
     *
53
     * @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...
54
     * @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...
55
     */
56
    public function create(Request $request)
57
    {
58
        $this->authorize('create', SkillDeclaration::class);
59
60
        $user = $request->user();
61
        $applicant = $user->applicant;
62
63
        //Get the default claim status id
64
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
65
66
        // Create a new Skill Declaration
67
        // But don't save, as it hasn't been validated yet
68
        $skillDeclaration = new SkillDeclaration();
69
        $skillDeclaration->applicant_id = $applicant->id;
70
        $skillDeclaration->skill_id = $request->input('skill_id');
71
        $skillDeclaration->skill_status_id = $claimedStatusId;
72
73
        //Update variable fields in skill declaration
74
        return $this->updateSkillDeclaration($request, $skillDeclaration);
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->updateSkil...est, $skillDeclaration) returns the type Illuminate\Http\RedirectResponse|string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
75
    }
76
77
    /**
78
     * Update the particular skill declaration in 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 5 spaces after parameter type; 2 found
Loading history...
81
     * @param  \App\Models\SkillDeclaration  $skillDeclaration
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...
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 update(Request $request, SkillDeclaration $skillDeclaration)
85
    {
86
        $this->authorize('update', $skillDeclaration);
87
88
        return $this->updateSkillDeclaration($request, $skillDeclaration);
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->updateSkil...est, $skillDeclaration) returns the type Illuminate\Http\RedirectResponse|string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
89
    }
90
91
    protected function updateSkillDeclaration(Request $request, SkillDeclaration $skillDeclaration)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function updateSkillDeclaration()
Loading history...
92
    {
93
        //Fill variable values
94
        $skillDeclaration->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...
95
            'description' => $request->input('description'),
96
            'skill_level_id' => $request->input('skill_level_id'),
97
        ]);
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...
98
99
        //Validate before saving
100
        $validator = new SkillDeclarationValidator($request->user()->applicant);
101
        $validator->validate($skillDeclaration);
102
103
        //Save this skill declaration
104
        $skillDeclaration->save();
105
106
        //Attach relatives
107
        $referenceIds = $this->getRelativeIds($request->input(), 'references');
108
        $skillDeclaration->references()->sync($referenceIds);
109
110
        $sampleIds = $this->getRelativeIds($request->input(), 'samples');
111
        $skillDeclaration->work_samples()->sync($sampleIds);
112
113
        $skillDeclaration->save();
114
115
        // If an ajax request, return the new object
116
        if($request->ajax()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
117
            $skillDeclaration->load('references');
118
            $skillDeclaration->load('work_samples');
119
            $skillDeclaration->load('skill');
120
            $skillDeclaration->load('skill_status');
121
            return $skillDeclaration->toJson();
122
        }
123
124
        return redirect()->back();
125
    }
126
127
    /**
128
     * Delete the particular skill declaration in storage.
129
     *
130
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 2 found
Loading history...
131
     * @param  \App\Models\SkillDeclaration  $skillDeclaration
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...
132
     * @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...
133
     */
134
    public function destroy(Request $request, SkillDeclaration $skillDeclaration)
135
    {
136
        $this->authorize('delete', $skillDeclaration);
137
        $skillDeclaration->delete();
138
139
        if($request->ajax()) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
140
            return ['message' => 'Skill deleted'];
1 ignored issue
show
Bug Best Practice introduced by
The expression return array('message' => 'Skill deleted') returns the type array<string,string> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
141
        }
142
143
        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...
144
    }
145
146
}
147