Passed
Push — dev5 ( 236dfc...16c2ad )
by Ron
07:50
created

FileLinksSeeder::run()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 83
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 56
nc 1
nop 0
dl 0
loc 83
rs 8.9599
c 1
b 0
f 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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Files. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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,
1 ignored issue
show
Bug introduced by
The property file_id does not seem to exist on App\Files. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
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