|
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, [ |
|
|
|
|
|
|
47
|
|
|
'name' => 'Expired', |
|
48
|
|
|
'end_at' => Carbon::yesterday(), |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
|
|
$active = Factory::create(new Discount, [ |
|
|
|
|
|
|
52
|
|
|
'name' => 'Active', |
|
53
|
|
|
'start_at' => Carbon::yesterday(), |
|
54
|
|
|
'end_at' => Carbon::tomorrow(), |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$upcoming = Factory::create(new Discount, [ |
|
|
|
|
|
|
58
|
|
|
'name' => 'Upcoming', |
|
59
|
|
|
'start_at' => Carbon::tomorrow(), |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.