GetRole   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 3
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