Completed
Push — feature/temp_view_app_2 ( 1c0007 )
by Tristan
10:09
created

getApplicationFromJob()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 Barryvdh\Debugbar\Facade as Debugbar;
6
use Illuminate\Support\Facades\Lang;
7
use Illuminate\Http\Request;
8
use App\Models\Lookup\ApplicationStatus;
9
use App\Models\Lookup\VeteranStatus;
10
use App\Models\Lookup\PreferredLanguage;
11
use App\Models\Lookup\CitizenshipDeclaration;
12
use App\Models\Applicant;
13
use App\Models\JobPoster;
14
use App\Models\JobApplication;
15
use App\Models\JobApplicationAnswer;
16
use App\Models\SkillDeclaration;
17
use App\Models\Skill;
18
use App\Models\Lookup\SkillStatus;
19
use App\Models\Degree;
20
use App\Models\Lookup\CriteriaType;
21
use App\Models\Criteria;
22
use App\Models\Course;
23
use App\Models\WorkExperience;
24
use App\Services\Validation\ApplicationValidator;
25
use Illuminate\Support\Facades\Auth;
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)
0 ignored issues
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
                "form_submit_action" => route('job.application.update.1', /** @scrutinizer ignore-type */ $jobPoster)
Loading history...
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)
0 ignored issues
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

127
                "form_submit_action" => route('job.application.update.2', /** @scrutinizer ignore-type */ $jobPoster)
Loading history...
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)
0 ignored issues
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

178
                "form_submit_action" => route('job.application.update.3', /** @scrutinizer ignore-type */ $jobPoster)
Loading history...
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)
0 ignored issues
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

229
                "form_submit_action" => route('job.application.update.4', /** @scrutinizer ignore-type */ $jobPoster)
Loading history...
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
        //TODO: Right now preview can't have the update gate, because we use the
247
            //  same view for viewing even after its been submitted. These should
248
            //  be seperate views, and then Preview can require the update permission.
249
        //Ensure user has permissions to view and update application
250
        $this->authorize('view', $application);
251
        //$this->authorize('update', $application);
252
253
        $criteria = [
254
            '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

254
            '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...
255
                return $value->criteria_type->name == 'essential';
256
            }),
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...
257
            '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

257
            '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...
258
                return $value->criteria_type->name == 'asset';
259
            }),
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...
260
        ];
261
262
        return view('applicant/application_post_05', [
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...
263
264
            /* Application Template Data */
265
                "application_step" => 5,
266
                "application_template" => Lang::get("applicant/application_template"),
267
                "preferred_language_template" => Lang::get('common/preferred_language'),
268
                "citizenship_declaration_template" => Lang::get('common/citizenship_declaration'),
269
                "veteran_status_template" => Lang::get('common/veteran_status'),
270
271
            /* Job Data */
272
                "job" => $jobPoster,
273
274
            /* Skills Data */
275
                "skills" => Skill::all(),
276
                "skill_template" => Lang::get("common/skills"),
277
                "criteria" => $criteria,
278
279
            /* Applicant Data */
280
                "applicant" => $applicant,
281
                "job_application" => $application,
282
283
            /* Submission */
284
                "form_submit_action" => route('job.application.submit', $jobPoster)
0 ignored issues
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

284
                "form_submit_action" => route('job.application.submit', /** @scrutinizer ignore-type */ $jobPoster)
Loading history...
285
286
        ]);
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...
287
    }
288
289
    /**
290
     * Show the application submission information.
291
     *
292
     * @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...
293
     * @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...
294
     */
295
    public function complete(JobPoster $jobPoster) {
296
297
        /* Include Applicant Data */
298
299
            $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...
300
301
        /* Include Application Data */
302
303
            $application = $this->getApplicationFromJob($jobPoster);
304
305
            //Ensure user has permissions to view application
306
            $this->authorize('view', $application);
307
308
        /* Return the Completion View */
309
310
            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...
311
312
                /* Application Template Data */
313
                    "application_template" => Lang::get("applicant/application_template"),
314
315
                /* Job Data */
316
                    "job" => $jobPoster,
317
318
                /* Applicant Data */
319
                    "applicant" => $applicant,
320
                    "job_application" => $application
321
322
            ]);
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...
323
324
    }
325
326
    /**
327
     * Update the Application Basics in storage for the specified job.
328
     *
329
     * @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...
330
     * @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...
331
     * @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...
332
     */
333
    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...
334
    {
335
        $input = $request->input();
336
        $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...
337
        $application = $this->getApplicationFromJob($jobPoster);
338
339
        //Ensure user has permissions to update this application
340
        $this->authorize('update', $application);
341
342
        $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...
343
            'citizenship_declaration_id' => $input['citizenship_declaration_id'],
344
            'veteran_status_id' => $input['veteran_status_id'],
345
            'preferred_language_id' => $input['preferred_language_id'],
346
        ]);
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...
347
        $application->save();
