Test Setup Failed
Branch feature/job-builder/work-env-r... (305963)
by Grant
52:57 queued 34:52
created

ApplicationByJobController::editBasics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 31
ccs 0
cts 19
cp 0
crap 2
rs 9.424
c 0
b 0
f 0
1
<?php
2
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\JobPoster;
12
use App\Models\JobApplication;
13
use App\Models\JobApplicationAnswer;
14
use App\Models\SkillDeclaration;
15
use App\Models\Skill;
16
use App\Models\Lookup\SkillStatus;
17
use App\Models\Degree;
18
use App\Models\Criteria;
19
use App\Models\Course;
20
use App\Models\WorkExperience;
21
use App\Services\Validation\ApplicationValidator;
22
use Illuminate\Support\Facades\Auth;
23
use Illuminate\Support\Facades\Log;
24
use App\Models\Lookup\ReviewStatus;
25
26
class ApplicationByJobController extends Controller
27
{
28
    /**
29
     * Display a listing of the applications for given jobPoster.
30
     *
31
     * @param  \App\Models\JobPoster $jobPoster Incoming JobPoster object.
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function index(JobPoster $jobPoster)
35
    {
36
        $applications = $jobPoster->submitted_applications()
37
            ->with([
38
                'veteran_status',
39
                'citizenship_declaration',
40
                'application_review',
41
                'applicant.user',
42
                'job_poster.criteria',
43
            ])
44
            ->get();
45
        return view('manager/review_applications', [
46
            // Localization Strings.
47
            'jobs_l10n' => Lang::get('manager/job_index'),
48
            // Data.
49
            'job' => $jobPoster->toApiArray(),
50
            'applications' => $applications,
51
            'review_statuses' => ReviewStatus::all()
52
        ]);
53
    }
54
55
    /**
56
     * Return the current applicant's application for a given Job Poster.
57
     *
58
     * @param  \App\Models\JobPoster $jobPoster Incoming JobPoster object.
59
     * @return mixed|\App\Models\JobApplication
60
     */
61
    protected function getApplicationFromJob(JobPoster $jobPoster)
62
    {
63
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
64
            ->where('job_poster_id', $jobPoster->id)->first();
65
        if ($application == null) {
66
            $application = new JobApplication();
67
            $application->job_poster_id = $jobPoster->id;
68
            $application->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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
69
            $application->application_status_id = ApplicationStatus::where('name', 'draft')->firstOrFail()->id;
70
            $application->save();
71
        }
72
        return $application;
73
    }
74
75
    /**
76
     * Show the form for editing Application basics for the specified job.
77
     *
78
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
79
     * @return \Illuminate\Http\Response
80
     */
81
    public function editBasics(JobPoster $jobPoster)
82
    {
83
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
84
        $application = $this->getApplicationFromJob($jobPoster);
85
86
        // Ensure user has permissions to view and update application.
87
        $this->authorize('view', $application);
88
        $this->authorize('update', $application);
89
90
        return view(
91
            'applicant/application_post_01',
92
            [
93
                // Application Template Data.
94
                'application_step' => 1,
95
                'application_template' => Lang::get('applicant/application_template'),
96
                'language_options' => PreferredLanguage::all(),
97
                'citizenship_options' => CitizenshipDeclaration::all(),
98
                'veteran_options' => VeteranStatus::all(),
99
                'preferred_language_template' => Lang::get('common/preferred_language'),
100
                'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'),
101
                'veteran_status_template' => Lang::get('common/veteran_status'),
102
                // Job Data.
103
                'job' => $jobPoster,
104
                // Applicant Data.
105
                'applicant' => $applicant,
106
                'job_application' => $application,
107
                // Submission.
108
                'form_submit_action' => route('job.application.update.1', $jobPoster)
109
            ]
110
        );
111
    }
112
113
    /**
114
     * Show the form for editing Application Experience for the specified job.
115
     *
116
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
117
     * @return \Illuminate\Http\Response
118
     */
