Completed
Push — master ( dbc3bd...6bde35 )
by Mahmoud
03:28
created

WebAuthenticationService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A login() 0 10 2
1
<?php
2
3
namespace App\Containers\WebAuthentication\Services;
4
5
use App\Containers\WebAuthentication\Exceptions\AuthenticationFailedException;
6
use Illuminate\Auth\AuthManager as Auth;
7
/**
8
 * Class WebAuthenticationService.
9
 *
10
 * @author Mahmoud Zalt <[email protected]>
11
 */
12
class WebAuthenticationService
13
{
14
15
    /**
16
     * @var  \Illuminate\Auth\AuthManager
17
     */
18
    private $auth;
19
20
    /**
21
     * WebAuthenticationService constructor.
22
     *
23
     * @param \Illuminate\Auth\AuthManager $auth
24
     */
25
    public function __construct(Auth $auth)
26
    {
27
        $this->auth = $auth;
28
    }
29
30
    /**
31
     * @param $email
32
     * @param $password
33
     *
34
     * @return mixed
35
     */
36
    public function login($email, $password)
37
    {
38
        $correct = $this->auth->attempt(['email' => $email, 'password' => $password]);
39
40
        if(!$correct){
41
            throw new AuthenticationFailedException();
42
        }
43
44
        return $this->auth->user();
45
    }
46
47
48
}
49