Completed
Push — master ( 3ab6ed...db6658 )
by Eric
03:23
created

helpers.php ➔ create_admin_user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use App\User;
4
use Spatie\Permission\Models\Permission;
5
use Spatie\Permission\Models\Role;
6
7
if (!function_exists('assignPermission')) {
8
    function assignPermission($role, $permission) {
9
        if (! $role->hasPermissionTo($permission)) {
10
            $role->givePermissionTo($permission);
11
        }
12
    }
13
}
14
15
if (!function_exists('initialize_articles_permissions')) {
16
    function initialize_articles_permissions()
17
    {
18
        Permission::firstOrCreate(['name' => 'list-articles']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
19
        Permission::firstOrCreate(['name' => 'show-article']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
20
        Permission::firstOrCreate(['name' => 'store-article']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
21
        Permission::firstOrCreate(['name' => 'update-article']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
22
        Permission::firstOrCreate(['name' => 'destroy-article']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
23
24
        $role = Role::firstOrCreate(['name' => 'articles-manager']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Role. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
25
26
        assignPermission($role,'list-articles');
27
        assignPermission($role,'show-article');
28
        assignPermission($role,'store-article');
29
        assignPermission($role,'update-article');
30
        assignPermission($role,'destroy-article');
31
32
33
        Permission::firstOrCreate(['name' => 'list-users']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
        Permission::firstOrCreate(['name' => 'show-user']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
        Permission::firstOrCreate(['name' => 'store-user']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
        Permission::firstOrCreate(['name' => 'update-user']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37
        Permission::firstOrCreate(['name' => 'destroy-user']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Permission. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
38
39
        $role = Role::firstOrCreate(['name' => 'users-manager']);
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on Spatie\Permission\Models\Role. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
41
        assignPermission($role,'list-users');
42
        assignPermission($role,'show-user');
43
        assignPermission($role,'store-user');
44
        assignPermission($role,'update-user');
45
        assignPermission($role,'destroy-user');
46
    }
47
}
48
49
if (!function_exists('create_admin_user')) {
50
    function create_admin_user()
51
    {
52
        factory(User::class)->create([
53
            'name'     => env('ARTICLES_USER_NAME', 'Eric Garcia Reverter'),
54
            'email'    => env('ARTICLES_USER_EMAIL', '[email protected]'),
55
            'password' => bcrypt(env('ARTICLES_USER_PASSWORD')),
56
        ]);
57
    }
58
}
59
60
if (!function_exists('first_user_as_articles_manager')) {
61
    function first_user_as_articles_manager()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
62
    {
63
        User::all()->first()->assignRole('articles-manager');
64
        User::all()->first()->assignRole('users-manager');
65
    }
66
}
67