Passed
Push — dev ( 35d96c...d805ad )
by Tristan
16:59 queued 08:51
created

JobController   B

Complexity

Total Complexity 47

Size/Duplication

Total Lines 578
Duplicated Lines 0 %

Test Coverage

Coverage 73.93%

Importance

Changes 0
Metric Value
wmc 47
eloc 270
dl 0
loc 578
ccs 190
cts 257
cp 0.7393
rs 8.64
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
B populateCreateView() 0 97 4
A store() 0 26 3
A index() 0 23 1
A managerIndex() 0 13 1
A submitForReview() 0 21 2
A destroy() 0 3 1
B show() 0 77 8
A fillAndSaveJobPosterTasks() 0 24 5
A populateDefaultQuestions() 0 35 3
A fillAndSaveJobPosterQuestions() 0 26 5
A fillAndSaveJobPoster() 0 41 2
B fillAndSaveJobPosterCriteria() 0 40 10

How to fix   Complexity   

Complex Class

Complex classes like JobController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use JobController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Lang;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Facades\Mail;
9
use Illuminate\Http\RedirectResponse;
10
use Illuminate\Http\Request;
11
use Illuminate\Http\Response;
12
use Illuminate\View\View;
13
use App\Http\Controllers\Controller;
14
15
use Carbon\Carbon;
16
17
use App\Mail\JobPosterReviewRequested;
18
19
use App\Models\JobPoster;
20
use App\Models\JobPosterQuestion;
21
use App\Models\Lookup\JobTerm;
22
use App\Models\Lookup\Province;
23
use App\Models\Lookup\SecurityClearance;
24
use App\Models\Lookup\LanguageRequirement;
25
use App\Models\Lookup\CitizenshipDeclaration;
26
use App\Models\Lookup\Department;
27
use App\Models\Lookup\SkillLevel;
28
use App\Models\Lookup\CriteriaType;
29
use App\Models\Lookup\VeteranStatus;
30
use App\Models\JobApplication;
31
use App\Models\Criteria;
32
use App\Models\Skill;
33
use App\Models\JobPosterKeyTask;
34
35
use App\Services\Validation\JobPosterValidator;
36
use Jenssegers\Date\Date;
37
38
class JobController extends Controller
39
{
40
    /**
41
     * Display a listing of JobPosters.
42
     *
43
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
44
     */
45
    public function index()
46
    {
47
        $now = Carbon::now();
48
49
        // Find published jobs that are currently open for applications.
50
        // Eager load required relationships: Department, Province, JobTerm.
51
        // Eager load the count of submitted applications, to prevent the relationship
52
        // from being actually loaded and firing off events.
53
        $jobs = JobPoster::where('open_date_time', '<=', $now)
54
            ->where('close_date_time', '>=', $now)
55
            ->where('published', true)
56
            ->with([
57
                'department',
58
                'province',
59
                'job_term',
60
            ])
61
            ->withCount([
62
                'submitted_applications',
63
            ])
64
            ->get();
65
        return view('applicant/job_index', [
66
            'job_index' => Lang::get('applicant/job_index'),
67
            'jobs' => $jobs
68
        ]);
69
    }
70
71
    /**
72
     * Display a listing of a manager's JobPosters.
73
     *
74
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
75
     */
76 1
    public function managerIndex()
77
    {
78 1
        $manager = Auth::user()->manager;
0 ignored issues
show
Bug introduced by
Accessing manager on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
79 1
        $jobs = JobPoster::where('manager_id', $manager->id)
80 1
            ->withCount('submitted_applications')
81 1
            ->get();
82
83 1
        return view('manager/job_index', [
84
            /*Localization Strings*/
85 1
            'jobs_l10n' => Lang::get('manager/job_index'),
86
87
            /* Data */
88 1
            'jobs' => $jobs,
89
        ]);
90
    }
91
92
    /**
93
     * Submit the Job Poster for review.
94
     *
95
     * @param \Illuminate\Http\Request $request   Incoming request object.
96
     * @param \App\Models\JobPoster    $jobPoster Job Poster object.
97
     *
98
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
99
     */
100 1
    public function submitForReview(Request $request, JobPoster $jobPoster)
101
    {
102
        // Update review request timestamp
103 1
        $jobPoster->review_requested_at = new Date();
104 1
        $jobPoster->save();
105
106
        // Refresh model instance with updated DB values.
107 1
        $jobPoster = JobPoster::withCount('submitted_applications')->where('id', $jobPoster->id)->first();
108
109
        // Send email
110 1
        $reviewer_email = config('mail.reviewer_email');
111 1
        if (isset($reviewer_email)) {
112 1
            Mail::to($reviewer_email)->send(new JobPosterReviewRequested($jobPoster, Auth::user()));
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facades\Auth::user() can also be of type null; however, parameter $manager of App\Mail\JobPosterReviewRequested::__construct() does only seem to accept App\Models\User, maybe add an additional type check? ( Ignorable by Annotation )

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

112
            Mail::to($reviewer_email)->send(new JobPosterReviewRequested($jobPoster, /** @scrutinizer ignore-type */ Auth::user()));
Loading history...
113
        } else {
114
            Log::error('The reviewer email environment variable is not set.');
115
        }
116
117 1
        return view('manager/job_index/job', [
118
            /*Localization Strings*/
119 1
            'jobs_l10n' => Lang::get('manager/job_index'),
120 1
            'job' => $jobPoster
121
        ]);
122
    }
123
124
    /**
125
     * Delete a draft Job Poster.
126
     *
127
     * @param \Illuminate\Http\Request $request   Incoming request object.
128
     * @param \App\Models\JobPoster    $jobPoster Job Poster object.
129
     *
130
     * @return void
131
     */
132
    public function destroy(Request $request, JobPoster $jobPoster) : void
133
    {
134
        $jobPoster->delete();
135
    }
136
137
    /**
138
     * Display the specified job poster.
139
     *
140
     * @param \Illuminate\Http\Request $request   Incoming request object.
141
     * @param \App\Models\JobPoster    $jobPoster Job Poster object.
142
     *
143
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
144
     */
145 5
    public function show(Request $request, JobPoster $jobPoster)
146
    {
147 5
        $jobPoster->load([
148 5
            'department',
149
            'criteria.skill.skill_type',
150
            'manager.team_culture',
151
            'manager.work_environment'
152
        ]);
153
154 5
        $user = Auth::user();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
155
156
        //TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model
157 5
        $workplacePhotos = [];
158 5
        foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) {
159
            $workplacePhotos[] = [
160
                'description' => $photoCaption->description,
161
                'url' => '/images/user.png'
162
            ];
163
        }
164
165
        //TODO: replace route('manager.show',manager.id) in templates with link using slug
166
167
        $criteria = [
168 5
            'essential' => $jobPoster->criteria->filter(
169
                function ($value, $key) {
170 2
                    return $value->criteria_type->name == 'essential';
171 5
                }
172
            ),
173 5
            'asset' => $jobPoster->criteria->filter(
174
                function ($value, $key) {
175 2
                    return $value->criteria_type->name == 'asset';
176 5
                }
177
            ),
178
        ];
179
180 5
        $jobLang = Lang::get('applicant/job_post');
181
182 5
        $applyButton = [];
183 5
        if (!$jobPoster->published && $this->authorize('update', $jobPoster)) {
184
            $applyButton = [
185 3
                'href' => route('manager.jobs.edit', $jobPoster->id),
186 3
                'title' => $jobLang['apply']['edit_link_title'],
187 3
                'text' => $jobLang['apply']['edit_link_label'],
188
            ];
189 2
        } elseif (Auth::check() && $jobPoster->isOpen()) {
190
            $applyButton = [
191 1
                'href' => route('job.application.edit.1', $jobPoster->id),
192 1
                'title' => $jobLang['apply']['apply_link_title'],
193 1
                'text' => $jobLang['apply']['apply_link_label'],
194
            ];
195 1
        } elseif (Auth::guest() && $jobPoster->isOpen()) {
196
            $applyButton = [
197 1
                'href' => route('job.application.edit.1', $jobPoster->id),
198 1
                'title' => $jobLang['apply']['login_link_title'],
199 1
                'text' => $jobLang['apply']['login_link_label'],
200
            ];
201
        } else {
202
            $applyButton = [
203
                'href' => null,
204
                'title' => null,
205
                'text' => $jobLang['apply']['job_closed_label'],
206
            ];
207
        }
208
209 5
        return view(
210 5
            'applicant/job_post',
211
            [
212 5
                'job_post' => $jobLang,
213 5
                'manager' => $jobPoster->manager,
214 5
                'manager_profile_photo_url' => '/images/user.png', //TODO get real photo
215 5
                'team_culture' => $jobPoster->manager->team_culture,
216 5
                'work_environment' => $jobPoster->manager->work_environment,
217 5
                'workplace_photos' => $workplacePhotos,
218 5
                'job' => $jobPoster,
219 5
                'criteria' => $criteria,
220 5
                'apply_button' => $applyButton,
221 5
                'skill_template' => Lang::get('common/skills'),
222
            ]
223
        );
224
    }
