Completed
Push — feature/manager_localization2 ( de29b5...0f36f8 )
by Xander
16:57 queued 09:59
created

ApplicationByJobController::confirm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
ccs 0
cts 10
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Http\Request;
7
use App\Models\Lookup\ApplicationStatus;
8
use App\Models\Lookup\VeteranStatus;
9
use App\Models\Lookup\PreferredLanguage;
10
use App\Models\Lookup\CitizenshipDeclaration;
11
use App\Models\Applicant;
12
use App\Models\JobPoster;
13
use App\Models\JobApplication;
14
use App\Models\JobApplicationAnswer;
15
use App\Models\SkillDeclaration;
16
use App\Models\Skill;
17
use App\Models\Lookup\SkillStatus;
18
use App\Models\Degree;
19
use App\Models\Lookup\CriteriaType;
20
use App\Models\Criteria;
21
use App\Models\Course;
22
use App\Models\WorkExperience;
23
use App\Services\Validation\ApplicationValidator;
24
use Illuminate\Support\Facades\Auth;
25
use Illuminate\Support\Facades\Log;
26
27
28
class ApplicationByJobController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ApplicationByJobController
Loading history...
29
{
30
    /**
31
     * Display a listing of the resource.
32
     *
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function index()
36
    {
37
        //
38
    }
39
40
    protected function getApplicationFromJob(JobPoster $jobPoster) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getApplicationFromJob()
Loading history...
41
        $application = JobApplication::where('applicant_id', Auth::user()->applicant->id)
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
42
            ->where('job_poster_id', $jobPoster->id)->first();
43
        if ($application == null) {
44
            $application = new JobApplication();
45
            $application->job_poster_id = $jobPoster->id;
46
            $application->applicant_id = Auth::user()->applicant->id;
47
            $application->application_status_id = ApplicationStatus::where('name', 'draft')->firstOrFail()->id;
48
            $application->save();
49
        }
50
        return $application;
51
    }
52
53
    /**
54
     * Show the form for editing Application basics for the specified job.
55
     *
56
     * @param  \App\Models\JobPoster  $jobPoster
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...
57
     * @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...
58
     */
59
    public function edit_basics(JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::edit_basics" is not in camel caps format
Loading history...
60
    {
61
62
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
63
64
        $application = $this->getApplicationFromJob($jobPoster);
65
66
        //Ensure user has permissions to view and update application
67
        $this->authorize('view', $application);
68
        $this->authorize('update', $application);
69
70
        return view('applicant/application_post_01', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a...pdate.1', $jobPoster))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
71
72
            /* Application Template Data */
73
                "application_step" => 1,
74
                "application_template" => Lang::get("applicant/application_template"),
75
                "language_options" => PreferredLanguage::all(),
76
                "citizenship_options" => CitizenshipDeclaration::all(),
77
                "veteran_options" => VeteranStatus::all(),
78
                "preferred_language_template" => Lang::get('common/preferred_language'),
79
                "citizenship_declaration_template" => Lang::get('common/citizenship_declaration'),
80
                "veteran_status_template" => Lang::get('common/veteran_status'),
81
82
            /* Job Data */
83
                "job" => $jobPoster,
84
85
            /* Applicant Data */
86
                "applicant" => $applicant,
87
                "job_application" => $application,
88
89
            /* Submission */
90
                "form_submit_action" => route('job.application.update.1', $jobPoster)
91
92
        ]);
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...
93
94
    }
95
96
    /**
97
     * Show the form for editing Application Experience for the specified job.
98
     *
99
     * @param  \App\Models\JobPoster  $jobPoster
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...
100
     * @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...
101
     */
102
    public function edit_experience(JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::edit_experience" is not in camel caps format
Loading history...
103
    {
104
105
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
106
107
        $application = $this->getApplicationFromJob($jobPoster);
108
109
        //Ensure user has permissions to view and update application
110
        $this->authorize('view', $application);
111
        $this->authorize('update', $application);
112
113
        return view('applicant/application_post_02', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a...pdate.2', $jobPoster))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
114
115
            /* Application Template Data */
116
                "application_step" => 2,
117
                "application_template" => Lang::get("applicant/application_template"),
118
119
            /* Job Data */
120
                "job" => $jobPoster,
121
122
            /* Applicant Data */
123
                "applicant" => $applicant,
124
                "job_application" => $application,
125
126
            /* Submission */
127
                "form_submit_action" => route('job.application.update.2', $jobPoster)
128
129
        ]);
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...
130
131
    }
132
133
    /**
134
     * Show the form for editing Application Essential Skills for the specified job.
135
     *
136
     * @param  \App\Models\JobPoster  $jobPoster
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...
137
     * @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...
138
     */
139
    public function edit_essential_skills(JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::edit_essential_skills" is not in camel caps format
Loading history...
140
    {
141
142
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
143
144
        $application = $this->getApplicationFromJob($jobPoster);
145
146
        //Ensure user has permissions to view and update application
147
        $this->authorize('view', $application);
148
        $this->authorize('update', $application);
149
150
        $criteria = [
151
            'essential' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

151
            'essential' => $jobPoster->criteria->filter(function($value, /** @scrutinizer ignore-unused */ $key) {

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
152
                return $value->criteria_type->name == 'essential';
153
            }),
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...
154
            'asset' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

154
            'asset' => $jobPoster->criteria->filter(function($value, /** @scrutinizer ignore-unused */ $key) {

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
155
                return $value->criteria_type->name == 'asset';
156
            }),
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...
157
        ];
158
159
        return view('applicant/application_post_03', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a...pdate.3', $jobPoster))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
160
161
            /* Application Template Data */
162
                "application_step" => 3,
163
                "application_template" => Lang::get("applicant/application_template"),
164
165
            /* Job Data */
166
                "job" => $jobPoster,
167
168
            /* Skills Data */
169
                "skills" => Skill::all(),
170
                "skill_template" => Lang::get("common/skills"),
171
                "criteria" => $criteria,
172
173
            /* Applicant Data */
174
                "applicant" => $applicant,
175
                "job_application" => $application,
176
177
            /* Submission */
178
                "form_submit_action" => route('job.application.update.3', $jobPoster)
179
180
        ]);
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...
181
182
    }
183
184
    /**
185
     * Show the form for editing Application Asset Skills for the specified job.
186
     *
187
     * @param  \App\Models\JobPoster  $jobPoster
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...
188
     * @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...
189
     */
190
    public function edit_asset_skills(JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::edit_asset_skills" is not in camel caps format
Loading history...
191
    {
192
193
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
194
195
        $application = $this->getApplicationFromJob($jobPoster);
196
197
        //Ensure user has permissions to view and update application
198
        $this->authorize('view', $application);
199
        $this->authorize('update', $application);
200
201
        $criteria = [
202
            'essential' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

202
            'essential' => $jobPoster->criteria->filter(function($value, /** @scrutinizer ignore-unused */ $key) {

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
203
                return $value->criteria_type->name == 'essential';
204
            }),
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...
205
            'asset' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

205
            'asset' => $jobPoster->criteria->filter(function($value, /** @scrutinizer ignore-unused */ $key) {

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
206
                return $value->criteria_type->name == 'asset';
207
            }),
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...
208
        ];
209
210
        return view('applicant/application_post_04', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a...pdate.4', $jobPoster))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
211
212
            /* Application Template Data */
213
                "application_step" => 4,
214
                "application_template" => Lang::get("applicant/application_template"),
215
216
            /* Job Data */
217
                "job" => $jobPoster,
218
219
            /* Skills Data */
220
                "skills" => Skill::all(),
221
                "skill_template" => Lang::get("common/skills"),
222
                "criteria" => $criteria,
223
224
            /* Applicant Data */
225
                "applicant" => $applicant,
226
                "job_application" => $application,
227
228
            /* Submission */
229
                "form_submit_action" => route('job.application.update.4', $jobPoster)
230
231
        ]);
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...
232
    }
233
234
    /**
235
     * Show the Application Preview for the application for the specified job.
236
     *
237
     * @param  \App\Models\JobPoster  $jobPoster
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...
238
     * @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...
239
     */
240
    public function preview(JobPoster $jobPoster) {
241
242
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
243
244
        $application = $this->getApplicationFromJob($jobPoster);
245
246
        $this->authorize('view', $application);
247
248
        $criteria = [
249
            'essential' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

249
            'essential' => $jobPoster->criteria->filter(function($value, /** @scrutinizer ignore-unused */ $key) {

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
250
                return $value->criteria_type->name == 'essential';
251
            }),
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...
252
            'asset' => $jobPoster->criteria->filter(function($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

252
            'asset' => $jobPoster->criteria->filter(function($value, /** @scrutinizer ignore-unused */ $key) {

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
253
                return $value->criteria_type->name == 'asset';
254
            }),
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...
255
        ];
256
257
        return view('applicant/application_post_05', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a...tion' => $application)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
258
259
            /* Application Template Data */
260
                "application_step" => 5,
261
                "application_template" => Lang::get("applicant/application_template"),
262
                "preferred_language_template" => Lang::get('common/preferred_language'),
263
                "citizenship_declaration_template" => Lang::get('common/citizenship_declaration'),
264
                "veteran_status_template" => Lang::get('common/veteran_status'),
265
266
            /* Job Data */
267
                "job" => $jobPoster,
268
269
            /* Skills Data */
270
                "skills" => Skill::all(),
271
                "skill_template" => Lang::get("common/skills"),
272
                "criteria" => $criteria,
273
274
            /* Applicant Data */
275
                "applicant" => $applicant,
276
                "job_application" => $application,
277
        ]);
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...
278
    }
279
280
    /**
281
     * Show the Confirm Submit page for the application for the specified job.
282
     *
283
     * @param  \App\Models\JobPoster  $jobPoster
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...
284
     * @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...
285
     */
286
    public function confirm(JobPoster $jobPoster)
287
    {
288
289
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Unused Code introduced by
The assignment to $applicant is dead and can be removed.
Loading history...
290
291
        $application = $this->getApplicationFromJob($jobPoster);
292
293
        $this->authorize('update', $application);
294
295
        return view('applicant/application_post_06', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a....submit', $jobPoster))) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
296
            /* Application Template Data */
297
            "application_step" => 6,
298
            "application_template" => Lang::get("applicant/application_template"),
299
300
            /* Used by tracker partial */
301
            "job" => $jobPoster,
302
            "job_application" => $application,
303
304
            /* Submission */
305
            "form_submit_action" => route('job.application.submit', $jobPoster)
306
        ]);
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...
307
    }
308
309
    /**
310
     * Show the application submission information.
311
     *
312
     * @param  \App\Models\JobPoster  $jobPoster
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...
313
     * @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...
314
     */
315
    public function complete(JobPoster $jobPoster) {
316
317
        /* Include Applicant Data */
318
319
            $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
320
321
        /* Include Application Data */
322
323
            $application = $this->getApplicationFromJob($jobPoster);
324
325
            //Ensure user has permissions to view application
326
            $this->authorize('view', $application);
327
328
        /* Return the Completion View */
329
330
            return view('applicant/application_post_complete', [
1 ignored issue
show
Bug Best Practice introduced by
The expression return view('applicant/a...tion' => $application)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
331
332
                /* Application Template Data */
333
                    "application_template" => Lang::get("applicant/application_template"),
334
335
                /* Job Data */
336
                    "job" => $jobPoster,
337
338
                /* Applicant Data */
339
                    "applicant" => $applicant,
340
                    "job_application" => $application
341
342
            ]);
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...
343
    }
344
345
    /**
346
     * Update the Application Basics in storage for the specified job.
347
     *
348
     * @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...
349
     * @param  \App\Models\JobPoster  $jobPoster
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...
350
     * @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...
351
     */
352
    public function update_basics(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::update_basics" is not in camel caps format
Loading history...
353
    {
354
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Unused Code introduced by
The assignment to $applicant is dead and can be removed.
Loading history...
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
355
        $application = $this->getApplicationFromJob($jobPoster);
356
357
        //Ensure user has permissions to update this application
358
        $this->authorize('update', $application);
359
360
        $application->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...
361
            'citizenship_declaration_id' => $request->input('citizenship_declaration_id'),
362
            'veteran_status_id' => $request->input('veteran_status_id'),
363
            'preferred_language_id' => $request->input('preferred_language_id'),
364
        ]);
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...
365
        $application->save();
366
367
        $questions = $jobPoster->job_poster_questions;
368
        $questionsInput = $request->input('questions');
369
        foreach($questions as $question) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
370
            $answer = null;
371
            if (isset($questionsInput[$question->id])) {
372
                $answer = $questionsInput[$question->id];
373
            }
374
            $answerObj = $application->job_application_answers
375
                ->firstWhere('job_poster_question_id', $question->id);
376
            if ($answerObj == null) {
377
                $answerObj = new JobApplicationAnswer();
378
                $answerObj->job_poster_question_id = $question->id;
379
                $answerObj->job_application_id = $application->id;
380
            }
381
            $answerObj->answer = $answer;
382
            $answerObj->save();
383
        }
