Passed
Push — master ( 07420f...521211 )
by Quim González
04:06
created

first_user_as_task_manager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
use App\User;
5
use Spatie\Permission\Models\Permission;
6
use Spatie\Permission\Models\Role;
7
8
//si no esta declarada (function_exists('nom_funcio')) la declaro
9
10
if(! function_exists('initialize_task_permissions')){
11
12
    function initialize_task_permissions(){
13
        //Permission::create(['name'=>'list-tasks']);
14
        //Crea només si no existeix
15
        Permission::firstOrCreate(['name'=>'list-tasks']);
16
        Permission::firstOrCreate(['name'=>'show-tasks']);
17
        Permission::firstOrCreate(['name'=>'store-tasks']);
18
        Permission::firstOrCreate(['name'=>'update-tasks']);
19
        Permission::firstOrCreate(['name'=>'destroy-tasks']);
20
21
        $role = Role::firstOrCreate(['name'=>'task-manager']);
22
        $role -> givePermissionTo('list-tasks');
23
        $role -> givePermissionTo('show-tasks');
24
        $role -> givePermissionTo('store-tasks');
25
        $role -> givePermissionTo('update-tasks');
26
        $role -> givePermissionTo('destroy-tasks');
27
    }
28
}
29
30
if(! function_exists('create_user')){
31
32
    function create_user(){
33
        factory(User::class)->create([
34
            'name' => env('TASKS_USER_NAME','Quim González Colat'),
35
            'email' => env('TASKS_USER_EMAIL','[email protected]'),
36
            'password' => bcrypt(env('TASKS_USER_PASSWORD'))
37
        ]);
38
    }
39
}
40
41
if(! function_exists('first_user_as_task_manager')){
42
43
    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...
44
        User::all()->first()->assignRole('task-manager');
45
    }
46
47
}