DefaultPermissionsTableSeeder::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 51
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 51
rs 9.44
c 0
b 0
f 0
cc 3
nc 3
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
namespace jeremykenedy\LaravelRoles\Database\Seeders;
4
5
use Illuminate\Database\Seeder;
6
7
class DefaultPermissionsTableSeeder extends Seeder
8
{
9
    /**
10
     * Run the database seeds.
11
     *
12
     * @return void
13
     */
14
    public function run()
15
    {
16
        /*
17
         * Permission Types
18
         *
19
         */
20
        $Permissionitems = [
21
            [
22
                'name'        => 'Can View Users',
23
                'slug'        => 'view.users',
24
                'description' => 'Can view users',
25
                'model'       => 'Permission',
26
            ],
27
            [
28
                'name'        => 'Can Create Users',
29
                'slug'        => 'create.users',
30
                'description' => 'Can create new users',
31
                'model'       => 'Permission',
32
            ],
33
            [
34
                'name'        => 'Can Edit Users',
35
                'slug'        => 'edit.users',
36
                'description' => 'Can edit users',
37
                'model'       => 'Permission',
38
            ],
39
            [
40
                'name'        => 'Can Delete Users',
41
                'slug'        => 'delete.users',
42
                'description' => 'Can delete users',
43
                'model'       => 'Permission',
44
            ],
45
        ];
46
47
        /*
48
         * Add Permission Items
49
         *
50
         */
51
        $this->command->getOutput()->writeln('<info>Seeding:</info> DefaultPermissionitemsTableSeeder');
52
        foreach ($Permissionitems as $Permissionitem) {
53
            $newPermissionitem = config('roles.models.permission')::where('slug', '=', $Permissionitem['slug'])
54
                ->first();
55
            if ($newPermissionitem === null) {
56
                $newPermissionitem = config('roles.models.permission')::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $newPermissionitem is dead and can be removed.
Loading history...
57
                    'name'          => $Permissionitem['name'],
58
                    'slug'          => $Permissionitem['slug'],
59
                    'description'   => $Permissionitem['description'],
60
                    'model'         => $Permissionitem['model'],
61
                ]);
62
                $this->command->getOutput()->writeln(
63
                    '<info>Seeding:</info> DefaultPermissionitemsTableSeeder - Permission:'
64
                    .$Permissionitem['slug']
65
                );
66
            }
67
        }
68
    }
69
}
70