384
385
        //Redirect to correct page
386
        switch($request->input('submit')) {
387
            case 'save_and_quit':
388
            case 'previous':
389
                return redirect()->route('applications.index');
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route('applications.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
390
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
391
            case 'save_and_continue':
392
            case 'next':
393
                return redirect()->route('job.application.edit.2', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.2', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
394
                break;
395
            default:
396
                return redirect()->back()->withInput();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back()->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
397
                break;
398
        }
399
    }
400
401
    /**
402
     * Update the Application Basics in storage for the specified job.
403
     *
404
     * @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...
405
     * @param  \App\Models\JobPoster  $jobPoster
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...
406
     * @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...
407
     */
408
    public function update_experience(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::update_experience" is not in camel caps format
Loading history...
409
    {
410
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
411
        $application = $this->getApplicationFromJob($jobPoster);
412
413
        //Ensure user has permissions to update this application
414
        $this->authorize('update', $application);
415
416
        // Record that the user has saved their experience for this application
417
        $application->experience_saved = true;
418
        $application->save();
419
420
        $degrees = $request->input('degrees');
421
422
        //Save new degrees
423
        if (isset($degrees['new'])) {
424
            foreach($degrees['new'] as $degreeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
425
                $degree = new Degree();
426
                $degree->applicant_id = $applicant->id;
427
                $degree->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...
428
                    'degree_type_id' => $degreeInput['degree_type_id'],
429
                    'area_of_study' => $degreeInput['area_of_study'],
430
                    'institution' => $degreeInput['institution'],
431
                    'thesis' => $degreeInput['thesis'],
432
                    'start_date' => $degreeInput['start_date'],
433
                    'end_date' => $degreeInput['end_date']
434
                ]);
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...
435
                $degree->save();
436
            }
437
        }
438
439
        //Update old degrees
440
        if (isset($degrees['old'])) {
441
            foreach($degrees['old'] as $id=>$degreeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
442
                //Ensure this degree belongs to this applicant
443
                $degree = $applicant->degrees->firstWhere('id', $id);
444
                if ($degree != null) {
445
                    $degree->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...
446
                        'degree_type_id' => $degreeInput['degree_type_id'],
447
                        'area_of_study' => $degreeInput['area_of_study'],
448
                        'institution' => $degreeInput['institution'],
449
                        'thesis' => $degreeInput['thesis'],
450
                        'start_date' => $degreeInput['start_date'],
451
                        'end_date' => $degreeInput['end_date']
452
                    ]);
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...
453
                    $degree->save();
454
                } else {
455
                    Log::warning('Applicant '.$applicant->id.' attempted to update degree with invalid id '.$id);
456
                }
457
            }