348
349
        $questions = $jobPoster->job_poster_questions;
350
        foreach($questions as $question) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
351
            $answer = null;
352
            if (isset($input['questions']) &&
353
                isset($input['questions'][$question->id])) {
0 ignored issues
show
Coding Style introduced by
Each line in a multi-line IF statement must begin with a boolean operator
Loading history...
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
354
                $answer = $input['questions'][$question->id];
355
            }
356
            $answerObj = $application->job_application_answers
357
                ->firstWhere('job_poster_question_id', $question->id);
358
            if ($answerObj == null) {
359
                $answerObj = new JobApplicationAnswer();
360
                $answerObj->job_poster_question_id = $question->id;
361
                $answerObj->job_application_id = $application->id;
362
            }
363
            $answerObj->answer = $answer;
364
            $answerObj->save();
365
        }
366
367
        //Redirect to correct page
368
        switch($input['submit']) {
369
            case 'save_and_quit':
370
            case 'previous':
371
                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...
372
                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...
373
            case 'save_and_continue':
374
            case 'next':
375
                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...
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

375
                return redirect()->route('job.application.edit.2', /** @scrutinizer ignore-type */ $jobPoster);
Loading history...
376
                break;
377
            default:
378
                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...
379
                break;
380
        }
381
    }
382
383
    /**
384
     * Update the Application Basics in storage for the specified job.
385
     *
386
     * @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...
387
     * @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...
388
     * @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...
389
     */
390
    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...
391
    {
392
        $input = $request->input();
393
        $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...
394
        $application = $this->getApplicationFromJob($jobPoster);
395
396
        //Ensure user has permissions to update this application
397
        $this->authorize('update', $application);
398
399
        $degrees = $input['degrees'];
400
401
        //Save new degrees
402
        if (isset($degrees['new'])) {
403
            foreach($degrees['new'] as $degreeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
404
                $degree = new Degree();
405
                $degree->applicant_id = $applicant->id;
406
                $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...
407
                    'degree_type_id' => $degreeInput['degree_type_id'],
408
                    'area_of_study' => $degreeInput['area_of_study'],
409
                    'institution' => $degreeInput['institution'],
410
                    'thesis' => $degreeInput['thesis'],
411
                    'start_date' => $degreeInput['start_date'],
412
                    'end_date' => $degreeInput['end_date']
413
                ]);
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...
414
                $degree->save();
415
            }
416
        }
417
418
        //Update old degrees
419
        if (isset($degrees['old'])) {
420
            foreach($degrees['old'] as $id=>$degreeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
421
                //Ensure this degree belongs to this applicant
422
                $degree = $applicant->degrees->firstWhere('id', $id);
423
                if ($degree != null) {
424
                    $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...
425
                        'degree_type_id' => $degreeInput['degree_type_id'],
426
                        'area_of_study' => $degreeInput['area_of_study'],
427
                        'institution' => $degreeInput['institution'],
428
                        'thesis' => $degreeInput['thesis'],
429
                        'start_date' => $degreeInput['start_date'],
430
                        'end_date' => $degreeInput['end_date']
431
                    ]);
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...
432
                    $degree->save();
433
                } else {
434
                    Debugbar::warning('Applicant '.$applicant->id.' attempted to update degree with invalid id '.$id);
435
                }
436
            }
437
        }
438
439
        $courses = $input['courses'];
440
441
        //Save new courses
442
        if (isset($courses['new'])) {
443
            foreach($courses['new'] as $courseInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
444
                $course = new Course();
445
                $course->applicant_id = $applicant->id;
446
                $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...
447
                    'name' => $courseInput['name'],
448
                    'institution' => $courseInput['institution'],
449
                    'course_status_id' => $courseInput['course_status_id'],
450
                    'start_date' => $courseInput['start_date'],
451
                    'end_date' => $courseInput['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
                $course->save();
454
            }
455
        }
456
457
        //Update old courses
458
        if (isset($courses['old'])) {
459
            foreach($courses['old'] as $id=>$courseInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
460
                //Ensure this course belongs to this applicant
461
                $course = $applicant->courses->firstWhere('id', $id);
462
                if ($course != null) {
463
                    $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...
464
                        'name' => $courseInput['name'],
465
                        'institution' => $courseInput['institution'],
466
                        'course_status_id' => $courseInput['course_status_id'],
467
                        'start_date' => $courseInput['start_date'],
468
                        'end_date' => $courseInput['end_date']
469
                    ]);
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...
470
                    $course->save();
471
                } else {
472
                    Debugbar::warning('Applicant '.$applicant->id.' attempted to update course with invalid id '.$id);
473
                }
474
            }
