Completed
Push — master ( a4eeb5...f9f04d )
by Scott
02:46
created

DevSeeder::seedDiscounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php namespace Bedard\Shop\Updates;
2
3
use Bedard\Shop\Models\Category;
4
use Bedard\Shop\Models\Discount;
5
use Bedard\Shop\Models\Product;
6
use Bedard\Shop\Tests\Factory;
7
use Carbon\Carbon;
8
use October\Rain\Database\Updates\Seeder;
9
10
class DevSeeder extends Seeder
11
{
12
    public function run()
13
    {
14
        // only run the seeder in development
15
        if (app()->env !== 'dev') {
16
            return;
17
        }
18
19
        $this->seedCategories();
20
        $this->seedProducts(10);
21
        $this->seedDiscounts();
22
    }
23
24
    protected function seedCategories()
25
    {
26
        $parent1 = Factory::create(new Category, ['name' => 'Parent 1', 'slug' => 'parent-1']);
27
        $parent2 = Factory::create(new Category, ['name' => 'Parent 2', 'slug' => 'parent-2']);
28
        Factory::create(new Category, ['name' => 'Child 1', 'slug' => 'child-1', 'parent_id' => $parent1->id]);
29
        Factory::create(new Category, ['name' => 'Child 2', 'slug' => 'child-2', 'parent_id' => $parent2->id]);
30
    }
31
32
    protected function seedProducts($count)
33
    {
34
        $categories = Category::count();
35
36
        for ($i = 0; $i < $count; $i++) {
37
            $product = Factory::create(new Product, ['name' => 'Product '.$i, 'slug' => 'product-'.$i]);
38
            $product->categories()->sync([rand(1, $categories)]);
39
        }
40
41
        Product::syncAllInheritedCategories();
42
    }
43
44
    protected function seedDiscounts()
45
    {
46
        $expired = Factory::create(new Discount, [
0 ignored issues
show
Unused Code introduced by
$expired is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
            'name' => 'Expired',
48
            'end_at' => Carbon::yesterday(),
49
        ]);
50
51
        $active = Factory::create(new Discount, [
0 ignored issues
show
Unused Code introduced by
$active is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
52
            'name' => 'Active',
53
            'start_at' => Carbon::yesterday(),
54
            'end_at' => Carbon::tomorrow(),
55
        ]);
56
57
        $upcoming = Factory::create(new Discount, [
0 ignored issues
show
Unused Code introduced by
$upcoming is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
            'name' => 'Upcoming',
59
            'start_at' => Carbon::tomorrow(),
60
        ]);
61
    }
62
}
63