225
226
    /**
227
     * Display the form for creating a new Job Poster
228
     *
229
     * @param \Illuminate\Http\Request $request Incoming request object.
230
     *
231
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view
232
     */
233 1
    public function create(Request $request)
234
    {
235 1
        return $this->populateCreateView($request);
236
    }
237
238
    /**
239
     * Display the form for editing an existing Job Poster
240
     *
241
     * @param \Illuminate\Http\Request $request   Incoming request object.
242
     * @param \App\Models\JobPoster    $jobPoster Job Poster object.
243
     *
244
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view
245
     */
246 1
    public function edit(Request $request, JobPoster $jobPoster)
247
    {
248 1
        return $this->populateCreateView($request, $jobPoster);
249
    }
250
251
    /**
252
     * Get the manager from the request object and check if creating or editing
253
     *
254
     * @param \Illuminate\Http\Request $request   Incoming request object.
255
     * @param \App\Models\JobPoster    $jobPoster Optional Job Poster object.
256
     *
257
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view
258
     */
259 2
    public function populateCreateView(Request $request, JobPoster $jobPoster = null)
260
    {
261 2
        $manager = $request->user() ? $request->user()->manager : null;
262 2
        if (isset($jobPoster)) {
263 1
            $job = $jobPoster;
264 1
            $route = ['manager.jobs.update', $jobPoster];
265 1
            $jobHeading = 'manager/job_edit';
266
        } else {
267 1
            $job = [];
268 1
            $defaultQuestions = $this->populateDefaultQuestions();
269 1
            if (!empty($defaultQuestions)) {
270 1
                $job['job_poster_questions'] = $defaultQuestions;
271
            }
272 1
            $route = ['manager.jobs.store'];
273 1
            $jobHeading = 'manager/job_create';
274
        }
275
276 2
        $skillLangs = Lang::get('common/skills');
277
278 2
        $softSkills = Skill::whereHas(
279 2
            'skill_type',
280
            function ($query) : void {
281 2
                $query->where('name', '=', 'soft');
282 2
            }
283 2
        )->get()
284 2
            ->mapWithKeys(
285
                function ($skill) {
286
                    return [
287 2
                        $skill->id => $skill->name
288
                    ];
289 2
                }
290
            )
291 2
            ->all();
292
293 2
        $hardSkills = Skill::whereHas(
294 2
            'skill_type',
295
            function ($query) : void {
296 2
                $query->where('name', '=', 'hard');
297 2
            }
298 2
        )->get()
299 2
            ->mapWithKeys(
300
                function ($skill) {
301
                    return [
302 2
                        $skill->id => $skill->name
303
                    ];
304 2
                }
305
            )
306 2
            ->all();
307
308 2
        asort($softSkills, SORT_LOCALE_STRING);
309 2
        asort($hardSkills, SORT_LOCALE_STRING);
310
311
        $skills = [
312
            'essential' => [
313 2
                'hard' => $hardSkills,
314 2
                'soft' => $softSkills
315
            ],
316
            'asset' => [
317 2
                'hard' => $hardSkills,
318 2
                'soft' => $softSkills
319
            ]
320
        ];
321
322 2
        $skillLevelCollection = SkillLevel::all();
323
324 2
        $skillLevels = array();
325
326 2
        $skillLevels['hard'] = $skillLevelCollection->mapWithKeys(
327
            function ($skillLevel) use ($skillLangs) {
328 2
                return [$skillLevel->id => $skillLangs['skill_levels']['hard'][$skillLevel->name]];
329 2
            }
330 2
        )->all();
331
332 2
        $skillLevels['soft'] = $skillLevelCollection->mapWithKeys(
333
            function ($skillLevel) use ($skillLangs) {
334 2
                return [$skillLevel->id => $skillLangs['skill_levels']['soft'][$skillLevel->name]];
335 2
            }
336 2
        )->all();
337
338 2
        return view(
339 2
            'manager/job_create',
340
            [
341
                /*Localization Strings*/
342 2
                'job_l10n' => Lang::get('manager/job_create'),
343
344
                /* Data */
345 2
                'job' => Lang::get($jobHeading),
346 2
                'manager' => $manager,
347 2
                'provinces' => Province::all(),
348 2
                'departments' => Department::all(),
349 2
                'language_requirments' => LanguageRequirement::all(),
350 2
                'security_clearances' => SecurityClearance::all(),
351 2
                'job' => $job,
352 2
                'form_action_url' => route(/** @scrutinizer ignore-type */ ...$route), // phpcs:ignore
0 ignored issues
show
Bug introduced by
$route is expanded, but the parameter $name of route() does not expect variable arguments. ( Ignorable by Annotation )

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

352
                'form_action_url' => route(/** @scrutinizer ignore-type */ /** @scrutinizer ignore-type */ ...$route), // phpcs:ignore
Loading history...
353 2
                'skills' => $skills,
354 2
                'skill_levels' => $skillLevels,
355 2
                'skill_template' => $skillLangs,
356
            ]
357
        );
358
    }