475
        }
476
477
        $work_experiences = $input['work_experiences'] ;
478
479
        //Save new work_experiences
480
        if (isset($work_experiences['new'])) {
481
            foreach($work_experiences['new'] as $workExperienceInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
482
                $workExperience = new WorkExperience();
483
                $workExperience->applicant_id = $applicant->id;
484
                $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...
485
                    'role' => $workExperienceInput['role'],
486
                    'company' => $workExperienceInput['company'],
487
                    'description' => $workExperienceInput['description'],
488
                    'start_date' => $workExperienceInput['start_date'],
489
                    'end_date' => $workExperienceInput['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
                $workExperience->save();
492
            }
493
        }
494
495
        //Update old work_experiences
496
        if (isset($work_experiences['old'])) {
497
            foreach($work_experiences['old'] as $id=>$workExperienceInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
498
                //Ensure this work_experience belongs to this applicant
499
                $workExperience = $applicant->work_experiences->firstWhere('id', $id);
500
                if ($workExperience != null) {
501
                    $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...
502
                        'role' => $workExperienceInput['role'],
503
                        'company' => $workExperienceInput['company'],
504
                        'description' => $workExperienceInput['description'],
505
                        'start_date' => $workExperienceInput['start_date'],
506
                        'end_date' => $workExperienceInput['end_date']
507
                    ]);
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...
508
                    $workExperience->save();
509
                } else {
510
                    Debugbar::warning('Applicant '.$applicant->id.' attempted to update work_experience with invalid id '.$id);
511
                }
512
            }
513
        }
514
515
        //Redirect to correct page
516
        switch($input['submit']) {
517
            case 'save_and_quit':
518
                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...
519
                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...
520
            case 'save_and_continue':
521
            case 'next':
522
                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...
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

522
                return redirect()->route('job.application.edit.3', /** @scrutinizer ignore-type */ $jobPoster);
Loading history...
523
                break;
524
            case 'previous':
525
                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...
526
                break;
527
            default:
528
                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...
529
                break;
530
        }
531
    }
532
533
    /**
534
     * Update the Application Essential Skills in storage for the specified job.
535
     *
536
     * @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...
537
     * @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...
538
     * @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...
539
     */
540
    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...
541
    {
542
        $input = $request->input();
543
        $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...
544
        $application = $this->getApplicationFromJob($jobPoster);
545
546
        //Ensure user has permissions to update this application
547
        $this->authorize('update', $application);
548
549
        $skillDeclarations = $input['skill_declarations'];
550
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
551
552
        //Save new skill declarartions
553
        if (isset($skillDeclarations['new'])) {
554
            foreach($skillDeclarations['new'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
555
                foreach($typeInput as $criterion_id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
556
                    $skillDeclaration = new SkillDeclaration();
557
                    $skillDeclaration->applicant_id = $applicant->id;
558
                    $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id;
559
                    $skillDeclaration->skill_status_id = $claimedStatusId;
560
                    $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...
561
                        'description' => $skillDeclarationInput['description'],
562
                        'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
563
                    ]);
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...
564
                    $skillDeclaration->save();
565
566
                    $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
567
                    $skillDeclaration->references()->sync($referenceIds);
568
569
                    $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
570
                    $skillDeclaration->work_samples()->sync($sampleIds);
571
                }
572
            }
573
        }
574
575
        //Update old declarations
576
        if (isset($skillDeclarations['old'])) {
577
            foreach($skillDeclarations['old'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
578
                foreach($typeInput as $id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
579
                    //Ensure this declaration belongs to this applicant
580
                    $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id);
581
                    if ($skillDeclaration != null) {
582
                        //skill_id and skill_status cannot be changed
583
                        $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...
584
                            'description' => $skillDeclarationInput['description'],
585
                            'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
586
                        ]);
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...
587
                        $skillDeclaration->save();
588
589
                        $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
590
                        $skillDeclaration->references()->sync($referenceIds);
591
592
                        $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
593
                        $skillDeclaration->work_samples()->sync($sampleIds);
594
                    } else {
595
                        Debugbar::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id);
596
                    }
597
                }
598
            }
599
        }
600
601
        //Redirect to correct page
602
        switch($input['submit']) {
603
            case 'save_and_quit':
604
                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...
605
                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...
606
            case 'save_and_continue':
607
            case 'next':
608
                return redirect()->route('job.application.edit.4', $jobPoster);
1 ignored issue
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

608
                return redirect()->route('job.application.edit.4', /** @scrutinizer ignore-type */ $jobPoster);
Loading history...
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...
609
                break;
610
            case 'previous':
611
                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...
612
                break;
613
            default:
614
                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...
615
                break;
616
        }
