Completed
Push — master ( 874c42...3f0650 )
by Ryan
02:09
created

CheckUserPermission   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 9 2
1
<?php namespace Anomaly\UsersModule\User\Command;
2
3
use Anomaly\Streams\Platform\Support\Authorizer;
4
use Anomaly\UsersModule\User\Contract\UserInterface;
5
use Illuminate\Contracts\Auth\Guard;
6
use Illuminate\Contracts\Bus\SelfHandling;
7
8
/**
9
 * Class CheckUserPermission
10
 *
11
 * @link          http://anomaly.is/streams-platform
12
 * @author        AnomalyLabs, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 * @package       Anomaly\UsersModule\User\Command
15
 */
16
class CheckUserPermission implements SelfHandling
17
{
18
19
    /**
20
     * The permission key.
21
     *
22
     * @var string
23
     */
24
    protected $permission;
25
26
    /**
27
     * Create a new CheckUserPermission instance.
28
     *
29
     * @param $permission
30
     */
31
    public function __construct($permission)
32
    {
33
        $this->permission = $permission;
34
    }
35
36
    /**
37
     * Handle the command.
38
     *
39
     * @param Authorizer $authorizer
40
     * @param Guard      $guard
41
     * @return bool
42
     */
43
    public function handle(Authorizer $authorizer, Guard $guard)
44
    {
45
        /* @var UserInterface $user */
46
        if (!$user = $guard->user()) {
47
            return false;
48
        }
49
50
        return $authorizer->authorize($this->permission, $user);
51
    }
52
}
53