Completed
Push — master ( 3f0650...a210b6 )
by Ryan
02:07
created

GetRole::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4286
cc 3
eloc 6
nc 3
nop 1
1
<?php namespace Anomaly\UsersModule\Role\Command;
2
3
use Anomaly\UsersModule\Role\Contract\RoleRepositoryInterface;
4
use Illuminate\Contracts\Bus\SelfHandling;
5
6
/**
7
 * Class GetRole
8
 *
9
 * @link          http://anomaly.is/streams-platform
10
 * @author        AnomalyLabs, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\UsersModule\Role\Command
13
 */
14
class GetRole implements SelfHandling
15
{
16
17
    /**
18
     * The role identifier.
19
     *
20
     * @var mixed
21
     */
22
    protected $identifier;
23
24
    /**
25
     * Create a new GetRole instance.
26
     *
27
     * @param $identifier
28
     */
29
    public function __construct($identifier)
30
    {
31
        $this->identifier = $identifier;
32
    }
33
34
    /**
35
     * Handle the command.
36
     *
37
     * @param RoleRepositoryInterface $roles
38
     * @return \Anomaly\Streams\Platform\Model\EloquentModel|\Anomaly\UsersModule\Role\Contract\RoleInterface|null
39
     */
40
    public function handle(RoleRepositoryInterface $roles)
41
    {
42
        if (is_numeric($this->identifier)) {
43
            return $roles->find($this->identifier);
44
        }
45
46
        if (!is_numeric($this->identifier)) {
47
            return $roles->findBySlug($this->identifier);
48
        }
49
50
        return null;
51
    }
52
}
53