initialize_task_permissions()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 21
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 31
rs 8.8571
1
<?php
2
3
use App\User;
4
use Spatie\Permission\Models\Permission;
5
use Spatie\Permission\Models\Role;
6
7
if (!function_exists('initialize_task_permission')) {
8
    function initialize_task_permissions()
9
    {
10
        Permission::firstOrCreate(['name' => 'list-tasks']);
11
        Permission::firstOrCreate(['name' => 'show-tasks']);
12
        Permission::firstOrCreate(['name' => 'store-tasks']);
13
        Permission::firstOrCreate(['name' => 'complete-tasks']);
14
        Permission::firstOrCreate(['name' => 'update-name-tasks']);
15
        Permission::firstOrCreate(['name' => 'destroy-tasks']);
16
17
        Permission::firstOrCreate(['name' => 'store-completed-tasks']);
18
        Permission::firstOrCreate(['name' => 'destroy-completed-tasks']);
19
20
        Permission::firstOrCreate(['name' => 'update-description-tasks']);
21
22
        Permission::firstOrCreate(['name' => 'update-user_id-tasks']);
23
24
        $role = Role::firstOrCreate(['name' => 'task-manager']);
25
26
        $role->givePermissionTo('list-tasks');
27
        $role->givePermissionTo('show-tasks');
28
        $role->givePermissionTo('store-tasks');
29
        $role->givePermissionTo('complete-tasks');
30
        $role->givePermissionTo('update-name-tasks');
31
        $role->givePermissionTo('destroy-tasks');
32
33
        $role->givePermissionTo('store-completed-tasks');
34
        $role->givePermissionTo('destroy-completed-tasks');
35
36
        $role->givePermissionTo('update-description-tasks');
37
38
        $role->givePermissionTo('update-user_id-tasks');
39
    }
40
}
41
42
if (!function_exists('create_user')) {
43
    function create_user()
44
    {
45
        factory(User::class)->create([
46
            'name'     => env('TASKS_USER_NAME', 'Eric Garcia Reverter'),
47
            'email'    => env('TASKS_USER_EMAIL', '[email protected]'),
48
            'password' => bcrypt(env('TASKS_USER_PASSWORD')),
0 ignored issues
show
Bug introduced by
It seems like env('TASKS_USER_PASSWORD') can also be of type array; however, parameter $value of bcrypt() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            'password' => bcrypt(/** @scrutinizer ignore-type */ env('TASKS_USER_PASSWORD')),
Loading history...
49
        ]);
50
51
        factory(User::class)->create([
52
            'name'     => env('TASKS_USER_NAME_2', 'Sergi Tur Badenas'),
53
            'email'    => env('TASKS_USER_EMAIL_2', '[email protected]'),
54
            'password' => bcrypt(env('TASKS_USER_PASSWORD_2')),
55
        ]);
56
    }
57
}
58
59
if (!function_exists('first_user_as_task_manager')) {
60
    function first_user_as_task_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...
61
    {
62
        User::all()->first()->assignRole('task-manager');
63
        User::findOrFail('2')->assignRole('task-manager');
64
    }
65
}
66