CognitoUserProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 56.25%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 47
ccs 9
cts 16
cp 0.5625
rs 10
c 2
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A validateCredentials() 0 2 1
A __construct() 0 4 1
A retrieveByCredentials() 0 15 2
A retrieveByToken() 0 2 1
A retrieveById() 0 2 1
A updateRememberToken() 0 2 1
1
<?php declare(strict_types=1);
2
3
namespace CustomerGauge\Cognito;
4
5
use CustomerGauge\Cognito\Contracts\UserFactory;
6
use Exception;
7
use Illuminate\Contracts\Auth\Authenticatable;
8
use Illuminate\Contracts\Auth\UserProvider;
9
10
final class CognitoUserProvider implements UserProvider
11
{
12
    private $parser;
13
14
    private $factory;
15
16 4
    public function __construct(TokenParser $parser, UserFactory $factory)
17
    {
18 4
        $this->parser = $parser;
19 4
        $this->factory = $factory;
20
    }
21
22 4
    public function retrieveByCredentials(array $credentials)
23
    {
24 4
        $token = $credentials['cognito_token'];
25
26
        try {
27 4
            $payload = $this->parser->parse($token);
28
29 1
        } catch (Exception $e) {
30
            // If we cannot parse the token, that probably means it's an invalid Token. Since
31
            // the Authenticate Middleware implements a Chain Of Responsibility Pattern,
32
            // we have to return null so that other Guards can try to authenticate.
33 1
            return null;
34
        }
35
36 3
        return $this->factory->make($payload);
37
    }
38
39
    /** @phpstan ignore */
40
    public function validateCredentials(Authenticatable $user, array $credentials)
41
    {
42
    }
43
44
    /** @phpstan ignore */
45
    public function retrieveById($identifier)
46
    {
47
    }
48
49
    /** @phpstan ignore */
50
    public function retrieveByToken($identifier, $token)
51
    {
52
    }
53
54
    /** @phpstan ignore */
55
    public function updateRememberToken(Authenticatable $user, $token)
56
    {
57
    }
58
}
59