458
        }
459
460
        $courses = $request->input('courses');
461
462
        //Save new courses
463
        if (isset($courses['new'])) {
464
            foreach($courses['new'] as $courseInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
465
                $course = new Course();
466
                $course->applicant_id = $applicant->id;
467
                $course->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...
468
                    'name' => $courseInput['name'],
469
                    'institution' => $courseInput['institution'],
470
                    'course_status_id' => $courseInput['course_status_id'],
471
                    'start_date' => $courseInput['start_date'],
472
                    'end_date' => $courseInput['end_date']
473
                ]);
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...
474
                $course->save();
475
            }
476
        }
477
478
        //Update old courses
479
        if (isset($courses['old'])) {
480
            foreach($courses['old'] as $id=>$courseInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
481
                //Ensure this course belongs to this applicant
482
                $course = $applicant->courses->firstWhere('id', $id);
483
                if ($course != null) {
484
                    $course->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...
485
                        'name' => $courseInput['name'],
486
                        'institution' => $courseInput['institution'],
487
                        'course_status_id' => $courseInput['course_status_id'],
488
                        'start_date' => $courseInput['start_date'],
489
                        'end_date' => $courseInput['end_date']
490
                    ]);
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...
491
                    $course->save();
492
                } else {
493
                    Log::warning('Applicant '.$applicant->id.' attempted to update course with invalid id '.$id);
494
                }
