GetRole::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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