Completed
Push — develop-3.0 ( 360277...bd5ff0 )
by Mohamed
06:52
created

UserPolicy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 0 6 4
A viewName() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Policies;
13
14
use Illuminate\Auth\Access\HandlesAuthorization;
15
use Tinyissue\Model\User;
16
17
class UserPolicy
18
{
19
    use HandlesAuthorization;
20
21
    /**
22
     * @param User $user
23
     *
24
     * @return bool
25
     */
26
    public function before(User $user)
27
    {
28
        if ($user instanceof User && ($user->isAdmin() || $user->isManager())) {
29
            return true;
30
        }
31
    }
32
33
    /**
34
     * Determine if the given user can manages administrator area.
35
     *
36
     * @param User $loggedUser
37
     * @param User $user
38
     *
39
     * @return bool
40
     */
41
    public function viewName(User $loggedUser, User $user)
42
    {
43
        if (!$user->private || (int) $loggedUser->id === (int) $user->id) {
44
            return true;
45
        }
46
47
        return false;
48
    }
49
}
50