GetUser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 20 5
1
<?php namespace Anomaly\UsersModule\User\Command;
2
3
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
4
use Illuminate\Contracts\Auth\Guard;
5
6
7
/**
8
 * Class GetUser
9
 *
10
 * @link          http://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 */
14
class GetUser
15
{
16
17
    /**
18
     * The user identifier.
19
     *
20
     * @var mixed
21
     */
22
    protected $identifier;
23
24
    /**
25
     * Create a new GetUser 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  UserRepositoryInterface                                                                          $users
38
     * @param  Guard                                                                                            $auth
39
     * @return \Anomaly\UsersModule\User\Contract\UserInterface|\Illuminate\Contracts\Auth\Authenticatable|null
40
     */
41
    public function handle(UserRepositoryInterface $users, Guard $auth)
42
    {
43
        if (is_null($this->identifier)) {
44
            return $auth->user();
45
        }
46
47
        if (is_numeric($this->identifier)) {
48
            return $users->find($this->identifier);
49
        }
50
51
        if (filter_var($this->identifier, FILTER_VALIDATE_EMAIL)) {
52
            return $users->findByEmail($this->identifier);
53
        }
54
55
        if (!is_numeric($this->identifier)) {
56
            return $users->findByUsername($this->identifier);
57
        }
58
59
        return null;
60
    }
61
}
62