| Total Complexity | 7 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class JobPosterDefaultQuestions |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Get the localized default questions and add them to an array. |
||
| 14 | * |
||
| 15 | * @return mixed[]|void |
||
| 16 | */ |
||
| 17 | public function createDefaultQuestions(bool $isStrategicResponseJob = false) |
||
| 18 | { |
||
| 19 | |||
| 20 | $question_key = $isStrategicResponseJob |
||
| 21 | ? 'strategic_response_questions' |
||
| 22 | : 'questions'; |
||
| 23 | |||
| 24 | $defaultQuestions = [ |
||
| 25 | 'en' => array_values(Lang::get('manager/job_create', [], 'en')[$question_key]), |
||
| 26 | 'fr' => array_values(Lang::get('manager/job_create', [], 'fr')[$question_key]), |
||
| 27 | ]; |
||
| 28 | |||
| 29 | if (count($defaultQuestions['en']) !== count($defaultQuestions['fr'])) { |
||
| 30 | Log::warning('There must be the same number of French and English default questions for a Job Poster.'); |
||
| 31 | return; |
||
| 32 | } |
||
| 33 | |||
| 34 | $jobQuestions = []; |
||
| 35 | |||
| 36 | for ($i = 0; $i < count($defaultQuestions['en']); $i++) { |
||
|
|
|||
| 37 | $jobQuestion = new JobPosterQuestion(); |
||
| 38 | $jobQuestion->fill( |
||
| 39 | [ |
||
| 40 | 'question' => [ |
||
| 41 | 'en' => $defaultQuestions['en'][$i], |
||
| 42 | 'fr' => $defaultQuestions['fr'][$i], |
||
| 43 | ] |
||
| 44 | ] |
||
| 45 | ); |
||
| 46 | $jobQuestions[] = $jobQuestion; |
||
| 47 | } |
||
| 48 | |||
| 49 | return $jobQuestions; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function initializeQuestionsIfEmpty(JobPoster $jobPoster) |
||
| 58 | } |
||
| 59 | } |
||
| 61 |
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: