Completed
Push — master ( 06c314...612aa7 )
by Scott
02:14
created

DevSeeder::seedProducts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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