495
            }
496
        }
497
498
        $work_experiences = $request->input('work_experiences');
499
500
        //Save new work_experiences
501
        if (isset($work_experiences['new'])) {
502
            foreach($work_experiences['new'] as $workExperienceInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
503
                $workExperience = new WorkExperience();
504
                $workExperience->applicant_id = $applicant->id;
505
                $workExperience->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...
506
                    'role' => $workExperienceInput['role'],
507
                    'company' => $workExperienceInput['company'],
508
                    'description' => $workExperienceInput['description'],
509
                    'start_date' => $workExperienceInput['start_date'],
510
                    'end_date' => $workExperienceInput['end_date']
511
                ]);
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...
512
                $workExperience->save();
513
            }
514
        }
515
516
        //Update old work_experiences
517
        if (isset($work_experiences['old'])) {
518
            foreach($work_experiences['old'] as $id=>$workExperienceInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
519
                //Ensure this work_experience belongs to this applicant
520
                $workExperience = $applicant->work_experiences->firstWhere('id', $id);
521
                if ($workExperience != null) {
522
                    $workExperience->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...
523
                        'role' => $workExperienceInput['role'],
524
                        'company' => $workExperienceInput['company'],
525
                        'description' => $workExperienceInput['description'],
526
                        'start_date' => $workExperienceInput['start_date'],
527
                        'end_date' => $workExperienceInput['end_date']
528
                    ]);
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...
529
                    $workExperience->save();
530
                } else {
531
                    Log::warning('Applicant '.$applicant->id.' attempted to update work_experience with invalid id '.$id);
532
                }