359
360
    /**
361
     * Create a new resource in storage
362
     *
363
     * @param \Illuminate\Http\Request $request   Incoming request object.
364
     * @param \App\Models\JobPoster    $jobPoster Optional Job Poster object.
365
     *
366
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse A redirect to the Job Index
367
     */
368 3
    public function store(Request $request, JobPoster $jobPoster = null)
369
    {
370
        // Don't allow edits for published Job Posters
371
        // Also check auth while we're at it
372 3
        if (isset($jobPoster)) {
373
            $this->authorize('update', $jobPoster);
374
            JobPosterValidator::validateUnpublished($jobPoster);
375
        } else {
376 3
            $this->authorize('create', JobPoster::class);
377
        }
378
379 3
        $input = $request->input();
380
381 3
        $job = (isset($jobPoster) ? $jobPoster : new JobPoster());
382
383 3
        $job->manager_id = $request->user()->manager->id;
384
385 3
        $this->fillAndSaveJobPoster($input, $job);
386
387 3
        $this->fillAndSaveJobPosterTasks($input, $job, isset($jobPoster));
388
389 3
        $this->fillAndSaveJobPosterQuestions($input, $job, isset($jobPoster));
390
391 3
        $this->fillAndSaveJobPosterCriteria($input, $job, isset($jobPoster));
392
393 3
        return redirect(route('manager.jobs.show', $job->id));
394
    }
