AbstractProxy::setUsernameField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Signifly\Janitor;
4
5
use Illuminate\Contracts\Auth\UserProvider;
6
use Illuminate\Support\Facades\Auth;
7
use Signifly\Janitor\Contracts\Proxy;
8
9
abstract class AbstractProxy implements Proxy
10
{
11
    /** @var array */
12
    protected $config;
13
14
    /** @var string */
15
    protected $usernameField;
16
17
    /**
18
     * Create a new instance.
19
     *
20
     * @param array $config
21
     */
22
    public function __construct(array $config)
23
    {
24
        $this->config = $config;
25
    }
26
27
    /**
28
     * Get the guard.
29
     *
30
     * @return string
31
     */
32
    protected function getGuard()
33
    {
34
        return Auth::guard();
35
    }
36
37
    /**
38
     * Get the user instance.
39
     *
40
     * @return \Illuminate\Contracts\Auth\UserProvider
41
     */
42
    protected function getUserProvider(): UserProvider
43
    {
44
        return Auth::getProvider();
45
    }
46
47
    /**
48
     * Get username field.
49
     *
50
     * @return string
51
     */
52
    public function getUsernameField(): string
53
    {
54
        return $this->usernameField ?? config('janitor.username_field');
55
    }
56
57
    /**
58
     * Set the username field.
59
     *
60
     * @param string $username
61
     * @return $this
62
     */
63
    public function setUsernameField(string $username): self
64
    {
65
        $this->usernameField = $username;
66
67
        return $this;
68
    }
69
}
70