Completed
Push — master ( e93f60...2f787f )
by Mahmoud
08:56 queued 02:41
created

UserPolicy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 5 2
A delete() 0 5 2
1
<?php
2
3
namespace App\Containers\User\Policies;
4
5
use App\Port\Policy\Abstracts\Policy;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
use App\Containers\User\Models\User;
8
9
/**
10
 * Class UserPolicy.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class UserPolicy extends Policy
15
{
16
    use HandlesAuthorization;
17
18
    /**
19
     * EXAMPLE CODE, NEVER USED
20
     * Determine if the user is updating himself and not another user.
21
     *
22
     * @param \App\Containers\User\Models\User $user
23
     * @param                                $inputUserId
24
     *
25
     * @return bool
26
     */
27
    public function update(User $user, $inputUserId)
28
    {
29
        // authorize only if a user is updating it's own records
30
        return ($user->id == $inputUserId) ? true : false;
31
    }
32
33
    /**
34
     * EXAMPLE CODE, NEVER USED
35
     * Determine if the user is deleting himself and not another user.
36
     *
37
     * @param \App\Containers\User\Models\User $user
38
     * @param                                $inputUserId
39
     *
40
     * @return bool
41
     */
42
    public function delete(User $user, $inputUserId)
43
    {
44
        // authorize only if a user is deleting it's own records
45
        return ($user->id == $inputUserId) ? true : false;
46
    }
47
}
48