Passed
Push — dev5 ( b08d9a...c43caf )
by Ron
04:08
created

FileLinksSeeder::run()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 8.3272
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use App\Files;
4
use App\FileLinks;
5
use App\FileLinkFiles;
6
//use Faker\Generator as Faker;
7
use Illuminate\Database\Seeder;
8
9
class FileLinksSeeder extends Seeder
10
{
11
    /**
12
     * Run the database seeds.
13
     *
14
     * @return void
15
     */
16
    public function run()
17
    {
18
//        $faker = new Faker;
19
        $faker = Faker\Factory::create('en_US');
20
        
21
        //  Create random file links for different users
22
        factory(FileLinks::class, 5)->create([
23
            'user_id' => 1,
24
            'note'    =>$faker->text
25
        ]);
26
        
27
        factory(FileLinks::class, 2)->create([
28
            'user_id' => 2
29
        ]);
30
        
31
        factory(FileLinks::class, 8)->create([
32
            'user_id' => 3
33
        ]);
34
        
35
        factory(FileLinks::class, 2)->create([
36
            'user_id' => 1,
37
            'cust_id' => 2387
38
        ]);
39
        
40
        //  Add files to the first file link
41
        $fileID = Files::create([
42
            'file_name' => 'file1.png',
43
            'file_link' => 'random/path'
44
        ]);
45
        FileLinkFiles::create([
46
            'link_id'  => 1,
47
            'file_id'  => $fileID->file_id,
48
            'user_id'  => 1,
49
            'added_by' => null,
50
            'upload'   => 0
51
        ]);
52
        
53
        $fileID = Files::create([
54
            'file_name' => 'file2.png',
55
            'file_link' => 'random/path'
56
        ]);
57
        FileLinkFiles::create([
58
            'link_id'  => 1,
59
            'file_id'  => $fileID->file_id,
60
            'user_id'  => 1,
61
            'added_by' => null,
62
            'upload'   => 0
63
        ]);
64
        
65
        $fileID = Files::create([
66
            'file_name' => 'file3.png',
67
            'file_link' => 'random/path'
68
        ]);
69
        FileLinkFiles::create([
70
            'link_id'  => 1,
71
            'file_id'  => $fileID->file_id,
72
            'user_id'  => 1,
73
            'added_by' => null,
74
            'upload'   => 0
75
        ]);
76
        
77
        $fileID = Files::create([
78
            'file_name' => 'file4.png',
79
            'file_link' => 'random/path'
80
        ]);
81
        FileLinkFiles::create([
82
            'link_id'  => 1,
83
            'file_id'  => $fileID->file_id,
84
            'user_id'  => null,
85
            'added_by' => $faker->name(),
86
            'upload'   => 1
87
        ]);
88
        
89
        $fileID = Files::create([
90
            'file_name' => 'file5.png',
91
            'file_link' => 'random/path'
92
        ]);
93
        FileLinkFiles::create([
94
            'link_id'  => 1,
95
            'file_id'  => $fileID->file_id,
96
            'user_id'  => null,
97
            'added_by' => $faker->name(),
98
            'upload'   => 1
99
        ]);
100
    }
101
}
102