395
396
    /**
397
     * Fill Job Poster model's properties and save
398
     *
399
     * @param mixed[]               $input     Field values.
400
     * @param \App\Models\JobPoster $jobPoster Job Poster object.
401
     *
402
     * @return void
403
     */
404 3
    protected function fillAndSaveJobPoster(array $input, JobPoster $jobPoster) : void
405
    {
406 3
        $closeDate = new Date($input['close_date']);
407 3
        $openDate = new Date($input['open_date']);
408 3
        $startDate = new Date($input['start_date']);
409
410 3
        $jobPoster->fill(
411
            [
412 3
                'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id,
413 3
                'term_qty' => $input['term_qty'],
414 3
                'open_date_time' => pstDayStartToUtcTime($openDate->year, $openDate->month, $openDate->day),
415 3
                'close_date_time' => pstDayEndToUtcTime($closeDate->year, $closeDate->month, $closeDate->day),
416 3
                'start_date_time' => pstDayStartToUtcTime($startDate->year, $startDate->month, $startDate->day),
417 3
                'department_id' => $input['department'],
418 3
                'province_id' => $input['province'],
419 3
                'salary_min' => $input['salary_min'],
420 3
                'salary_max' => $input['salary_max'],
421 3
                'noc' => $input['noc'],
422 3
                'classification' => $input['classification'],
423 3
                'security_clearance_id' => $input['security_clearance'],
424 3
                'language_requirement_id' => $input['language_requirement'],
425 3
                'remote_work_allowed' => (isset($input['remote_work_allowed']) ? $input['remote_work_allowed'] : false),
426
                'en' => [
427 3
                    'city' => $input['city'],
428 3
                    'title' => $input['title']['en'],
429 3
                    'impact' => $input['impact']['en'],
430 3
                    'branch' => $input['branch']['en'],
431 3
                    'division' => $input['division']['en'],
432 3
                    'education' => $input['education']['en'],
433
                ],
434
                'fr' => [
435 3
                    'city' => $input['city'],
436 3
                    'title' => $input['title']['fr'],
437 3
                    'impact' => $input['impact']['fr'],
438 3
                    'branch' => $input['branch']['fr'],
439 3
                    'division' => $input['division']['fr'],
440 3
                    'education' => $input['education']['fr'],
441
                ],
442
            ]
443
        );
444 3
        $jobPoster->save();
445 3
    }