119
    public function editExperience(JobPoster $jobPoster)
120
    {
121
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
122
        $application = $this->getApplicationFromJob($jobPoster);
123
124
        // Ensure user has permissions to view and update application.
125
        $this->authorize('view', $application);
126
        $this->authorize('update', $application);
127
128
        return view(
129
            'applicant/application_post_02',
130
            [
131
                // Application Template Data.
132
                'application_step' => 2,
133
                'application_template' => Lang::get('applicant/application_template'),
134
                // Job Data.
135
                'job' => $jobPoster,
136
                // Applicant Data.
137
                'applicant' => $applicant,
138
                'job_application' => $application,
139
                // Submission.
140
                'form_submit_action' => route('job.application.update.2', $jobPoster)
141
            ]
142
        );
143
    }
144
145
    /**
146
     * Show the form for editing Application Essential Skills for the specified job.
147
     *
148
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
149
     * @return \Illuminate\Http\Response
150
     */
151 View Code Duplication
    public function editEssentialSkills(JobPoster $jobPoster)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
154
        $application = $this->getApplicationFromJob($jobPoster);
155
156
        // Ensure user has permissions to view and update application.
157
        $this->authorize('view', $application);
158
        $this->authorize('update', $application);
159
160
        $criteria = [
161
            '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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
162
                return $value->criteria_type->name == 'essential';
163
            }),
164
            '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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
165
                return $value->criteria_type->name == 'asset';
166
            }),
167
        ];
168
169
        return view(
170
            'applicant/application_post_03',
171
            [
172
                // Application Template Data.
173
                'application_step' => 3,
174
                'application_template' => Lang::get('applicant/application_template'),
175
                // Job Data.
176
                'job' => $jobPoster,
177
                // Skills Data.
178
                'skills' => Skill::all(),
179
                'skill_template' => Lang::get('common/skills'),
180
                'criteria' => $criteria,
181
                // Applicant Data.
182
                'applicant' => $applicant,
183
                'job_application' => $application,
184
                // Submission.
185
                'form_submit_action' => route('job.application.update.3', $jobPoster)
186
            ]
187
        );
188
    }
189
190
    /**
191
     * Show the form for editing Application Asset Skills for the specified job.
192
     *
193
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
194
     * @return \Illuminate\Http\Response
195
     */
196 View Code Duplication
    public function editAssetSkills(JobPoster $jobPoster)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
197
    {
198
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
199
        $application = $this->getApplicationFromJob($jobPoster);
200
201
        // Ensure user has permissions to view and update application.
202
        $this->authorize('view', $application);
203
        $this->authorize('update', $application);
204
205
        $criteria = [
206
            '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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
207
                return $value->criteria_type->name == 'essential';
208
            }),
209
            '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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
210
                return $value->criteria_type->name == 'asset';
211
            }),
212
        ];
213
214
        return view(
215
            'applicant/application_post_04',
216
            [
217
                // Application Template Data.
218
                'application_step' => 4,
219
                'application_template' => Lang::get('applicant/application_template'),
220
                // Job Data.
221
                'job' => $jobPoster,
222
                // Skills Data.
223
                'skills' => Skill::all(),
224
                'skill_template' => Lang::get('common/skills'),
225
                'criteria' => $criteria,
226
                // Applicant Data.
227
                'applicant' => $applicant,
228
                'job_application' => $application,
229
                // Submission.
230
                'form_submit_action' => route('job.application.update.4', $jobPoster)
231
            ]
232
        );
233
    }
234
235
    /**
236
     * Show the Application Preview for the application for the specified job.
237
     *
238
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
239
     * @return \Illuminate\Http\Response
240
     */
241
    public function preview(JobPoster $jobPoster)
242
    {
243
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
244
        $application = $this->getApplicationFromJob($jobPoster);
245
246
        $this->authorize('view', $application);
247
        $criteria = [
248
            '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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
249
                return $value->criteria_type->name == 'essential';
250
            }),
251
            '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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
252
                return $value->criteria_type->name == 'asset';
253
            }),
254
        ];
255
256
        return view(
257
            'applicant/application_post_05',
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
                // Job Data.
266
                'job' => $jobPoster,
267
                // Skills Data.
268
                'skills' => Skill::all(),
269
                'skill_template' => Lang::get('common/skills'),
270
                'criteria' => $criteria,
271
                // Applicant Data.
272
                'applicant' => $applicant,
273
                'job_application' => $application,
274
            ]
275
        );
276
    }
277
278
    /**
279
     * Show the Confirm Submit page for the application for the specified job.
280
     *
281
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
282
     * @return \Illuminate\Http\Response
283
     */
284
    public function confirm(JobPoster $jobPoster)
285
    {
286
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Unused Code introduced by
$applicant is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
287
        $application = $this->getApplicationFromJob($jobPoster);
288
289
        $this->authorize('update', $application);
290
291
        return view(
292
            'applicant/application_post_06',
293
            [
294
                // Application Template Data.
295
                'application_step' => 6,
296
                'application_template' => Lang::get('applicant/application_template'),
297
                // Used by tracker partial.
298
                'job' => $jobPoster,
299
                'job_application' => $application,
300
                // Submission.
301
                'form_submit_action' => route('job.application.submit', $jobPoster)
302
            ]
303
        );
304
    }
305
306
    /**
307
     * Show the application submission information.
308
     *
309
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
310
     * @return \Illuminate\Http\Response
311
     */
312
    public function complete(JobPoster $jobPoster)
313
    {
314
        // Include Applicant Data.
315
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
316
        // Include Application Data.
317
        $application = $this->getApplicationFromJob($jobPoster);
318
319
        // Ensure user has permissions to view application.
320
        $this->authorize('view', $application);
321
322
        // Return the Completion View.
323
        return view(
324
            'applicant/application_post_complete',
325
            [
326
                // Application Template Data.
327
                'application_template' => Lang::get('applicant/application_template'),
328
                // Job Data.
329
                'job' => $jobPoster,
330
                // Applicant Data.
331
                'applicant' => $applicant,
332
                'job_application' => $application
333
            ]
334
        );
335
    }
336
337
    /**
338
     * Update the Application Basics in storage for the specified job.
339
     *
340
     * @param  \Illuminate\Http\Request $request   Incoming Request object.
341
     * @param  \App\Models\JobPoster    $jobPoster Incoming Job Poster object.
342
     * @return \Illuminate\Http\Response
343
     */
344
    public function updateBasics(Request $request, JobPoster $jobPoster)
345
    {
346
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Unused Code introduced by
$applicant is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
347
        $application = $this->getApplicationFromJob($jobPoster);
348
349
        // Ensure user has permissions to update this application.
350
        $this->authorize('update', $application);
351
352
        $application->fill([
353
            'citizenship_declaration_id' => $request->input('citizenship_declaration_id'),
354
            'veteran_status_id' => $request->input('veteran_status_id'),
355
            'preferred_language_id' => $request->input('preferred_language_id'),
356
            'language_requirement_confirmed' => $request->input('language_requirement_confirmed')
357
        ]);
358
        $application->save();
359
360
        $questions = $jobPoster->job_poster_questions;
361
        $questionsInput = $request->input('questions');
362
        foreach ($questions as $question) {
363
            $answer = null;
364
            if (isset($questionsInput[$question->id])) {
365
                $answer = $questionsInput[$question->id];
366
            }
367
            $answerObj = $application->job_application_answers
368
            ->firstWhere('job_poster_question_id', $question->id);
369
            if ($answerObj == null) {
370
                $answerObj = new JobApplicationAnswer();
371
                $answerObj->job_poster_question_id = $question->id;
372
                $answerObj->job_application_id = $application->id;
373
            }
374
            $answerObj->answer = $answer;
375
            $answerObj->save();
376
        }
377
378
        // Redirect to correct page.
379
        switch ($request->input('submit')) {
380
            case 'save_and_quit':
381
            case 'previous':
382
                return redirect()->route('applications.index');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect()->route('applications.index'); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\App...ontroller::updateBasics of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
383
                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...
384
            case 'save_and_continue':
385
            case 'next':
386
                return redirect()->route('job.application.edit.2', $jobPoster);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return redirect()->route...n.edit.2', $jobPoster); (Illuminate\Http\RedirectResponse) is incompatible with the return type documented by App\Http\Controllers\App...ontroller::updateBasics of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
387
                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...
388
            default:
389
                return redirect()->back()->withInput();
390
        }
391
    }