533
            }
534
        }
535
536
        //Redirect to correct page
537
        switch($request->input('submit')) {
538
            case 'save_and_quit':
539
                return redirect()->route('applications.index');
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route('applications.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
540
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
541
            case 'save_and_continue':
542
            case 'next':
543
                return redirect()->route('job.application.edit.3', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.3', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
544
                break;
545
            case 'previous':
546
                return redirect()->route('job.application.edit.1', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.1', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
547
                break;
548
            default:
549
                return redirect()->back()->withInput();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back()->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
550
                break;
551
        }
552
    }
553
554
    /**
555
     * Update the Application Essential Skills in storage for the specified job.
556
     *
557
     * @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...
558
     * @param  \App\Models\JobPoster  $jobPoster
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...
559
     * @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...
560
     */
561
    public function update_essential_skills(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::update_essential_skills" is not in camel caps format
Loading history...
562
    {
563
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
564
        $application = $this->getApplicationFromJob($jobPoster);
565
566
        //Ensure user has permissions to update this application
567
        $this->authorize('update', $application);
568
569
        $skillDeclarations = $request->input('skill_declarations');
570
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
571
572
        //Save new skill declarartions
573
        if (isset($skillDeclarations['new'])) {
574
            foreach($skillDeclarations['new'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
575
                foreach($typeInput as $criterion_id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
576
                    $skillDeclaration = new SkillDeclaration();
577
                    $skillDeclaration->applicant_id = $applicant->id;
578
                    $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id;
579
                    $skillDeclaration->skill_status_id = $claimedStatusId;
580
                    $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...
581
                        'description' => $skillDeclarationInput['description'],
582
                        'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
583
                    ]);
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...
584
                    $skillDeclaration->save();
585
586
                    $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
587
                    $skillDeclaration->references()->sync($referenceIds);
588
589
                    $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
590
                    $skillDeclaration->work_samples()->sync($sampleIds);
591
                }
592
            }
593
        }
594
595
        //Update old declarations
596
        if (isset($skillDeclarations['old'])) {
597
            foreach($skillDeclarations['old'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
598
                foreach($typeInput as $id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
599
                    //Ensure this declaration belongs to this applicant
600
                    $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id);
601
                    if ($skillDeclaration != null) {
602
                        //skill_id and skill_status cannot be changed
603
                        $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...
604
                            'description' => $skillDeclarationInput['description'],
605
                            'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
606
                        ]);
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...
607
                        $skillDeclaration->save();
608
609
                        $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
610
                        $skillDeclaration->references()->sync($referenceIds);
611
612
                        $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
613
                        $skillDeclaration->work_samples()->sync($sampleIds);
614
                    } else {
615
                        Log::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id);
616
                    }
617
                }
618
            }
619
        }