446
447
    /**
448
     * Fill Job Poster's tasks and save
449
     *
450
     * @param mixed[]               $input     Field values.
451
     * @param \App\Models\JobPoster $jobPoster Job Poster object.
452
     * @param boolean               $replace   Remove existing relationships.
453
     *
454
     * @return void
455
     */
456 3
    protected function fillAndSaveJobPosterTasks(array $input, JobPoster $jobPoster, bool $replace) : void
457
    {
458 3
        if ($replace) {
459
            $jobPoster->job_poster_key_tasks()->delete();
460
        }
461
462 3
        if (!array_key_exists('task', $input) || !is_array($input['task'])) {
463 3
            return;
464
        }
465
466
        foreach ($input['task'] as $task) {
467
            $jobPosterTask = new JobPosterKeyTask();
468
            $jobPosterTask->job_poster_id = $jobPoster->id;
469
            $jobPosterTask->fill(
470
                [
471
                    'en' => [
472
                        'description' => $task['en']
473
                    ],
474
                    'fr' => [
475
                        'description' => $task['fr']
476
                    ]
477
                ]
478
            );
479
            $jobPosterTask->save();
480
        }
481
    }
482
483
    /**
484
     * Fill Job Poster's questions and save
485
     *
486
     * @param mixed[]               $input     Field values.
487
     * @param \App\Models\JobPoster $jobPoster Job Poster object.
488
     * @param boolean               $replace   Remove existing relationships.
489
     *
490
     * @return void
491
     */
492 3
    protected function fillAndSaveJobPosterQuestions(array $input, JobPoster $jobPoster, bool $replace) : void
493
    {
494 3
        if ($replace) {
495
            $jobPoster->job_poster_questions()->delete();
496
        }
497
498 3
        if (!array_key_exists('question', $input) || !is_array($input['question'])) {
499 3
            return;
500
        }
501
502
        foreach ($input['question'] as $question) {
503
            $jobQuestion = new JobPosterQuestion();
504
            $jobQuestion->job_poster_id = $jobPoster->id;
505
            $jobQuestion->fill(
506
                [
507
                    'en' => [
508
                        'question' => $question['question']['en'],
509
                        'description' => $question['description']['en']
510
                    ],
511
                    'fr' => [
512
                        'question' => $question['question']['fr'],
513
                        'description' => $question['description']['fr']
514
                    ]
515
                ]
516
            );
517
            $jobQuestion->save();
518
        }
519
    }