617
    }
618
619
    /**
620
     * Update the Application Asset Skills in storage for the specified job.
621
     *
622
     * @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...
623
     * @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...
624
     * @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...
625
     */
626
    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...
627
    {
628
        $input = $request->input();
629
        $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...
630
        $application = $this->getApplicationFromJob($jobPoster);
631
632
        //Ensure user has permissions to update this application
633
        $this->authorize('update', $application);
634
635
        $skillDeclarations = $input['skill_declarations'];
636
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
637
638
        //Save new skill declarartions
639
        if (isset($skillDeclarations['new'])) {
640
            foreach($skillDeclarations['new'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
641
                foreach($typeInput as $criterion_id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
642
                    $skillDeclaration = new SkillDeclaration();
643
                    $skillDeclaration->applicant_id = $applicant->id;
644
                    $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id;
645
                    $skillDeclaration->skill_status_id = $claimedStatusId;
646
                    $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...
647
                        'description' => $skillDeclarationInput['description'],
648
                        'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
649
                    ]);
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...
650
                    $skillDeclaration->save();
651
652
                    $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
653
                    $skillDeclaration->references()->sync($referenceIds);
654
655
                    $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
656
                    $skillDeclaration->work_samples()->sync($sampleIds);
657
                }
658
            }
659
        }
660
661
        //Update old declarations
662
        if (isset($skillDeclarations['old'])) {
663
            foreach($skillDeclarations['old'] as $skillType => $typeInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
664
                foreach($typeInput as $id=>$skillDeclarationInput) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
665
                    //Ensure this declaration belongs to this applicant
666
                    $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id);
667
                    if ($skillDeclaration != null) {
668
                        //skill_id and skill_status cannot be changed
669
                        $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...
670
                            'description' => $skillDeclarationInput['description'],
671
                            'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
672
                        ]);
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...
673
                        $skillDeclaration->save();
674
675
                        $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
676
                        $skillDeclaration->references()->sync($referenceIds);
677
678
                        $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
679
                        $skillDeclaration->work_samples()->sync($sampleIds);
680
                    } else {
681
                        Debugbar::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id);
682
                    }
683
                }
684
            }
685
        }
686
687
        //Redirect to correct page
688
        switch($input['submit']) {
689
            case 'save_and_quit':
690
                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...
691
                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...
692
            case 'save_and_continue':
693
            case 'next':
694
                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...
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

694
                return redirect()->route('job.application.edit.5', /** @scrutinizer ignore-type */ $jobPoster);
Loading history...
695
                break;
696
            case 'previous':
697
                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...
698
                break;
699
            default:
700
                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...
701
                break;
702
        }
703
    }
704
705
    /**
706
     * Submit the Application for the specified job.
707
     *
708
     * @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...
709
     * @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...
710
     * @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...
711
     */
712
    public function submit(Request $request, JobPoster $jobPoster)
713
    {
714
        $input = $request->input();
715
        $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...
716
        $application = $this->getApplicationFromJob($jobPoster);
717
718
        //Ensure user has permissions to update this application
719
        $this->authorize('update', $application);
720
721
        //Only save anything if submit button was pressed
722
        if ($input['submit'] == "submit") {
723
724
            $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...
725
                'submission_signature' => [
726
                    'required',
727
                    'string',
728
                    'max:191',
729
                ],
730
                'submission_date' => [
731
                    'required',
732
                    'string',
733
                    'max:191',
734
               ]
735
           ]);
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...
736
737
            //Save any final info
738
            $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...
739
                'submission_signature' => $input['submission_signature'],
740
                'submission_date' => $input['submission_date'],
741
            ]);
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...
742
743
            $validator = new ApplicationValidator();
744
            $validator->validate($application);
745
746
            //Change status to 'submitted'
747
            $application->application_status_id = ApplicationStatus::where('name', 'submitted')->firstOrFail()->id;
748
        }
749
750
        $application->save();
751
752
        //Redirect to correct page
753
        switch($input['submit']) {
754
            case 'save_and_quit':
755
                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...
756
                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...
757
            case 'submit':
758
                return redirect()->route('job.application.complete', $jobPoster);
1 ignored issue
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

758
                return redirect()->route('job.application.complete', /** @scrutinizer ignore-type */ $jobPoster);
Loading history...
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...
759
                break;
760
            case 'previous':
761
                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...
762
                break;
763
            default:
764
                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...
765
                break;
766
        }
767
    }
768
}
769