620
621
        //Redirect to correct page
622
        switch($request->input('submit')) {
623
            case 'save_and_quit':
624
                return redirect()->route('applications.index');
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route('applications.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
625
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
626
            case 'save_and_continue':
627
            case 'next':
628
                return redirect()->route('job.application.edit.4', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.4', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
629
                break;
630
            case 'previous':
631
                return redirect()->route('job.application.edit.2', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.2', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
632
                break;
633
            default:
634
                return redirect()->back()->withInput();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back()->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
635
                break;
636
        }
637
    }
638
639
    /**
640
     * Update the Application Asset Skills in storage for the specified job.
641
     *
642
     * @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...
643
     * @param  \App\Models\JobPoster  $jobPoster
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...
644
     * @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...
645
     */
646
    public function update_asset_skills(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Public method name "ApplicationByJobController::update_asset_skills" is not in camel caps format
Loading history...
647
    {
648
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
649
        $application = $this->getApplicationFromJob($jobPoster);
650
651
        //Ensure user has permissions to update this application
652
        $this->authorize('update', $application);
653
654
        $skillDeclarations = $request->input('skill_declarations');
655
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
656
657
        //Save new skill declarartions
658
        if (isset($skillDeclarations['new'])) {
659
            foreach($skillDeclarations['new'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
660
                foreach($typeInput as $criterion_id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
661
                    $skillDeclaration = new SkillDeclaration();
662
                    $skillDeclaration->applicant_id = $applicant->id;
663
                    $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id;
664
                    $skillDeclaration->skill_status_id = $claimedStatusId;
665
                    $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...
666
                        'description' => $skillDeclarationInput['description'],
667
                        'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
668
                    ]);
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...
669
                    $skillDeclaration->save();
670
671
                    $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
672
                    $skillDeclaration->references()->sync($referenceIds);
673
674
                    $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
675
                    $skillDeclaration->work_samples()->sync($sampleIds);
676
                }
677
            }
678
        }
679
680
        //Update old declarations
681
        if (isset($skillDeclarations['old'])) {
682
            foreach($skillDeclarations['old'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
683
                foreach($typeInput as $id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
684
                    //Ensure this declaration belongs to this applicant
685
                    $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id);
686
                    if ($skillDeclaration != null) {
687
                        //skill_id and skill_status cannot be changed
688
                        $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...
689
                            'description' => $skillDeclarationInput['description'],
690
                            'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
691
                        ]);
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...
692
                        $skillDeclaration->save();
693
694
                        $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
695
                        $skillDeclaration->references()->sync($referenceIds);
696
697
                        $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
698
                        $skillDeclaration->work_samples()->sync($sampleIds);
699
                    } else {
700
                        Log::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id);
701
                    }
702
                }
703
            }
704
        }
