Completed
Pull Request — master (#295)
by Anton
06:14
created

AbstractProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 6
cts 6
cp 1
c 0
b 0
f 0
rs 10
wmc 1
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
authenticate() 0 1 ?
verify() 0 1 ?
create() 0 1 ?
A remove() 0 12 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link      https://github.com/bluzphp/skeleton
5
 */
6
7
declare(strict_types=1);
8
9
namespace Application\Auth\Provider;
10
11
use \Application\Auth\Row;
12
use \Application\Auth\Table;
13
use \Application\Users\Row as User;
14
15
/**
16
 * AbstractProvider
17
 *
18
 * @package  Application\Auth\Provider
19
 * @author   Anton Shevchuk
20
 */
21
abstract class AbstractProvider
22
{
23
    const PROVIDER = 'abstract';
24
25
    /**
26
     * Authenticate user by token
27
     *
28
     * @param string $token
29
     *
30
     * @return void
31
     * @throws \Application\Exception
32
     * @throws \Bluz\Auth\AuthException
33
     */
34
    abstract public static function authenticate($token);
35
36
    /**
37
     * Check if supplied cookie is valid
38
     *
39
     * @param string $token
40
     *
41
     * @return Row
42
     * @throws \Bluz\Auth\AuthException
43
     */
44
    abstract public static function verify($token) : Row;
45
46
    /**
47
     * Create and save Auth record, and send cookies
48
     *
49
     * @param User $user
50
     *
51
     * @return Row
52
     * @throws \Application\Exception
53
     * @throws \Bluz\Auth\AuthException
54
     */
55
    abstract public static function create($user) : Row;
56
57
    /**
58
     * Remove Auth record by user ID
59
     *
60
     * @param integer $id User ID
61
     *
62
     * @return void
63
     * @throws \Bluz\Db\Exception\DbException
64
     */
65 2
    public static function remove($id)
66
    {
67
        // clear previous generated Auth record
68
        // works with change password
69 2
        Table::delete(
70
            [
71 2
                'userId' => $id,
72 2
                'provider' => static::PROVIDER,
73 2
                'tokenType' => Table::TYPE_ACCESS
74
            ]
75
        );
76 2
    }
77
}
78