Passed
Push — feature/response-home-message ( 8fa134...20069e )
by Tristan
03:51
created

StrategicResponseSeeder::run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 50
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 50
rs 9.424
cc 3
nc 4
nop 0
1
<?php
2
3
use App\Models\Applicant;
4
use App\Models\HrAdvisor;
5
use App\Models\JobApplication;
6
use App\Models\JobPoster;
7
use App\Models\Manager;
8
use App\Models\User;
9
use Illuminate\Database\Seeder;
10
11
class StrategicResponseSeeder extends Seeder // phpcs:ignore
12
{
13
14
    /**
15
     * Manager for Strategic Talent Response jobs.
16
     *
17
     * @var string
18
     */
19
    protected $strManagerEmail = '[email protected]';
20
21
    /**
22
     * HR Advisor for Strategic Talent Response jobs.
23
     *
24
     * @var string
25
     */
26
    protected $strHrEmail = '[email protected]';
27
28
    /**
29
     * Run the database seeds.
30
     *
31
     * @return void
32
     */
33
    public function run(): void
34
    {
35
        $str_department_id = config('app.strategic_response_department_id');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

35
        $str_department_id = /** @scrutinizer ignore-call */ config('app.strategic_response_department_id');
Loading history...
36
37
        DB::table('departments')->updateOrInsert(
38
            ['id' => $str_department_id],
39
            [
40
                'name' => json_encode([
41
                    'en' => 'Strategic Talent Response',
42
                    'fr' => 'Réponse stratégique de talents'
43
                ]),
44
                'impact' => json_encode([
45
                    'en' => 'Impact text placeholder',
46
                    'fr' => 'Impact text placeholder'
47
                ]),
48
                'preference' => json_encode([
49
                    'en' => 'You must currently be an employee of the Government of Canada with valid security clearance to apply to this opportunity.',
50
                    'fr' => 'Vous devez actuellement être un employé du gouvernement du Canada avec une habilitation de sécurité valide pour postuler à cette opportunité.'
51
                ]),
52
            ]
53
        );
54
55
        $hrUser = User::where('email', $this->strHrEmail)->first();
56
        if ($hrUser === null) {
57
            $hrUser = factory(User::class)->state('hr_advisor')->create([
0 ignored issues
show
Bug introduced by
The function factory was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

57
            $hrUser = /** @scrutinizer ignore-call */ factory(User::class)->state('hr_advisor')->create([
Loading history...
58
                'email' => $this->strHrEmail,
59
                'department_id' => $str_department_id,
60
            ]);
61
            $hrUser->hr_advisor()->save(factory(HrAdvisor::class)->create([
62
                'user_id' => $hrUser->id,
63
            ]));
64
        }
65
66
        $managerUser = User::where('email', $this->strManagerEmail)->first();
67
        // Create the test manager if it does not exist yet.
68
        if ($managerUser === null) {
69
            $managerUser = factory(User::class)->state('upgradedManager')->create([
70
                'email' => $this->strManagerEmail,
71
                'department_id' => $str_department_id,
72
            ]);
73
            $managerUser->manager()->save(factory(Manager::class)->create([
74
                'user_id' => $managerUser->id,
75
            ]));
76
        }
77
78
        factory(JobPoster::class, 100)->states(['live', 'strategic_response'])->create([
79
            'manager_id' => $managerUser->manager->id
80
        ])->each(function ($job): void {
81
            $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([
0 ignored issues
show
Bug introduced by
The function factory was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

81
            $job->job_applications()->saveMany(/** @scrutinizer ignore-call */ factory(JobApplication::class, 5))->create([
Loading history...
82
                'job_poster_id' => $job->id
83
            ]);
84
        });
85
    }
86
}
87