Completed
Pull Request — dev (#297)
by Tristan
11:17
created

WorkEnvironmentSeeder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
dl 0
loc 29
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 2
A __construct() 0 2 1
1
<?php
2
3
use Illuminate\Database\Seeder;
4
use App\Models\Manager;
5
use App\Models\WorkEnvironment;
6
use App\Models\Lookup\Frequency;
7
8
class WorkEnvironmentSeeder extends Seeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    protected $faker;
11
12
    public function __construct(Faker\Generator $faker) {
13
        $this->faker = $faker;
14
    }
15
16
    /**
17
     * Run the Users table seeds.
18
     *
19
     * @return void
20
     */
21
    public function run()
22
    {
23
        $faker = $this->faker;
0 ignored issues
show
Unused Code introduced by
The assignment to $faker is dead and can be removed.
Loading history...
24
25
        //Find all managers that don't have a work environment yet
26
        $managers = Manager::doesntHave('work_environment')->get();
27
28
        foreach($managers as $manager) {
29
            $workEnvironment = new WorkEnvironment();
30
            $workEnvironment->manager_id = $manager->id;
31
            $workEnvironment->fill([
32
                'remote_work_allowed' => $this->faker->boolean(),
33
                'telework_allowed_frequency_id' => Frequency::inRandomOrder()->first()->id,
34
                'flexible_hours_frequency_id' => Frequency::inRandomOrder()->first()->id,
35
            ]);
36
            $workEnvironment->save();
37
        }
38
    }
39
}
40