Passed
Push — dev ( 17cc34...596d5a )
by Chris
03:59 queued 12s
created

JobPosterQuestionInitializer::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 10
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
namespace App\Listeners;
4
5
use App\Events\JobSaved;
6
use App\Models\Lookup\JobPosterStatus;
7
use App\Services\JobPosterDefaultQuestions;
8
9
class JobPosterQuestionInitializer
10
{
11
    /**
12
     * When Job enters approved state, where an Admin must to a final look over,
13
     * ensure default questions are added.
14
     *
15
     * @param  JobSaved  $event
16
     * @return void
17
     */
18
    public function handle(JobSaved $event)
19
    {
20
        $job = $event->job;
21
22
        if ($job->isDirty('job_poster_status_id')) {
23
            $toStatusId = $job->job_poster_status_id;
24
            $approvedId = JobPosterStatus::where('key', 'approved')->first()->id;
25
            if ($toStatusId == $approvedId) {
26
                $defaultQuestionManager = new JobPosterDefaultQuestions();
27
                $defaultQuestionManager->initializeQuestionsIfEmpty($job);
28
            }
29
        }
30
    }
31
}
32