520
521
    /**
522
     * Fill Job Poster's criteria and save
523
     *
524
     * @param mixed[]               $input     Field values.
525
     * @param \App\Models\JobPoster $jobPoster Job Poster object.
526
     * @param boolean               $replace   Remove existing relationships.
527
     *
528
     * @return void
529
     */
530 3
    protected function fillAndSaveJobPosterCriteria(array $input, JobPoster $jobPoster, bool $replace) : void
531
    {
532 3
        if ($replace) {
533
            $jobPoster->criteria()->delete();
534
        }
535
536 3
        if (!array_key_exists('criteria', $input) || !is_array($input['criteria'])) {
537 3
            return;
538
        }
539
540
        $criteria = $input['criteria'];
541
542
        $combinedCriteria = [];
543
        if (isset($criteria['old'])) {
544
            $combinedCriteria = array_replace_recursive($combinedCriteria, $criteria['old']);
545
        }
546
        if (isset($criteria['new'])) {
547
            $combinedCriteria = array_replace_recursive($combinedCriteria, $criteria['new']);
548
        }
549
550
        if (! empty($combinedCriteria)) {
551
            foreach ($combinedCriteria as $criteriaType => $criteriaTypeInput) {
552
                foreach ($criteriaTypeInput as $skillType => $skillTypeInput) {
553
                    foreach ($skillTypeInput as $criteriaInput) {
554
                        $criteria = new Criteria();
555
                        $criteria->job_poster_id = $jobPoster->id;
556
                        $criteria->fill(
557
                            [
558
                                'criteria_type_id' => CriteriaType::where('name', $criteriaType)->firstOrFail()->id,
559
                                'skill_id' => $criteriaInput['skill_id'],
560
                                'skill_level_id' => $criteriaInput['skill_level_id'],
561
                                'en' => [
562
                                    'description' => $criteriaInput['description']['en'],
563
                                ],
564
                                'fr' => [
565
                                    'description' => $criteriaInput['description']['fr'],
566
                                ],
567
                            ]
568
                        );
569
                        $criteria->save();
570
                    }
571
                }
572
            }
573
        }
574
    }
575
576
    /**
577
     * Get the localized default questions and add them to an array.
578
     *
579
     * @return mixed[]|void
580
     */
581 1
    protected function populateDefaultQuestions()
582
    {
583
        $defaultQuestions = [
584 1
            'en' => array_values(Lang::get('manager/job_create', [], 'en')['questions']),
585 1
            'fr' => array_values(Lang::get('manager/job_create', [], 'fr')['questions']),
586
        ];
587
588 1
        if (count($defaultQuestions['en']) !== count($defaultQuestions['fr'])) {
589
            Log::warning('There must be the same number of French and English default questions for a Job Poster.');
590
            return;
591
        }
592
593 1
        $jobQuestions = [];
594
595 1
        for ($i = 0; $i < count($defaultQuestions['en']); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
596 1
            $jobQuestion = new JobPosterQuestion();
597 1
            $jobQuestion->fill(
598
                [
599
                    'en' => [
600 1
                        'question' => $defaultQuestions['en'][$i],
601
                    ],
602
                    'fr' => [
603 1
                        'question' => $defaultQuestions['fr'][$i],
604
                    ]
605
                ]
606
            );
607
            // Workaround for Default Questions with empty descriptions
608
            // throwing an error during save.
609
            // The id isn't actually used during the fillAndSaveJobPosterQuestions
610
            // method call.
611 1
            $jobQuestion->id = $i + 1;
612 1
            $jobQuestions[] = $jobQuestion;
613
        }
614
615 1
        return $jobQuestions;
616
    }
617
}
618