AuthService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 19
c 3
b 0
f 1
dl 0
loc 42
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attemptLogin() 0 22 4
A validationFailed() 0 3 1
A authenticatedUser() 0 9 2
1
<?php
2
3
namespace InnoFlash\LaraStart\Services;
4
5
class AuthService
6
{
7
    public function attemptLogin(array $credentials = [], string $guard = 'api')
8
    {
9
        if (! count($credentials)) {
10
            $credentials = request(['email', 'password']);
11
        }
12
13
        if (! $guard) {
14
            $guard = config('larastart.guard');
15
        }
16
17
        if (! $token = auth($guard)->attempt($credentials)) {
18
            return $this->validationFailed();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->validationFailed() targeting InnoFlash\LaraStart\Serv...ice::validationFailed() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
        }
20
21
        $class = config('larastart.resource');
22
23
        return [
24
            config('larastart.wrap') => new $class(auth($guard)->user()),
25
            'token' => [
26
                'access_token' => $token,
27
                'expires_in' => auth($guard)->factory()->getTTL() * 60,
0 ignored issues
show
Bug introduced by
The method factory() does not exist on Illuminate\Contracts\Auth\Guard. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\TokenGuard or Illuminate\Contracts\Auth\StatefulGuard. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
                'expires_in' => auth($guard)->/** @scrutinizer ignore-call */ factory()->getTTL() * 60,
Loading history...
28
                'type' => 'bearer',
29
            ],
30
        ];
31
    }
32
33
    public function authenticatedUser(string $guard = 'api')
34
    {
35
        $class = config('larastart.resource');
36
37
        if (! $guard) {
38
            $guard = config('larastart.guard');
39
        }
40
41
        return new $class(auth($guard)->user());
42
    }
43
44
    public function validationFailed()
45
    {
46
        abort(401, 'Invalid login credentials');
47
    }
48
}
49