705
706
        //Redirect to correct page
707
        switch($request->input('submit')) {
708
            case 'save_and_quit':
709
                return redirect()->route('applications.index');
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route('applications.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
710
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
711
            case 'save_and_continue':
712
            case 'next':
713
                return redirect()->route('job.application.edit.5', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.5', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
714
                break;
715
            case 'previous':
716
                return redirect()->route('job.application.edit.3', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.3', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
717
                break;
718
            default:
719
                return redirect()->back()->withInput();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back()->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
720
                break;
721
        }
722
    }
723
724
    /**
725
     * Submit the Application for the specified job.
726
     *
727
     * @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...
728
     * @param  \App\Models\JobPoster  $jobPoster
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...
729
     * @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...
730
     */
731
    public function submit(Request $request, JobPoster $jobPoster)
732
    {
733
        $applicant = Auth::user()->applicant;
0 ignored issues
show
Unused Code introduced by
The assignment to $applicant is dead and can be removed.
Loading history...
Bug introduced by
Accessing applicant on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
734
        $application = $this->getApplicationFromJob($jobPoster);
735
736
        //Ensure user has permissions to update this application
737
        $this->authorize('update', $application);
738
739
        //Only complete submission if submit button was pressed
740
        if ($request->input('submit') == "submit") {
741
742
            $request->validate([
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...
743
                'submission_signature' => [
744
                    'required',
745
                    'string',
746
                    'max:191',
747
                ],
748
                'submission_date' => [
749
                    'required',
750
                    'string',
751
                    'max:191',
752
               ]
753
           ]);
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...
754
755
           //Save any final info
756
           $application->fill([
0 ignored issues
show
Coding Style introduced by
Opening statement of multi-line function call not indented correctly; expected 8 spaces but found 11
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
757
               'submission_signature' => $request->input('submission_signature'),
758
               'submission_date' => $request->input('submission_date'),
759
           ]);
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...
760
761
            $validator = new ApplicationValidator();
762
            $validator->validate($application);
763
764
            //Change status to 'submitted'
765
            $application->application_status_id = ApplicationStatus::where('name', 'submitted')->firstOrFail()->id;
766
        }
767
768
        $application->save();
769
770
        //Redirect to correct page
771
        switch($request->input('submit')) {
772
            case 'save_and_quit':
773
                return redirect()->route('applications.index');
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route('applications.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
774
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
775
            case 'submit':
776
                return redirect()->route('job.application.complete', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route....complete', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
777
                break;
778
            case 'previous':
779
                return redirect()->route('job.application.edit.4', $jobPoster);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->route...on.edit.4', $jobPoster) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
780
                break;
781
            default:
782
                return redirect()->back()->withInput();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back()->withInput() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
783
                break;
784
        }
785
    }
786
}
787