392
393
    /**
394
     * Update the Application Basics in storage for the specified job.
395
     *
396
     * @param  \Illuminate\Http\Request $request   Incoming Request object.
397
     * @param  \App\Models\JobPoster    $jobPoster Incoming Job Poster object.
398
     * @return \Illuminate\Http\Response
399
     */
400
    public function updateExperience(Request $request, JobPoster $jobPoster)
401
    {
402
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
403
        $application = $this->getApplicationFromJob($jobPoster);
404
405
        // Ensure user has permissions to update this application.
406
        $this->authorize('update', $application);
407
408
        // Record that the user has saved their experience for this application.
409
        $application->experience_saved = true;
410
        $application->save();
411
412
        $degrees = $request->input('degrees');
413
414
        $request->validate([
415
            'degrees.new.*.degree_type_id' => 'required',
416
            'degrees.new.*.area_of_study'  => 'required',
417
            'degrees.new.*.institution'    => 'required',
418
            'degrees.new.*.thesis'         => 'nullable',
419
            'degrees.new.*.start_date'     => 'required|date',
420
            'degrees.new.*.end_date'       => 'required|date',
421
            'degrees.new.*.blockcert_url'  => 'nullable|string',
422
        ]);
423
424
        // Save new degrees.
425 View Code Duplication
        if (isset($degrees['new'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
426
            foreach ($degrees['new'] as $degreeInput) {
427
                $degree = new Degree();
428
                $degree->applicant_id = $applicant->id;
429
                $degree->fill([
430
                    'degree_type_id' => $degreeInput['degree_type_id'],
431
                    'area_of_study' => $degreeInput['area_of_study'],
432
                    'institution' => $degreeInput['institution'],
433
                    'thesis' => $degreeInput['thesis'],
434
                    'start_date' => $degreeInput['start_date'],
435
                    'end_date' => $degreeInput['end_date'],
436
                    'blockcert_url' => $degreeInput['blockcert_url'],
437
                ]);
438
                $degree->save();
439
            }
440
        }
441
442
        // Update old degrees.
443 View Code Duplication
        if (isset($degrees['old'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
444
            foreach ($degrees['old'] as $id => $degreeInput) {
445
                // Ensure this degree belongs to this applicant.
446
                $degree = $applicant->degrees->firstWhere('id', $id);
447
                if ($degree != null) {
448
                    $degree->fill([
449
                        'degree_type_id' => $degreeInput['degree_type_id'],
450
                        'area_of_study' => $degreeInput['area_of_study'],
451
                        'institution' => $degreeInput['institution'],
452
                        'thesis' => $degreeInput['thesis'],
453
                        'start_date' => $degreeInput['start_date'],
454
                        'end_date' => $degreeInput['end_date'],
455
                        'blockcert_url' => $degreeInput['blockcert_url'],
456
                    ]);
457
                    $degree->save();
458
                } else {
459
                    Log::warning("Applicant $applicant->id attempted to update degree with invalid id: $id");
460
                }
461
            }
462
        }
463
464
        $courses = $request->input('courses');
465
466
        $request->validate([
467
            'courses.new.*.name'             => 'required',
468
            'courses.new.*.institution'      => 'required',
469
            'courses.new.*.course_status_id' => 'required',
470
            'courses.new.*.start_date'       => 'required|date',
471
            'courses.new.*.end_date'         => 'required|date',
472
        ]);
473
474
        // Save new courses.
475 View Code Duplication
        if (isset($courses['new'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
476
            foreach ($courses['new'] as $courseInput) {
477
                $course = new Course();
478
                $course->applicant_id = $applicant->id;
479
                $course->fill([
480
                    'name' => $courseInput['name'],
481
                    'institution' => $courseInput['institution'],
482
                    'course_status_id' => $courseInput['course_status_id'],
483
                    'start_date' => $courseInput['start_date'],
484
                    'end_date' => $courseInput['end_date']
485
                ]);
486
                $course->save();
487
            }
488
        }
489
490
        // Update old courses.
491 View Code Duplication
        if (isset($courses['old'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
492
            foreach ($courses['old'] as $id => $courseInput) {
493
                // Ensure this course belongs to this applicant.
494
                $course = $applicant->courses->firstWhere('id', $id);
495
                if ($course != null) {
496
                    $course->fill([
497
                        'name' => $courseInput['name'],
498
                        'institution' => $courseInput['institution'],
499
                        'course_status_id' => $courseInput['course_status_id'],
500
                        'start_date' => $courseInput['start_date'],
501
                        'end_date' => $courseInput['end_date']
502
                    ]);
503
                    $course->save();
504
                } else {
505
                    Log::warning("Applicant $applicant->id attempted to update course with invalid id: $id");
506
                }
507
            }
508
        }
509
510
        $work_experiences = $request->input('work_experiences');
511
512
        $request->validate([
513
            'work_experiences.new.*.role'        => 'required',
514
            'work_experiences.new.*.company'     => 'required',
515
            'work_experiences.new.*.description' => 'required',
516
            'work_experiences.new.*.start_date'  => 'required|date',
517
            'work_experiences.new.*.end_date'    => 'required|date',
518
        ]);
519
520
        // Save new work_experiences.
521 View Code Duplication
        if (isset($work_experiences['new'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
522
            foreach ($work_experiences['new'] as $workExperienceInput) {
523
                $workExperience = new WorkExperience();
524
                $workExperience->applicant_id = $applicant->id;
525
                $workExperience->fill([
526
                    'role' => $workExperienceInput['role'],
527
                    'company' => $workExperienceInput['company'],
528
                    'description' => $workExperienceInput['description'],
529
                    'start_date' => $workExperienceInput['start_date'],
530
                    'end_date' => $workExperienceInput['end_date']
531
                ]);
532
                $workExperience->save();
533
            }
534
        }
535
536
        // Update old work_experiences.
537 View Code Duplication
        if (isset($work_experiences['old'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
538
            foreach ($work_experiences['old'] as $id => $workExperienceInput) {
539
                // Ensure this work_experience belongs to this applicant.
540
                $workExperience = $applicant->work_experiences->firstWhere('id', $id);
541
                if ($workExperience != null) {
542
                    $workExperience->fill([
543
                        'role' => $workExperienceInput['role'],
544
                        'company' => $workExperienceInput['company'],
545
                        'description' => $workExperienceInput['description'],
546
                        'start_date' => $workExperienceInput['start_date'],
547
                        'end_date' => $workExperienceInput['end_date']
548
                    ]);
549
                    $workExperience->save();
550
                } else {
551
                    Log::warning("Applicant $applicant->id attempted to update work_experience with invalid id: $id");
552
                }
553
            }
554
        }
555
556
        // Redirect to correct page.
557
        switch ($request->input('submit')) {
558
            case 'save_and_quit':
559
                return redirect()->route('applications.index');
560
                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...
561
            case 'save_and_continue':
562
            case 'next':
563
                return redirect()->route('job.application.edit.3', $jobPoster);
564
                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...
565
            case 'previous':
566
                return redirect()->route('job.application.edit.1', $jobPoster);
567
                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...
568
            default:
569
                return redirect()->back()->withInput();
570
        }
571
    }
572
573
    /**
574
     * Update the Application Essential Skills in storage for the specified job.
575
     *
576
     * @param  \Illuminate\Http\Request $request   Incoming Request object.
577
     * @param  \App\Models\JobPoster    $jobPoster Incoming Job Poster object.
578
     * @return \Illuminate\Http\Response
579
     */
580 View Code Duplication
    public function updateEssentialSkills(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
581
    {
582
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
583
        $application = $this->getApplicationFromJob($jobPoster);
584
585
        // Ensure user has permissions to update this application.
586
        $this->authorize('update', $application);
587
588
        $skillDeclarations = $request->input('skill_declarations');
589
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
590
591
        // Save new skill declarartions.
592
        if (isset($skillDeclarations['new'])) {
593
            foreach ($skillDeclarations['new'] as $skillType => $typeInput) {
594
                foreach ($typeInput as $criterion_id => $skillDeclarationInput) {
595
                    $skillDeclaration = new SkillDeclaration();
596
                    $skillDeclaration->applicant_id = $applicant->id;
597
                    $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id;
598
                    $skillDeclaration->skill_status_id = $claimedStatusId;
599
                    $skillDeclaration->fill([
600
                        'description' => $skillDeclarationInput['description'],
601
                        'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
602
                    ]);
603
                    $skillDeclaration->save();
604
605
                    $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
606
                    $skillDeclaration->references()->sync($referenceIds);
607
608
                    $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
609
                    $skillDeclaration->work_samples()->sync($sampleIds);
610
                }
611
            }
612
        }
613
614
        // Update old declarations.
615
        if (isset($skillDeclarations['old'])) {
616
            foreach ($skillDeclarations['old'] as $skillType => $typeInput) {
617
                foreach ($typeInput as $id => $skillDeclarationInput) {
618
                    // Ensure this declaration belongs to this applicant.
619
                    $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id);
620
                    if ($skillDeclaration != null) {
621
                        // skill_id and skill_status cannot be changed.
622
                        $skillDeclaration->fill([
623
                            'description' => $skillDeclarationInput['description'],
624
                            'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
625
                        ]);
626
                        $skillDeclaration->save();
627
628
                        $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
629
                        $skillDeclaration->references()->sync($referenceIds);
630
631
                        $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
632
                        $skillDeclaration->work_samples()->sync($sampleIds);
633
                    } else {
634
                        Log::warning("Applicant $applicant->id attempted to update skill declaration with invalid id: $id");
635
                    }
636
                }
637
            }
638
        }
639
640
        // Redirect to correct page.
641
        switch ($request->input('submit')) {
642
            case 'save_and_quit':
643
                return redirect()->route('applications.index');
644
                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...
645
            case 'save_and_continue':
646
            case 'next':
647
                return redirect()->route('job.application.edit.4', $jobPoster);
648
                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...
649
            case 'previous':
650
                return redirect()->route('job.application.edit.2', $jobPoster);
651
                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...
652
            default:
653
                return redirect()->back()->withInput();
654
        }
655
    }
656
657
    /**
658
     * Update the Application Asset Skills in storage for the specified job.
659
     *
660
     * @param  \Illuminate\Http\Request $request   Incoming Request object.
661
     * @param  \App\Models\JobPoster    $jobPoster Incoming Job Poster object.
662
     * @return \Illuminate\Http\Response
663
     */
664 View Code Duplication
    public function updateAssetSkills(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
665
    {
666
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
667
        $application = $this->getApplicationFromJob($jobPoster);
668
669
        // Ensure user has permissions to update this application.
670
        $this->authorize('update', $application);
671
672
        $skillDeclarations = $request->input('skill_declarations');
673
        $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id;
674
675
        // Save new skill declarartions.
676
        if (isset($skillDeclarations['new'])) {
677
            foreach ($skillDeclarations['new'] as $skillType => $typeInput) {
678
                foreach ($typeInput as $criterion_id => $skillDeclarationInput) {
679
                    $skillDeclaration = new SkillDeclaration();
680
                    $skillDeclaration->applicant_id = $applicant->id;
681
                    $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id;
682
                    $skillDeclaration->skill_status_id = $claimedStatusId;
683
                    $skillDeclaration->fill([
684
                        'description' => $skillDeclarationInput['description'],
685
                        'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
686
                    ]);
687
                    $skillDeclaration->save();
688
689
                    $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
690
                    $skillDeclaration->references()->sync($referenceIds);
691
692
                    $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
693
                    $skillDeclaration->work_samples()->sync($sampleIds);
694
                }
695
            }
696
        }
697
698
        // Update old declarations.
699
        if (isset($skillDeclarations['old'])) {
700
            foreach ($skillDeclarations['old'] as $skillType => $typeInput) {
701
                foreach ($typeInput as $id => $skillDeclarationInput) {
702
                    // Ensure this declaration belongs to this applicant.
703
                    $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id);
704
                    if ($skillDeclaration != null) {
705
                        // skill_id and skill_status cannot be changed.
706
                        $skillDeclaration->fill([
707
                            'description' => $skillDeclarationInput['description'],
708
                            'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null,
709
                        ]);
710
                        $skillDeclaration->save();
711
712
                        $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references');
713
                        $skillDeclaration->references()->sync($referenceIds);
714
715
                        $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples');
716
                        $skillDeclaration->work_samples()->sync($sampleIds);
717
                    } else {
718
                        Log::warning("Applicant $applicant->id attempted to update skill declaration with invalid id: $id");
719
                    }
720
                }
721
            }
722
        }
723
724
        // Redirect to correct page.
725
        switch ($request->input('submit')) {
726
            case 'save_and_quit':
727
                return redirect()->route('applications.index');
728
                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...
729
            case 'save_and_continue':
730
            case 'next':
731
                return redirect()->route('job.application.edit.5', $jobPoster);
732
                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...
733
            case 'previous':
734
                return redirect()->route('job.application.edit.3', $jobPoster);
735
                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...
736
            default:
737
                return redirect()->back()->withInput();
738
        }
739
    }
740
741
    /**
742
     * Submit the Application for the specified job.
743
     *
744
     * @param  \Illuminate\Http\Request $request   Incoming Request object.
745
     * @param  \App\Models\JobPoster    $jobPoster Incoming Job Poster object.
746
     * @return \Illuminate\Http\Response
747
     */
748
    public function submit(Request $request, JobPoster $jobPoster)
749
    {
750
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Unused Code introduced by
$applicant is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
751
        $application = $this->getApplicationFromJob($jobPoster);
752
753
        // Ensure user has permissions to update this application.
754
        $this->authorize('update', $application);
755
756
        // Only complete submission if submit button was pressed.
757
        if ($request->input('submit') == 'submit') {
758
            $request->validate([
759
                'submission_signature' => [
760
                    'required',
761
                    'string',
762
                    'max:191',
763
                ],
764
                'submission_date' => [
765
                    'required',
766
                    'string',
767
                    'max:191',
768
                ]
769
            ]);
770
771
            // Save any final info.
772
            $application->fill([
773
                'submission_signature' => $request->input('submission_signature'),
774
                'submission_date' => $request->input('submission_date'),
775
            ]);
776
777
            $validator = new ApplicationValidator();
778
            $validator->validate($application);
779
780
            // Change status to 'submitted'.
781
            $application->application_status_id = ApplicationStatus::where('name', 'submitted')->firstOrFail()->id;
782
        }
783
784
        $application->save();
785
786
        // Redirect to correct page.
787
        switch ($request->input('submit')) {
788
            case 'save_and_quit':
789
                return redirect()->route('applications.index');
790
                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...
791
            case 'submit':
792
                return redirect()->route('job.application.complete', $jobPoster);
793
                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...
794
            case 'previous':
795
                return redirect()->route('job.application.edit.4', $jobPoster);
796
                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...
797
            default:
798
                return redirect()->back()->withInput();
799
        }
800
    }
801
}
802