Failed Conditions
Push — master ( 9593ed...05e56c )
by Arnold
02:48 queued 11s
created

BasicUser::verifyPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\Auth\User;
6
7
use Jasny\Auth\ContextInterface as Context;
8
use Jasny\Auth\UserInterface;
9
10
/**
11
 * A simple user class which can be used be used instead of creating a custom user class.
12
 */
13
final class BasicUser implements UserInterface
14
{
15
    /** @var string|int */
16
    public $id;
17
18
    protected string $hashedPassword = '';
19
20
    /** @var string|int */
21
    public $role;
22
23
    /**
24
     * @inheritDoc
25
     */
26 1
    public function getAuthId(): string
27
    {
28 1
        return (string)$this->id;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 1
    public function verifyPassword(string $password): bool
35
    {
36 1
        return password_verify($password, $this->hashedPassword);
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 1
    public function getAuthChecksum(): string
43
    {
44 1
        return hash('sha256', $this->id . $this->hashedPassword);
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50 1
    public function getAuthRole(?Context $context = null)
51
    {
52 1
        return $this->role;
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58 1
    public function requiresMfa(): bool
59
    {
60 1
        return false;
61
    }
62
63
    /**
64
     * Factory method; create object from data loaded from DB.
65
     *
66
     * @param array $data
67
     * @return static
68
     */
69 2
    public static function fromData(array $data): self
0 ignored issues
show
introduced by
Method Jasny\Auth\User\BasicUser::fromData() has parameter $data with no value type specified in iterable type array.
Loading history...
70
    {
71 2
        $user = new self();
72
73 2
        foreach ($data as $key => $value) {
74 2
            $user->{$key} = $value;
75
        }
76
77 2
        return $user;
0 ignored issues
show
introduced by
Method Jasny\Auth\User\BasicUser::fromData() should return static(Jasny\Auth\User\BasicUser) but returns Jasny\Auth\User\BasicUser.
Loading history...
78
    }
79
}
80